You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2008/07/14 19:20:52 UTC

svn commit: r676652 - in /tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl: NodeImpl.java NodeUtil.java

Author: jsdelfino
Date: Mon Jul 14 10:20:51 2008
New Revision: 676652

URL: http://svn.apache.org/viewvc?rev=676652&view=rev
Log:
Starting to fix algorithm driving the resolution of the composite associated with a node. Before it was trying to resolve it with all contributions, causing exceptions when multiple contributions were used and the composite could not be fully resolved in one of them.

Added:
    tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
Modified:
    tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java

Modified: tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java?rev=676652&r1=676651&r2=676652&view=diff
==============================================================================
--- tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java (original)
+++ tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java Mon Jul 14 10:20:51 2008
@@ -105,39 +105,6 @@
     /** 
      * Constructs a new SCA node.
      *  
-     * @param configuration the the node configuration information.
-     */
-    NodeImpl(ConfiguredNodeImplementation configuration) {
-        configurationName = configuration.getURI();
-        logger.log(Level.INFO, "Creating node: " + configuration.getURI());
-
-        try {
-            // Initialize the runtime
-            initRuntime();
-
-            URL configurationURL = new URL(configuration.getURI());
-
-            // Resolve contribution URLs
-            for (Contribution contribution : configuration.getContributions()) {
-                URL contributionURL = new URL(configurationURL, contribution.getLocation());
-                contribution.setLocation(contributionURL.toString());
-            }
-
-            // Resolve composite URL
-            URL compositeURL = new URL(configurationURL, configuration.getComposite().getURI());
-            configuration.getComposite().setURI(compositeURL.toString());
-
-            // Configure the node
-            configureNode(configuration);
-
-        } catch (Exception e) {
-            throw new ServiceRuntimeException(e);
-        }
-    }
-
-    /** 
-     * Constructs a new SCA node.
-     *  
      * @param configurationURI the URI of the node configuration information.
      */
     NodeImpl(String configurationURI) {
@@ -391,8 +358,7 @@
                 configuration = findNodeConfiguration(compositeURI, null);
             } else {
                 // Create a node configuration
-                NodeImplementationFactory nodeImplementationFactory =
-                    modelFactories.getFactory(NodeImplementationFactory.class);
+                NodeImplementationFactory nodeImplementationFactory = modelFactories.getFactory(NodeImplementationFactory.class);
                 configuration = nodeImplementationFactory.createConfiguredNodeImplementation();
 
                 // Read the composite model
@@ -488,10 +454,11 @@
             // Load the contribution
             logger.log(Level.INFO, "Loading contribution: " + contributionURL);
             contributions.add(contributionService.contribute(contribution.getURI(), contributionURL, false));
-            analyseProblems();
+            analyzeProblems();
         }
         
         // Resolve the metadata within the context of the contribution
+        //FIXME This doesn't seem to make sense here 
         if (metadata != null) {
             StAXArtifactProcessor<ContributionMetadata> processor =
                 artifactProcessors.getProcessor(ContributionMetadata.class);
@@ -505,40 +472,51 @@
             configuration.setComposite(composites.get(0));
         }
 
-
         // Load the specified composite
-        StAXArtifactProcessor<Composite> compositeProcessor = artifactProcessors.getProcessor(Composite.class);
-        if (configuration.getComposite().getName() == null) {
-            URI uri = URI.create(configuration.getComposite().getURI());
-            if (uri.getScheme() == null) {
-                // For relative URI, try to resolve it within the contributions
-                Artifact file = resolveCompositeArtifact(contributions, uri.toString());
-                if (file == null) {
-                    throw new IllegalArgumentException("Composite is not found in contributions: " + uri);
-                }
-                uri = URI.create(file.getLocation());
+        Contribution contribution;
+        URL compositeURL;
+        
+        URI uri = URI.create(configuration.getComposite().getURI());
+        if (uri.getScheme() == null) {
+            
+            // If the composite URI is a relative URI, try to resolve it within the contributions
+            contribution = contribution(contributions, uri.toString());
+            if (contribution == null) {
+                throw new IllegalArgumentException("Composite is not found in contributions: " + uri);
             }
-            URL compositeURL = uri.toURL();
+            compositeURL = new URL(location(contribution, uri.toString()));
+            
+        } else {
+            
+            // If the composite URI is an absolute URI, use it as is
+            compositeURL = uri.toURL();
+            
+            // And resolve the composite within the scope of the last contribution
+            if (contributions.size() != 0) {
+                contribution = contributions.get(contributions.size() -1);
+            } else {
+                contribution = null;
+            }
+        }
+            
+        // Read the composite
+        StAXArtifactProcessor<Composite> compositeProcessor = artifactProcessors.getProcessor(Composite.class);
+        composite = configuration.getComposite();
+        if (composite.getName() == null) {
             logger.log(Level.INFO, "Loading composite: " + compositeURL);
             InputStream is = compositeURL.openStream();
             XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
             composite = compositeProcessor.read(reader);
             reader.close();
-        } else {
-            composite = configuration.getComposite();
-        }
-
-        analyseProblems();
 
-        // Resolve it within the context of the contribution
-        for (Contribution c : contributions) {
-            compositeProcessor.resolve(composite, c.getModelResolver());
-            if (!composite.isUnresolved()) {
-                break;
-            }
+            analyzeProblems();
         }
 
-        analyseProblems();
+        // Resolve the given composite within the scope of the selected contribution
+        if (contribution != null) {
+            compositeProcessor.resolve(composite, contribution.getModelResolver());
+            analyzeProblems();
+        }
 
         // Create a top level composite to host our composite
         // This is temporary to make the activator happy
@@ -558,21 +536,45 @@
         // Build the composite
         runtime.buildComposite(composite);
 
-        analyseProblems();
+        analyzeProblems();
     }
     
     /**
-     * Search all contributions to resolve the relative composite URI
-     * @param contributions
+     * Returns the artifact representing the given composite.
+     * 
+     * @param contribution
      * @param compositeURI
      * @return
      */
-    private Artifact resolveCompositeArtifact(List<Contribution> contributions, String compositeURI) {
+    private String location(Contribution contribution, String uri) {
+        if (uri != null && uri.startsWith("/")) {
+            uri = uri.substring(1);
+        }
         ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
-        // Remove the leading /
+        Artifact compositeFile = contributionFactory.createArtifact();
+        compositeFile.setUnresolved(true);
+        compositeFile.setURI(uri);
+        ModelResolver resolver = contribution.getModelResolver();
+        Artifact resolved = resolver.resolveModel(Artifact.class, compositeFile);
+        if (resolved != null && !resolved.isUnresolved()) {
+            return resolved.getLocation();
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Returns the contribution containing the given composite.
+     * 
+     * @param contributions
+     * @param compositeURI
+     * @return
+     */
+    private Contribution contribution(List<Contribution> contributions, String compositeURI) {
         if (compositeURI != null && compositeURI.startsWith("/")) {
             compositeURI = compositeURI.substring(1);
         }
+        ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
         Artifact compositeFile = contributionFactory.createArtifact();
         compositeFile.setUnresolved(true);
         compositeFile.setURI(compositeURI);
@@ -580,13 +582,13 @@
             ModelResolver resolver = c.getModelResolver();
             Artifact resolved = resolver.resolveModel(Artifact.class, compositeFile);
             if (resolved != null && !resolved.isUnresolved()) {
-                return resolved;
+                return c;
             }
         }
         return null;
     }
 
-    private void analyseProblems() throws Exception {
+    private void analyzeProblems() throws Exception {
 
         for (Problem problem : monitor.getProblems()) {
             if ((problem.getSeverity() == Severity.ERROR) && (!problem.getMessageId().equals("SchemaError"))) {

Added: tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java?rev=676652&view=auto
==============================================================================
--- tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java (added)
+++ tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java Mon Jul 14 10:20:51 2008
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.node.impl;
+
+/**
+ * NodeUtil
+ *
+ * @version $Rev: $ $Date: $
+ */
+class NodeUtil {
+
+}