Package org.apache.tuscany.sca.workspace

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


    }

    private Composite 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 composite = configuration.getComposite();

        if (composite == null) {
            composite = getDefaultComposite(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


    @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

    public Entry<String, Item>[] getAll() {
        logger.info("getAll");

        // Return all the contributions
        List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>();
        Workspace workspace = readContributions(readWorkspace());
       
        for (Contribution contribution: workspace.getContributions()) {
            if (contribution.getURI().equals(DEPLOYMENT_CONTRIBUTION_URI)) {
                continue;
            }
            entries.add(entry(workspace, contribution));
        }
View Full Code Here

    public Item get(String key) throws NotFoundException {
        logger.info("get " + key);

        // Returns the contribution with the given URI key
        Workspace workspace = readContributions(readWorkspace());
        for (Contribution contribution: workspace.getContributions()) {
            if (key.equals(contribution.getURI())) {
                return item(workspace, contribution);
            }
        }
        throw new NotFoundException(key);
View Full Code Here

    public String post(String key, Item item) {
        logger.info("post " + key);
       
        // Adds a new contribution to the workspace
        Workspace workspace = readWorkspace();
        Contribution contribution = contributionFactory.createContribution();
        contribution.setURI(key);
        try {
            contribution.setLocation(locationURL(item.getLink()).toString());
        } catch (MalformedURLException e) {
            throw new ServiceRuntimeException(e);
        }
        workspace.getContributions().add(contribution);
       
        // Write the workspace
        writeWorkspace(workspace);
       
        return key;
View Full Code Here

    }

    public void put(String key, Item item) throws NotFoundException {
       
        // Update a contribution already in the workspace
        Workspace workspace = readWorkspace();
        Contribution newContribution = contributionFactory.createContribution();
        newContribution.setURI(key);
        try {
            newContribution.setLocation(locationURL(item.getLink()).toString());
        } catch (MalformedURLException e) {
            throw new ServiceRuntimeException(e);
        }
        List<Contribution> contributions = workspace.getContributions();
        for (int i = 0, n = contributions.size(); i < n; i++) {
            if (contributions.get(i).getURI().equals(key)) {
                contributions.set(i, newContribution);
               
                // Write the workspace
View Full Code Here

    public void delete(String key) throws NotFoundException {
        logger.info("delete " + key);
       
        // Delete a contribution from the workspace
        Workspace workspace = readWorkspace();
        List<Contribution> contributions = workspace.getContributions();
        for (int i = 0, n = contributions.size(); i < n; i++) {
            if (contributions.get(i).getURI().equals(key)) {
                contributions.remove(i);

                // Write the workspace
View Full Code Here

            // Extract the contribution URI
            int eq = queryString.indexOf('=');
            String key = queryString.substring(eq+1);
           
            // Read the metadata for all the contributions
            Workspace workspace = readContributions(readWorkspace());
           
            // Look for the specified contribution
            for (Contribution contribution: workspace.getContributions()) {
                if (key.equals(contribution.getURI())) {

                    // Compute the contribution dependencies
                    ContributionDependencyBuilder analyzer = new ContributionDependencyBuilderImpl(null);
                    List<Contribution> dependencies = analyzer.buildContributionDependencies(workspace, contribution);
View Full Code Here

     * Read the workspace.
     *
     * @return
     */
    private Workspace readWorkspace() {
        Workspace workspace;
        File file = new File(workspaceFile);
        if (file.exists()) {
            try {
                FileInputStream is = new FileInputStream(file);
                XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
                reader.nextTag();
                workspace = (Workspace)staxProcessor.read(reader);
            } catch (Exception e) {
                throw new ServiceRuntimeException(e);
            }
        } else {
            workspace = workspaceFactory.createWorkspace();
        }
       
        // Make sure that the workspace contains the cloud contribution
        // The cloud contribution contains the composites describing the
        // SCA nodes declared in the cloud
        Contribution cloudContribution = null;
        for (Contribution contribution: workspace.getContributions()) {
            if (contribution.getURI().equals(DEPLOYMENT_CONTRIBUTION_URI)) {
                cloudContribution = contribution;
            }
        }
        if (cloudContribution == null) {
            Contribution contribution = contributionFactory.createContribution();
            contribution.setURI(DEPLOYMENT_CONTRIBUTION_URI);
            File cloudDirectory = new File(deploymentContributionDirectory);
            contribution.setLocation(cloudDirectory.toURI().toString());
            workspace.getContributions().add(contribution);
        }
        return workspace;
    }
View Full Code Here

     *
     * @param workspace
     * @return
     */
    private Workspace readContributions(Workspace workspace) {
        Workspace dependencyWorkspace = workspaceFactory.createWorkspace();
        try {
            for (Contribution c: workspace.getContributions()) {
                URI uri = URI.create(c.getURI());
                URL url = locationURL(c.getLocation());
                Contribution contribution = (Contribution)contributionInfoProcessor.read(null, uri, url);
                dependencyWorkspace.getContributions().add(contribution);
            }
        } catch (Exception e) {
            throw new ServiceRuntimeException(e);
        }
        return dependencyWorkspace;
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.