Package org.apache.tuscany.sca.workspace

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


    public void delete(String key) throws NotFoundException {
        logger.fine("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(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

            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 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

    public void delete(String key) throws NotFoundException {
        logger.fine("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++) {
         
          Contribution contribution = contributions.get(i);
         
            if (contribution.getURI().equals(key)) {
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.