Package org.apache.tuscany.sca.workspace

Examples of org.apache.tuscany.sca.workspace.Workspace


        XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML));

        WorkspaceFactory workspaceFactory = new DefaultWorkspaceFactory();
        ContributionFactory contributionFactory = new DefaultContributionFactory();
        WorkspaceProcessor processor = new WorkspaceProcessor(workspaceFactory, contributionFactory, null);
        Workspace workspace = processor.read(reader);
        assertNotNull(workspace);
        assertEquals(2, workspace.getContributions().size());
        assertEquals("uri2", workspace.getContributions().get(1).getURI());
        assertEquals("location2", workspace.getContributions().get(1).getLocation());
  }
View Full Code Here


    @Override
    public void tearDown() throws Exception {
    }

    public void testAnalyze() {
        Workspace workspace = workspaceFactory.createWorkspace();
        Contribution importer = contributionFactory.createContribution();
        importer.setURI("importer");
        workspace.getContributions().add(importer);
        NamespaceImport import_ = importExportFactory.createNamespaceImport();
        import_.setNamespace("http://foo");
        importer.getImports().add(import_);

        Contribution imported = contributionFactory.createContribution();
        imported.setURI("imported");
        workspace.getContributions().add(imported);
        NamespaceExport export = importExportFactory.createNamespaceExport();
        export.setNamespace("http://foo");
        imported.getExports().add(export);
        import_ = importExportFactory.createNamespaceImport();
        import_.setNamespace("http://bar");
        imported.getImports().add(import_);
       
        Contribution imported2 = contributionFactory.createContribution();
        imported2.setURI("imported2");
        workspace.getContributions().add(imported2);
        export = importExportFactory.createNamespaceExport();
        export.setNamespace("http://bar");
        imported2.getExports().add(export);
       
        Contribution another = contributionFactory.createContribution();
        another.setURI("another");
        workspace.getContributions().add(another);
        export = importExportFactory.createNamespaceExport();
        export.setNamespace("http://another");
        another.getExports().add(export);
       
        ContributionDependencyBuilderImpl analyzer = new ContributionDependencyBuilderImpl(null);
View Full Code Here

        this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
    }
   
    public Workspace read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
       
        Workspace workspace = null;
        Contribution contribution = null;
       
        // Read the workspace document
        while (reader.hasNext()) {
            int event = reader.getEventType();
            switch (event) {
                case START_ELEMENT:
                    QName name = reader.getName();

                    if (WORKSPACE_QNAME.equals(name)) {

                        // Read a <workspace>
                        workspace = workspaceFactory.createWorkspace();
                        workspace.setUnresolved(true);

                    } else if (CONTRIBUTION_QNAME.equals(name)) {

                        // Read a <contribution>
                        contribution = contributionFactory.createContribution();
                        contribution.setURI(getString(reader, URI));
                        contribution.setLocation(getString(reader, LOCATION));
                        contribution.setUnresolved(true);
                        workspace.getContributions().add(contribution);
                    }
                    break;

                case END_ELEMENT:
                    name = reader.getName();
View Full Code Here

            urlStream = connection.getInputStream();
            XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
            reader.nextTag();
           
            // Read the workspace model
            Workspace workspace = (Workspace)staxProcessor.read(reader);
            if (workspace != null) {
                workspace.setURI(uri.toString());
            }

            return workspace;
           
        } catch (XMLStreamException e) {
View Full Code Here

        importExportFactory = new DefaultNamespaceImportExportFactory();
    }

    @Test
    public void testAnalyze() throws Exception {
        Workspace workspace = workspaceFactory.createWorkspace();
        Contribution importer = contributionFactory.createContribution();
        importer.setURI("importer");
        workspace.getContributions().add(importer);
        NamespaceImport import_ = importExportFactory.createNamespaceImport();
        import_.setNamespace("http://foo");
        importer.getImports().add(import_);

        Contribution imported = contributionFactory.createContribution();
        imported.setURI("imported");
        workspace.getContributions().add(imported);
        NamespaceExport export = importExportFactory.createNamespaceExport();
        export.setNamespace("http://foo");
        imported.getExports().add(export);
        import_ = importExportFactory.createNamespaceImport();
        import_.setNamespace("http://bar");
        imported.getImports().add(import_);
       
        Contribution imported2 = contributionFactory.createContribution();
        imported2.setURI("imported2");
        workspace.getContributions().add(imported2);
        export = importExportFactory.createNamespaceExport();
        export.setNamespace("http://bar");
        imported2.getExports().add(export);
       
        Contribution another = contributionFactory.createContribution();
        another.setURI("another");
        workspace.getContributions().add(another);
        export = importExportFactory.createNamespaceExport();
        export.setNamespace("http://another");
        another.getExports().add(export);
       
        ContributionDependencyBuilderImpl builder = new ContributionDependencyBuilderImpl(null);
View Full Code Here

    }

    @Test
    public void testRead() throws Exception {
        XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
        Workspace workspace = (Workspace)staxProcessor.read(reader);
        assertNotNull(workspace);
        assertEquals(2, workspace.getContributions().size());
        assertEquals("uri2", workspace.getContributions().get(1).getURI());
        assertEquals("location2", workspace.getContributions().get(1).getLocation());
    }
View Full Code Here

    }
   
    private void configureNode(ConfiguredNodeImplementation configuration) throws Exception {

        // Create workspace model
        Workspace workspace = workspaceFactory.createWorkspace();
        workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories));

        // Load the specified contributions
        for (Contribution c : configuration.getContributions()) {
            URI contributionURI = URI.create(c.getURI());
           
            URI uri = createURI(c.getLocation());
            if (uri.getScheme() == null) {
                uri = new File(c.getLocation()).toURI();
            }
            URL contributionURL = uri.toURL();

            // Load the contribution
            logger.log(Level.INFO, "Loading contribution: " + contributionURL);
            Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL);
            workspace.getContributions().add(contribution);
            analyzeProblems();
        }
       
        // Build an aggregated SCA definitions model. Must be done before we try and
        // resolve any contributions or composites as they may depend on the full
        // definitions.xml picture
       
        // get all definitions.xml artifacts from contributions and aggregate
        // into the system contribution. In turn add a default import into
        // each contribution so that for unresolved items the resolution
        // processing will look in the system contribution
        for (Contribution contribution: workspace.getContributions()) {
            // aggregate definitions
            for (Artifact artifact : contribution.getArtifacts()) {
                Object model = artifact.getModel();
                if (model instanceof Definitions) {
                    DefinitionsUtil.aggregate((Definitions)model, systemDefinitions);
                }
            }
           
            // create a default import and wire it up to the system contribution
            // model resolver. This is the trick that makes the resolution processing
            // skip over to the system contribution if resolution is unsuccessful
            // in the current contribution
            DefaultImport defaultImport = contributionFactory.createDefaultImport();
            defaultImport.setModelResolver(systemContribution.getModelResolver());
            contribution.getImports().add(defaultImport);
        }
       
        // now resolve the system contribution and add the contribution
        // to the workspace
        contributionProcessor.resolve(systemContribution, workspace.getModelResolver());
        workspace.getContributions().add(systemContribution);
       
        // TODO - Now we can calculate applicable policy sets for each composite

        // Build the contribution dependencies
        Set<Contribution> resolved = new HashSet<Contribution>();
        for (Contribution contribution: workspace.getContributions()) {
            contributionDependencyBuilder.build(contribution, workspace, monitor);
           
            // Resolve contributions
            for (Contribution dependency: contribution.getDependencies()) {
                if (!resolved.contains(dependency)) {
                    resolved.add(dependency);
                    contributionProcessor.resolve(dependency, workspace.getModelResolver());
                }
            }
        }
       
        composite = configuration.getComposite();
       
        if (composite == null) {
            setDefaultComposite(configuration, workspace);
        }
       
        // Find the composite in the given contributions
        boolean found = false;
        Artifact compositeFile = contributionFactory.createArtifact();
        compositeFile.setUnresolved(true);
        compositeFile.setURI(composite.getURI());
        for (Contribution contribution: workspace.getContributions()) {
            ModelResolver resolver = contribution.getModelResolver();
//            for (Artifact artifact : contribution.getArtifacts()){
//                logger.log(Level.INFO,"artifact - " + artifact.getURI());
//            }
            Artifact resolvedArtifact = resolver.resolveModel(Artifact.class, compositeFile);
View Full Code Here

    }

    @Test
    public void testRead() throws Exception {
        XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
        Workspace workspace = (Workspace)staxProcessor.read(reader);
        assertNotNull(workspace);
        assertEquals(2, workspace.getContributions().size());
        assertEquals("uri2", workspace.getContributions().get(1).getURI());
        assertEquals("location2", workspace.getContributions().get(1).getLocation());
    }
View Full Code Here

        this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
    }
   
    public Workspace read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
       
        Workspace workspace = null;
        Contribution contribution = null;
       
        // Read the workspace document
        while (reader.hasNext()) {
            int event = reader.getEventType();
            switch (event) {
                case START_ELEMENT:
                    QName name = reader.getName();

                    if (WORKSPACE_QNAME.equals(name)) {

                        // Read a <workspace>
                        workspace = workspaceFactory.createWorkspace();
                        workspace.setUnresolved(true);

                    } else if (CONTRIBUTION_QNAME.equals(name)) {

                        // Read a <contribution>
                        contribution = contributionFactory.createContribution();
                        contribution.setURI(getString(reader, URI));
                        contribution.setLocation(getString(reader, LOCATION));
                        contribution.setUnresolved(true);
                        workspace.getContributions().add(contribution);
                    }
                    break;

                case END_ELEMENT:
                    name = reader.getName();
View Full Code Here

            urlStream = connection.getInputStream();
            XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
            reader.nextTag();
           
            // Read the workspace model
            Workspace workspace = (Workspace)staxProcessor.read(reader);
            if (workspace != null) {
                workspace.setURI(uri.toString());
            }

            return workspace;
           
        } catch (XMLStreamException e) {
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.workspace.Workspace

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.