Package org.apache.tuscany.sca.workspace

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


            // 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(monitor);
                    List<Contribution> dependencies = analyzer.buildContributionDependencies(contribution, workspace);
                   
                    // Returns entries for the dependencies
                    // optionally skip the specified contribution
                    boolean allDependencies = queryString.startsWith("alldependencies=");
                    for (Contribution dependency: dependencies) {
                        if (!allDependencies && dependency == contribution) {
                            // Skip the specified contribution
                            continue;
                        }
                        entries.add(entry(workspace, dependency));
                    }
                    break;
                }
            }

            return entries.toArray(new Entry[entries.size()]);
           
        } if (queryString.startsWith("suggestions=true")) {
           
            // Returns a list of contribution suggestions, scan the parent of the workspace
            // directory for potential contribution directories
           
            // For now, recognize project directories that contain .project files
            // Directories containing .classpath files are likely to be Java projects, we parse
            // the .classpath file to determine the Java project output location
            Workspace suggestionWorkspace = workspaceFactory.createWorkspace();
            List<Entry> entries = new ArrayList<Entry>();
            String rootDirectory = domainManagerConfiguration.getRootDirectory();
            File rootLocation = new File(new File(rootDirectory).toURI().normalize());
            for (File project: rootLocation.getParentFile().listFiles()) {
                File dotProject = new File(project, ".project");
View Full Code Here


     * @return
     */
    private Workspace readWorkspace() {
        String rootDirectory = domainManagerConfiguration.getRootDirectory();
       
        Workspace workspace;
        File file = new File(rootDirectory + "/" + workspaceFile);
        if (file.exists()) {
           
            // Get workspace from cache
            if (cache.workspace != null && file.lastModified() == cache.workspaceLastModified) {
                workspace = cache.workspace;
               
            } else {
               
                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);
                }

                // Cache workspace
                cache.workspaceLastModified = file.lastModified();
                cache.workspace = workspace;
            }
           
        } else {
           
            // Create new workspace
            workspace = workspaceFactory.createWorkspace();

            // Cache workspace
            cache.workspaceLastModified = 0;
            cache.workspace = workspace;
        }
       
        // 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(rootDirectory + "/" + 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 contributions = workspaceFactory.createWorkspace();
        try {
            for (Contribution c: workspace.getContributions()) {
                URI uri = URI.create(c.getURI());
                URL location = locationURL(c.getLocation());
               
                // Get contribution from cache
                ContributionCache contributionCache = cache.contributions.get(location);
                long lastModified = lastModified(location);
                if (contributionCache != null) {
                    if (contributionCache.contributionLastModified == lastModified) {
                        Contribution contribution = contributionCache.contribution;
                        contribution.setUnresolved(false);
                        contributions.getContributions().add(contribution);
                        continue;
                    }
                   
                    // Reset contribution cache
                    cache.contributions.remove(location);
                }
               
                try {
                    Contribution contribution = (Contribution)contributionProcessor.read(null, uri, location);
                    contribution.setUnresolved(false);
                    contributions.getContributions().add(contribution);
                   
                    // Cache contribution
                    contributionCache = new ContributionCache();
                    contributionCache.contribution = contribution;
                    contributionCache.contributionLastModified = lastModified;
                    cache.contributions.put(location, contributionCache);
                   
                   
                    // Make sure that the cloud contribution does not contain
                    // default imports/exports as we want to isolate it from application
                    // provided contributions
                    if (contribution.getURI().equals(DEPLOYMENT_CONTRIBUTION_URI)) {
                        for (Iterator<Import> i = contribution.getImports().iterator(); i.hasNext(); ) {
                            Import import_ = i.next();
                            if (import_ instanceof DefaultImport) {
                                i.remove();
                            }
                        }
                        for (Iterator<Export> i = contribution.getExports().iterator(); i.hasNext(); ) {
                            Export export = i.next();
                            if (export instanceof DefaultExport) {
                                i.remove();
                            }
                        }
                    }
                   
                } catch (ContributionReadException e) {
                    Contribution contribution = contributionFactory.createContribution();
                    contribution.setURI(c.getURI());
                    contribution.setLocation(c.getLocation());
                    contribution.setUnresolved(true);
                    contributions.getContributions().add(contribution);
                }
            }
        } catch (Exception e) {
            throw new ServiceRuntimeException(e);
        }
View Full Code Here

    public static void main(String[] args) throws Exception {
        init();

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

        // Read the sample store contribution
        URI storeURI = URI.create("store");
        URL storeURL = new File("./target/sample-domain-management-store.jar").toURI().toURL();
        Contribution storeContribution = contributionProcessor.read(null, storeURI, storeURL);
        workspace.getContributions().add(storeContribution);

        // Read the sample assets contribution
        URI assetsURI = URI.create("assets");
        URL assetsURL = new File("./target/sample-domain-management-assets.jar").toURI().toURL();
        Contribution assetsContribution = contributionProcessor.read(null, assetsURI, assetsURL);
        workspace.getContributions().add(assetsContribution);

        // Build the store contribution dependencies
        List<Contribution> dependencies = contributionDependencyBuilder.buildContributionDependencies(storeContribution, workspace);
       
        // Resolve the contributions
        for (Contribution contribution: dependencies) {
            contributionProcessor.resolve(contribution, workspace.getModelResolver());
        }
       
        // List the components declared in the deployables found in the
        // contribution, their services, bindings, interfaces, and implementations
        for (Composite deployable: storeContribution.getDeployables()) {
View Full Code Here

    public static void main(String[] args) throws Exception {
        init();

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

        // Read the sample store contribution
        URI storeURI = URI.create("store");
        URL storeURL = new File("./target/sample-domain-management-store.jar").toURI().toURL();
        Contribution storeContribution = contributionProcessor.read(null, storeURI, storeURL);
        workspace.getContributions().add(storeContribution);

        // Read the sample assets contribution
        URI assetsURI = URI.create("assets");
        URL assetsURL = new File("./target/sample-domain-management-assets.jar").toURI().toURL();
        Contribution assetsContribution = contributionProcessor.read(null, assetsURI, assetsURL);
        workspace.getContributions().add(assetsContribution);

        // Read the sample client contribution
        URI clientURI = URI.create("client");
        URL clientURL = new File("./target/sample-domain-management-client.jar").toURI().toURL();
        Contribution clientContribution = contributionProcessor.read(null, clientURI, clientURL);
        workspace.getContributions().add(clientContribution);

        // Build the contribution dependencies
        Map<Contribution, List<Contribution>> contributionDependencies = new HashMap<Contribution, List<Contribution>>();
        Set<Contribution> resolved = new HashSet<Contribution>();
        for (Contribution contribution: workspace.getContributions()) {
            List<Contribution> dependencies = contributionDependencyBuilder.buildContributionDependencies(contribution, workspace);
           
            // Resolve contributions
            for (Contribution dependency: dependencies) {
                if (!resolved.contains(dependency)) {
                    resolved.add(dependency);
                    contributionProcessor.resolve(dependency, workspace.getModelResolver());
                }
            }
           
            contributionDependencies.put(contribution, dependencies);
        }
       
        // Create a set of nodes, and assign the sample deployables to them
        Map<Component, List<Contribution>> nodeDependencies = new HashMap<Component, List<Contribution>>();
        Composite cloudComposite = assemblyFactory.createComposite();
        cloudComposite.setName(new QName("http://sample", "cloud"));
        int nodeID = 8100;
        for (Contribution contribution: workspace.getContributions()) {
            for (Composite deployable: contribution.getDeployables()) {
               
                // Create a node
                Component node = assemblyFactory.createComponent();
                node.setName("Node" + nodeID);
                cloudComposite.getComponents().add(node);
               
                // Add default binding configuration to the node, our samples use
                // Atom bindings so here we're just creating default Atom binding
                // configurations, but all the other binding types can be configured
                // like that too
                ComponentService nodeService = assemblyFactory.createComponentService();
                Binding binding = atomBindingFactory.createAtomBinding();
                binding.setURI("http://localhost:" + (8100 + nodeID));
                nodeService.getBindings().add(binding);
                node.getServices().add(nodeService);

                // Assign a deployable to the node
                NodeImplementation nodeImplementation = nodeFactory.createNodeImplementation();
                nodeImplementation.setComposite(deployable);
                node.setImplementation(nodeImplementation);
               
                // Keep track of what contributions will be needed by the node
                nodeDependencies.put(node, contributionDependencies.get(contribution));
               
                nodeID++;
            }
        }
       
        // Print the model describing the nodes that we just built
        System.out.println("cloud.composite");
        System.out.println(print(cloudComposite));
       
        // Build the nodes, this will apply their default binding configuration to the
        // composites assigned to them
        nodeCompositeBuilder.build(cloudComposite);
       
        // Create a composite model for the domain
        Composite domainComposite = assemblyFactory.createComposite();
        domainComposite.setName(new QName("http://sample", "domain"));
       
        // Add all deployables to it, normally the domain administrator would select
        // the deployables to include
        domainComposite.getIncludes().addAll(workspace.getDeployables());
       
        // Build the domain composite and wire the components included in it
        domainCompositeBuilder.build(domainComposite);

        // Print out the resulting domain composite
View Full Code Here

           
        // Get the domain composite items
        Entry<String, Item>[] domainEntries = domainCompositeCollection.getAll();
       
        // Populate the domain composite
        Workspace workspace = workspaceFactory.createWorkspace();
        workspace.setModelResolver(new ExtensibleModelResolver(workspace, modelResolvers, modelFactories));
       
        Map<String, Contribution> contributionMap = new HashMap<String, Contribution>();
        for (Entry<String, Item> domainEntry: domainEntries) {
           
            // Load the required contributions
            String contributionURI = contributionURI(domainEntry.getKey());
            Contribution contribution = contributionMap.get(contributionURI);
            if (contribution == null) {
               
                // The contribution has not been loaded yet, load it with all its dependencies
                Entry<String, Item>[] entries = contributionCollection.query("alldependencies=" + contributionURI);
                for (Entry<String, Item> entry: entries) {
                    Item dependencyItem = entry.getData();
                    String dependencyURI = entry.getKey();
                   
                    if (!contributionMap.containsKey(dependencyURI)) {
                       
                        // Read the contribution
                        Contribution dependency;
                        try {
                            String dependencyLocation = dependencyItem.getAlternate();
                            dependency = contribution(workspace, dependencyURI, dependencyLocation);
                        } catch (ContributionReadException e) {
                            continue;
                        }
                        workspace.getContributions().add(dependency);
                        contributionMap.put(dependencyURI, dependency);
                       
                        if (contributionURI.equals(entry.getKey())) {
                            contribution = dependency;
                        }
View Full Code Here

       
        // Get the collection of cloud composites
        Entry<String, Item>[] cloudEntries = cloudCollection.getAll();
       
        // Load the cloud contributions
        Workspace workspace = workspaceFactory.createWorkspace();
        Map<String, Contribution> contributionMap = new HashMap<String, Contribution>();
        for (Entry<String, Item> cloudEntry: cloudEntries) {
            String key = cloudEntry.getKey();
            String contributionURI = contributionURI(key);

            // Load the contribution
            Contribution contribution = contributionMap.get(contributionURI);
            if (contribution == null) {
                Item contributionItem = contributionCollection.get(contributionURI);
               
                // Read the contribution
                try {
                    contribution = contribution(workspace, contributionURI, contributionItem.getAlternate());
                } catch (ContributionReadException e) {
                    continue;
                }
                workspace.getContributions().add(contribution);
                contributionMap.put(contributionURI, contribution);
               
            }

            // Include the cloud composite in the clouds composite
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

    public static void main(String[] args) throws Exception {
        init();

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

        // Read the sample assets contribution
        URI assetsURI = URI.create("assets");
        URL assetsURL = new File("./target/sample-domain-management-assets.jar").toURI().toURL();
        Contribution assetsContribution = contributionProcessor.read(null, assetsURI, assetsURL);
        workspace.getContributions().add(assetsContribution);

        // Read the sample store contribution
        URI storeURI = URI.create("store");
        URL storeURL = new File("./target/sample-domain-management-store.jar").toURI().toURL();
        Contribution storeContribution = contributionProcessor.read(null, storeURI, storeURL);
        workspace.getContributions().add(storeContribution);

        // Read the sample client contribution
        URI clientURI = URI.create("client");
        URL clientURL = new File("./target/sample-domain-management-client.jar").toURI().toURL();
        Contribution clientContribution = contributionProcessor.read(null, clientURI, clientURL);
        workspace.getContributions().add(clientContribution);

        // Build the contribution dependencies
        Set<Contribution> resolved = new HashSet<Contribution>();
        for (Contribution contribution: workspace.getContributions()) {
            List<Contribution> dependencies = contributionDependencyBuilder.buildContributionDependencies(contribution, workspace);
           
            // Resolve contributions
            for (Contribution dependency: dependencies) {
                if (!resolved.contains(dependency)) {
                    resolved.add(dependency);
                    contributionProcessor.resolve(contribution, workspace.getModelResolver());
                }
            }
        }
       
        // Create a composite model for the domain
        Composite domainComposite = assemblyFactory.createComposite();
        domainComposite.setName(new QName("http://sample", "domain"));
       
        // Add all deployables to it, normally the domain administrator would select
        // the deployables to include
        domainComposite.getIncludes().addAll(workspace.getDeployables());
       
        // Build the domain composite and wire the components included in it
        domainCompositeBuilder.build(domainComposite);

        // Print out the resulting domain composite
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.