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

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


                                  DataType<?> itemClassType, DataType<?> itemXMLType, Mediator mediator,
                                  Factory factory) {
        Object key = entry.getKey();
        Object data = entry.getData();
        if (data instanceof Item) {
            Item item = (Item)data;

            org.apache.abdera.model.Entry feedEntry = factory.newEntry();
            if (key != null) {
                feedEntry.setId(key.toString());
            }
            feedEntry.setTitle(item.getTitle());
            feedEntry.setContentAsHtml(item.getContents());

            String href = item.getLink();
            if (href == null && key != null) {
                href = key.toString();
            }

            if (href != null) {
                feedEntry.addLink(href);
            }
            String related = item.getRelated();
            if (related != null) {
                feedEntry.addLink(related, "related");
            }
            String alternate = item.getAlternate();
            if (alternate != null) {
                feedEntry.addLink(alternate, "alternate");
            }

            Date date = item.getDate();
            if (date != null) {
                feedEntry.setUpdated(date);
            }
            return feedEntry;
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

     * @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>();
        Monitor monitor = new Monitor() {
            public void problem(Problem problem) {
                problems.add(problem.getMessageId() + " " + problem.getProblemObject().toString());
            }
           
            public List<Problem> getProblems() {
                return null;
            }
            public Problem createProblem(String sourceClassName, String bundleName,
              Severity severity, Object problemObject, String messageId,
              Exception cause) {
            return new ProblemImpl(sourceClassName, bundleName, severity,
                problemObject, messageId, cause);
          }

          public Problem createProblem(String sourceClassName, String bundleName,
              Severity severity, Object problemObject, String messageId,
              Object... messageParams) {
            return new ProblemImpl(sourceClassName, bundleName, severity,
                problemObject, messageId, messageParams);
          }            
        };
       
        StringBuffer sb = new StringBuffer();
        ContributionDependencyBuilderImpl analyzer = new ContributionDependencyBuilderImpl(monitor);
        List<Contribution> dependencies = analyzer.buildContributionDependencies(contribution, workspace);
        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 (contribution.isUnresolved()) {
            problems.add("Contribution not found");
        }
        if (problems.size() > 0) {
            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();
                String compositeFileName = compositeURI.substring(compositeURI.lastIndexOf("/") + 1);
                if (contributionURI.equals(contributionURI(entry.getKey())) &&
                    (item.getAlternate().endsWith(compositeURI) ||
                     item.getAlternate().endsWith(compositeFileName))) {
                    compositeKey = entry.getKey();
                    break;
                }
            }
           
            if (compositeKey == null) {
              logger.info("Composite not found");
                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.sca uri=\"" + nodeURI + "\"/>\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

            results = this.domainSearch.parseAndSearch(query, true);
        } catch (Exception e1) {
            throw new NotFoundException("Exception while searching: " + e1.getMessage(), e1);
        }

        Item item = new Item();
        item.setTitle("Results");

        StringWriter sw = new StringWriter();
        this.elementCounter = 0;

        if (results.length > 0) {
            for (Result result : results) {
                try {
                    writeToHTML(0, result, sw);
                } catch (IOException e) {
                    // ignore result
                }
            }

            String contents = HighlightingUtil.replaceHighlightMarkupBy(sw.getBuffer(), HIGHLIGHT_START, HIGHLIGHT_END);

            item.setContents(replaceAll(contents, 40));

        } else {
            item.setContents("No results match: <u>" + query + "</u>");
        }

        // System.out.println(item.getContents());

        return item;
View Full Code Here

    @SuppressWarnings("unchecked")
    public Entry<String, Item>[] query(String queryString) {

        try {

            Item item;
            String key;

            if (queryString.startsWith("highlight")) {
                int lastSemicolonIndex = queryString.lastIndexOf(";");
                String artifact = queryString.substring(lastSemicolonIndex + 1);
View Full Code Here

            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;
View Full Code Here

            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);
View Full Code Here

        String contributionName = path.substring("contribution="
            .length(), semicolonIndex);
        artifactURI = path.substring(semicolonIndex + 1);

        try {
          Item item = this.contributionCollection
              .get(contributionName);

          if (item == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);

            return;

          }

          path = item.getAlternate();

        } catch (NotFoundException e) {
          response.sendError(HttpServletResponse.SC_NOT_FOUND);

          return;
View Full Code Here

    Entry<String, Item>[] contributionEntries = contributionCollection
        .getAll();

    // Read contribution metadata
    for (Entry<String, Item> contributionEntry : contributionEntries) {
      Item contributionItem = contributionEntry.getData();
      Contribution contribution;
      try {
        contribution = contribution(contributionEntry.getKey(),
            contributionItem.getAlternate());
      } catch (ContributionReadException e) {
        continue;
      }

      // Create entries for the deployable composites
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.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.