Package org.apache.tuscany.sca.implementation.data.collection

Examples of org.apache.tuscany.sca.implementation.data.collection.Item


        // The key is the contribution URI
        String key = path.startsWith("/")? path.substring(1) : path;
        logger.info("get " + key);
       
        // Get the item describing the composite
        Item item;
        try {
            item = get(key);
        } catch (NotFoundException e) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND, key);
            return;
        }

        // Redirect to the actual contribution location
        response.sendRedirect("/files/" + item.getAlternate());
    }
View Full Code Here


     * @param contribution
     * @return
     */
    private static Item item(Workspace workspace, Contribution contribution) {
        String contributionURI = contribution.getURI();
        Item item = new Item();
        item.setTitle(title(contributionURI));
        item.setLink(link(contributionURI));
        item.setAlternate(contribution.getLocation());
       
        // List the contribution dependencies in the item contents
        final List<String> problems = new ArrayList<String>();
        ContributionDependencyBuilderMonitor monitor = new ContributionDependencyBuilderMonitor() {
            public void problem(Problem problem) {
                problems.add(problem.getMessage() + " " + problem.getModel());
            }
        };
       
        StringBuffer sb = new StringBuffer();
        ContributionDependencyBuilderImpl analyzer = new ContributionDependencyBuilderImpl(monitor);
        List<Contribution> dependencies = analyzer.buildContributionDependencies(workspace, contribution);
        if (dependencies.size() > 1) {
            sb.append("Dependencies: <span id=\"dependencies\">");
            for (int i = 0, n = dependencies.size(); i < n ; i++) {
                if (i > 0) {
                    sb.append("  ");
                }
                Contribution dependency = dependencies.get(i);
                if (dependency != contribution) {
                    String dependencyURI = dependency.getURI();
                    sb.append("<a href=\""+ link(dependencyURI) +"\">" + title(dependencyURI) + "</a>");
                }
            }
            sb.append("</span><br>");
        }
       
        // List the deployables
        List<Composite> deployables = contribution.getDeployables();
        if (!deployables.isEmpty()) {
            sb.append("Deployables: <span id=\"deployables\">");
            for (int i = 0, n = deployables.size(); i < n ; i++) {
                if (i > 0) {
                    sb.append("  ");
                }
                Composite deployable = deployables.get(i);
                QName qname = deployable.getName();
                sb.append("<a href=\""+ compositeSourceLink(contributionURI, qname) +"\">" + compositeSimpleTitle(contributionURI, qname) + "</a>");
            }
            sb.append("</span><br>");
        }
       
        // List the dependency problems
        if (problems.size() > 1) {
            sb.append("<span id=\"problems\" style=\"color: red\">");
            for (int i = 0, n = problems.size(); i < n ; i++) {
                sb.append("Problem: "+ problems.get(i) + "<br>");
            }
            sb.append("</span>");
        }
       
        // Store in the item contents
        item.setContents(sb.toString());
       
        return item;
    }
View Full Code Here

                }
            }
           
            // Add the contribution if necessary
            if (contributionEntry == null) {
                Item item = new Item();
                item.setLink(contributionLocation);
                contributionCollection.post(contributionURI, item);
            }
           
            // Look for the specified deployable composite in the contribution
            String compositeKey = null;
            Entry<String, Item>[] deployableEntries = deployableCollection.query("contribution=" + contributionURI);
            for (Entry<String, Item> entry: deployableEntries) {
                Item item = entry.getData();
                if (contributionURI.equals(contributionURI(entry.getKey())) && item.getAlternate().endsWith(compositeURI)) {
                    compositeKey = entry.getKey();
                    break;
                }
            }
           
            if (compositeKey == null) {
                response.sendError(HttpServletResponse.SC_NOT_FOUND, compositeURI);
                return;
            }
           
            // Look for the deployable composite in the domain composite
            try {
                domainCompositeCollection.get(compositeKey);
            } catch (NotFoundException e) {
   
                // Add the deployable composite to the domain composite
                Item item = new Item();
                domainCompositeCollection.post(compositeKey, item);
            }
   
            // Check if the deployable composite is already assigned a node
            Entry<String, Item>[] nodeEntries = cloudCollection.getAll();
            String nodeName = null;
            for (Entry<String, Item> entry: nodeEntries) {
                Item item = entry.getData();
                String related = item.getRelated();
                if (related != null) {
                    int c = related.indexOf("composite:");
                    related = related.substring(c);
                    if (compositeKey.equals(related)) {
                        nodeName = compositeQName(entry.getKey()).getLocalPart();
                    }
                }
            }
           
            // Create a new node for the composite if necessary
            if (nodeName == null) {
               
                // Construct node name and key
                QName compositeName = compositeQName(compositeKey);
                nodeName = compositeName.getLocalPart() + "Node";
                String nodeKey = compositeKey("http://tuscany.apache.org/cloud", new QName("http://tuscany.apache.org/cloud", nodeName));
               
                // Find a free node port
                Set<Integer> nodePorts = new HashSet<Integer>();
                for (Entry<String, Item> entry: nodeEntries) {
                    Item item = entry.getData();
                    String uri = nodeURI(item.getContents());
                    if (uri != null) {
                        URI u = URI.create(uri);
                        int port = u.getPort();
                        if (port != -1) {
                            nodePorts.add(port);
                        }
                    }
                }
                String nodeURI = null;
                for (int port = 8100; port<8200; port++) {
                    if (!nodePorts.contains(port)) {
                        nodeURI = "http://localhost:" + port;
                        break;
                    }
                }
                if (nodeURI == null) {
                    throw new RuntimeException("Couldn't find a free port for new node: " + nodeName);
                }
               
                // Build the entry describing the node
                Item item = new Item();
                String content =
                                "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\"\n" +
                                "       xmlns:t=\"http://tuscany.apache.org/xmlns/sca/1.0\"\n" +
                                "       targetNamespace=\"http://tuscany.apache.org/cloud\"\n" +
                                "       xmlns:c=\"" + compositeName.getNamespaceURI() + "\"\n" +
                                "       name=\"" + nodeName + "\">\n" +
                                "\n" +
                                "       <component name=\"" + nodeName + "\">\n" +
                                "               <t:implementation.node uri=\"" + contributionURI + "\" composite=\"c:" + compositeName.getLocalPart() + "\"/>\n" +
                                "               <service name=\"Node\">\n" +
                                "                       <binding.ws uri=\"" + nodeURI + "\"/>\n" +
                                "                       <t:binding.http uri=\"" + nodeURI + "\"/>\n" +
                                "                       <t:binding.jsonrpc uri=\"" + nodeURI + "\"/>\n" +
                                "                       <t:binding.atom uri=\"" + nodeURI + "\"/>\n" +
                                "               </service>\n" +
                                "       </component>\n" +
                                "</composite>";
                item.setContents(content);
   
                // Create the new node
                cloudCollection.post(nodeKey, item);
            }
           
            // Finally, start the node
            if ("true".equals(start)) {
                processCollection.post(nodeName, new Item());
            }
           
            response.getWriter().print("<html><body>Node <span id=\"node\">" + nodeName + "</span> OK.</body></html>");

        } catch (Exception e) {
View Full Code Here

            // the required contributions
            List<Entry<String, Item>> entries = new ArrayList<Entry<String, Item>>();
           
            // Add the resolved composite entry
            Entry<String, Item> compositeEntry = new Entry<String, Item>();
            Item compositeItem = new Item();
            compositeItem.setTitle(compositeTitle(contributionURI, qname));
            compositeItem.setLink("/composite-resolved/" + key);
            compositeEntry.setKey(key);
            compositeEntry.setData(compositeItem);
            entries.add(compositeEntry);
           
            // Get the collection of required contributions
            Entry<String, Item>[] contributionEntries = contributionCollection.query("alldependencies=" + contributionURI);
            for (Entry<String, Item> entry: contributionEntries) {
                Item item = entry.getData();
                item.setContents(null);
                entries.add(entry);
            }

            return entries.toArray(new Entry[entries.size()]);
           
View Full Code Here

        Composite compositeCollection = readCompositeCollection();
        for (Composite composite: compositeCollection.getIncludes()) {
            String contributionURI = composite.getURI();
            QName qname = composite.getName();
            String key = compositeKey(contributionURI, qname);
            Item item;
            try {
                item = deployableCollection.get(key);
            } catch (NotFoundException e) {
                item = new Item();
                item.setTitle(compositeTitle(contributionURI, qname));
                item.setLink(compositeSourceLink(contributionURI, qname));
                item.setContents("<span id=\"problem\" style=\"color: red\">Problem: Composite not found</span>");
            }
            Entry<String, Item> entry = new Entry<String, Item>();
            entry.setKey(key);
            entry.setData(item);
            entries.add(entry);
View Full Code Here

        String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8");
        String key = path.startsWith("/")? path.substring(1) : path;
        logger.info("get " + key);
       
        // Get the item describing the composite
        Item item;
        try {
            item = deployableCollection.get(key);
        } catch (NotFoundException e) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND, key);
            return;
        }

        // Support reading source composite file inside a JAR
        String uri = item.getAlternate();
        int e = uri.indexOf("!/");
        if (e != -1) {
            int s = uri.lastIndexOf('/', e - 2) +1;
            if (uri.substring(s, e).contains(".")) {
                uri = "jar:" + uri;
View Full Code Here

     */
    private Entry createFeedEntry(org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object> entry) {
        Object key = entry.getKey();
        Object data = entry.getData();
        if (data instanceof Item) {
            Item item = (Item)data;
           
            Entry feedEntry = new Entry();
            feedEntry.setId(key.toString());
            feedEntry.setTitle(item.getTitle());
   
            String value = item.getContents();
            if (value != null) {
                Content content = new Content();
                content.setType("text/xml");
                content.setValue(value);
                List<Content> contents = new ArrayList<Content>();
                contents.add(content);
                feedEntry.setContents(contents);
            }
   
            String href = item.getLink();
            if (href == null) {
                href = key.toString();
            }
            Link link = new Link();
            link.setRel("edit");
            link.setHref(href);
            feedEntry.getOtherLinks().add(link);
            link = new Link();
            link.setRel("alternate");
            link.setHref(href);
            feedEntry.getAlternateLinks().add(link);
   
            Date date = item.getDate();
            if (date == null) {
                date = new Date();
            }
            feedEntry.setCreated(date);
            return feedEntry;
View Full Code Here

    private org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object> createEntry(Entry feedEntry) {
        if (feedEntry != null) {
            if (itemClassType.getPhysical() == Item.class) {
                String key = feedEntry.getId();
               
                Item item = new Item();
                item.setTitle(feedEntry.getTitle());
               
                List<?> contents = feedEntry.getContents();
                if (!contents.isEmpty()) {
                    Content content = (Content)contents.get(0);
                    String value = content.getValue();
                    item.setContents(value);
                }
               
                for (Object l : feedEntry.getOtherLinks()) {
                    Link link = (Link)l;
                    if (link.getRel() == null || "edit".equals(link.getRel())) {
                        String href = link.getHref();
                        if (href.startsWith("null/")) {
                            href = href.substring(5);
                        }
                        item.setLink(href);
                        break;
                    }
                }
               
                item.setDate(feedEntry.getCreated());
               
                return new org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object>(key, item);
               
            } else {
                String key = feedEntry.getId();
View Full Code Here

     *
     * @param vm
     * @return
     */
    private static Item item(SCANodeVM vm) {
        Item item = new Item();
        String key = vm.getNodeName();
        item.setTitle(title(key));
        item.setLink("/node-image/" + vm.getNodeName());
        item.setContents("<span id=\"log\" style=\"white-space: nowrap; font-size: small\">" + vm.getLog().toString() + "</span>");
        return item;
    }
View Full Code Here

     */
    private SyndEntry createFeedEntry(org.apache.tuscany.sca.implementation.data.collection.Entry<Object, Object> entry) {
        Object key = entry.getKey();
        Object data = entry.getData();
        if (data instanceof Item) {
            Item item = (Item)data;
           
            SyndEntry feedEntry = new SyndEntryImpl();
            feedEntry.setUri(key.toString());
            feedEntry.setTitle(item.getTitle());
   
            String value = item.getContents();
            if (value != null) {
                SyndContent content = new SyndContentImpl();
                content.setType("text/xml");
                content.setValue(value);
                List<SyndContent> contents = new ArrayList<SyndContent>();
                contents.add(content);
                feedEntry.setContents(contents);
            }
   
            String href = item.getLink();
            if (href == null) {
                href = key.toString();
            }
            SyndLink link = new SyndLinkImpl();
            link.setRel("edit");
            link.setHref(href);
            feedEntry.getLinks().add(link);
            link = new SyndLinkImpl();
            link.setRel("alternate");
            link.setHref(href);
            feedEntry.getLinks().add(link);
   
            Date date = item.getDate();
            if (date == null) {
                date = new Date();
            }
            feedEntry.setPublishedDate(date);
            return feedEntry;
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.implementation.data.collection.Item

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.