Package org.apache.tuscany.sca.workspace

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


        this.contributionFactory = contributionFactory;
    }
   
    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

        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

           
        // Get the domain composite items
        Entry<String, Item>[] domainEntries = domainCompositeCollection.getAll();
       
        // Populate the domain composite
        Workspace workspace = workspaceFactory.createWorkspace();
        workspace.setModelResolver(new ExtensibleModelResolver(workspace, extensionPoints));
       
        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 (Exception e) {
                            if (contributionURI.equals(dependencyURI)) {
                                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, getDescription(e));
                                return;
                            } else {
                                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

        staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
    }

    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

    public Entry<String, Item>[] getAll() {
        logger.fine("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.fine("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.fine("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);
       
        // add it to the search index, contributionUpdated is called to guarantee
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

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.