You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2010/07/28 23:01:49 UTC

svn commit: r980219 - in /tuscany/sca-java-2.x/trunk/modules: contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ implementation-spring/src/main/java/o...

Author: rfeng
Date: Wed Jul 28 21:01:49 2010
New Revision: 980219

URL: http://svn.apache.org/viewvc?rev=980219&view=rev
Log:
Add parent artifact to the ProcessorContext

Modified:
    tuscany/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java
    tuscany/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
    tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java
    tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java

Modified: tuscany/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java?rev=980219&r1=980218&r2=980219&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java Wed Jul 28 21:01:49 2010
@@ -19,6 +19,7 @@
 
 package org.apache.tuscany.sca.contribution.processor;
 
+import org.apache.tuscany.sca.contribution.Artifact;
 import org.apache.tuscany.sca.contribution.Contribution;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.UtilityExtensionPoint;
@@ -32,6 +33,7 @@ import org.apache.tuscany.sca.monitor.Mo
  */
 public class ProcessorContext {
     protected Contribution contribution;
+    protected Artifact artifact;
     protected Monitor monitor;
     protected Object parentModel;
 
@@ -62,10 +64,19 @@ public class ProcessorContext {
         this.monitor = new DefaultMonitorFactory().createMonitor();
     }
 
+    /**
+     * Get the current contribution
+     * @return The current contribution
+     */
     public Contribution getContribution() {
         return contribution;
     }
 
+    /**
+     * Set the current contribution
+     * @param contribution
+     * @return
+     */
     public Contribution setContribution(Contribution contribution) {
         Contribution old = this.contribution;
         this.contribution = contribution;
@@ -92,4 +103,25 @@ public class ProcessorContext {
         return old;
     }
 
+    /**
+     * Get the current artifact
+     * @return The current artifact
+     */
+    public Artifact getArtifact() {
+        return artifact;
+    }
+
+    /**
+     * Set the current artifact. This should be called by URLArtifactProcessor to set the document
+     * context (such as the URI of the composite file).
+     * 
+     * @param artifact The new artifact
+     * @return The old artifact
+     */
+    public Artifact setArtifact(Artifact artifact) {
+        Artifact old = this.artifact;
+        this.artifact = artifact;
+        return old;
+    }
+
 }

Modified: tuscany/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java?rev=980219&r1=980218&r2=980219&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java Wed Jul 28 21:01:49 2010
@@ -139,7 +139,7 @@ public class ContributionContentProcesso
                 
                 monitor.pushContext("Artifact: " + artifact.getURI());
     
-                old = context.setContribution(contribution);
+                Artifact oldArtifact = context.setArtifact(artifact);
                 try {
                     // Read each artifact
                     URL artifactLocationURL = null;
@@ -169,7 +169,7 @@ public class ContributionContentProcesso
                     }
                 } finally {
                     monitor.popContext();
-                    context.setContribution(old);
+                    context.setArtifact(oldArtifact);
                 }                    
             }
             
@@ -252,23 +252,32 @@ public class ContributionContentProcesso
 	        for (Artifact artifact : contribution.getArtifacts()) {
 	            Object model = artifact.getModel();
 	            if (model != null) {
+	                Artifact oldArtifact = context.setArtifact(artifact);
 	                try {
 	                   artifactProcessor.resolve(model, contributionResolver, context);
 	                } catch (Throwable e) {
 	                    throw new ContributionResolveException(e);
+	                } finally {
+	                    context.setArtifact(oldArtifact);
 	                }
 	            }
 	        }
 	
-	        // Resolve deployable composites
-	        List<Composite> deployables = contribution.getDeployables();
-	        for (int i = 0, n = deployables.size(); i < n; i++) {
-	            Composite deployable = deployables.get(i);
-	            Composite resolved = (Composite)contributionResolver.resolveModel(Composite.class, deployable, context);
-	            if (resolved != deployable) {
-	                deployables.set(i, resolved);
-	            }
-	        } // end for
+            // Resolve deployable composites
+            List<Composite> deployables = contribution.getDeployables();
+            Artifact oldArtifact = context.setArtifact(contribution);
+            try {
+                for (int i = 0, n = deployables.size(); i < n; i++) {
+                    Composite deployable = deployables.get(i);
+                    Composite resolved =
+                        (Composite)contributionResolver.resolveModel(Composite.class, deployable, context);
+                    if (resolved != deployable) {
+                        deployables.set(i, resolved);
+                    }
+                } // end for
+            } finally {
+                context.setArtifact(oldArtifact);
+            }
     	} finally {
     		monitor.popContext();
     		context.setContribution(old);

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java?rev=980219&r1=980218&r2=980219&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java Wed Jul 28 21:01:49 2010
@@ -97,10 +97,9 @@ public class SpringXMLComponentTypeLoade
     private JavaInterfaceFactory javaFactory;
     private PolicyFactory policyFactory;
     private PolicySubjectProcessor policyProcessor;
-    private Monitor monitor;
     private SpringBeanIntrospector beanIntrospector;
 
-    public SpringXMLComponentTypeLoader(ExtensionPointRegistry registry, Monitor monitor) {
+    public SpringXMLComponentTypeLoader(ExtensionPointRegistry registry) {
         super();
         this.registry = registry;
         FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
@@ -110,7 +109,6 @@ public class SpringXMLComponentTypeLoade
         this.policyProcessor = new PolicySubjectProcessor(policyFactory);
         this.contributionFactory = factories.getFactory(ContributionFactory.class);
         this.xmlInputFactory = factories.getFactory(XMLInputFactory.class);
-        this.monitor = monitor;
     }
 
     /**
@@ -120,7 +118,7 @@ public class SpringXMLComponentTypeLoade
      * @param message
      * @param model
      */
-    private void error(String message, Object model, Exception ex) {
+    private void error(Monitor monitor, String message, Object model, Exception ex) {
         if (monitor != null) {
             Problem problem =
                 monitor.createProblem(this.getClass().getName(),
@@ -140,7 +138,7 @@ public class SpringXMLComponentTypeLoade
      * @param message
      * @param model
      */
-    private void error(String message, Object model, Object... messageParameters) {
+    private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
         if (monitor != null) {
             Problem problem =
                 monitor.createProblem(this.getClass().getName(),
@@ -234,7 +232,7 @@ public class SpringXMLComponentTypeLoade
                                       appCxtProperties,
                                       context);
                 // Validate the beans from individual application context for uniqueness
-                validateBeans(appCxtBeans, appCxtServices, appCxtReferences, appCxtProperties);
+                validateBeans(appCxtBeans, appCxtServices, appCxtReferences, appCxtProperties, context.getMonitor());
                 // Add all the validated beans to the generic list
                 beans.addAll(appCxtBeans);
                 services.addAll(appCxtServices);
@@ -261,9 +259,18 @@ public class SpringXMLComponentTypeLoade
         URL resource = null;
         URI uri = URI.create(contextPath);
         if (!uri.isAbsolute()) {
+            Artifact parent = context.getArtifact();
+            if (parent != null && parent.getURI() != null) {
+                URI base = URI.create("/" + parent.getURI());
+                uri = base.resolve(uri);
+                // Remove the leading / to make artifact resolver happy
+                if (uri.toString().startsWith("/")) {
+                    uri = URI.create(uri.toString().substring(1));
+                }
+            }
             Artifact artifact = contributionFactory.createArtifact();
             artifact.setUnresolved(true);
-            artifact.setURI(contextPath);
+            artifact.setURI(uri.toString());
             artifact = resolver.resolveModel(Artifact.class, artifact, context);
             if (!artifact.isUnresolved()) {
                 resource = new URL(artifact.getLocation());
@@ -340,7 +347,7 @@ public class SpringXMLComponentTypeLoade
                             // The value of the @name attribute of an <sca:service/> subelement of a <beans/> 
                             // element MUST be unique amongst the <sca:service/> subelements of the <beans/> element.
                             if (!services.isEmpty() && (services.contains(reader.getAttributeValue(null, "name"))))
-                                error("ScaServiceNameNotUnique", resolver);
+                                error(context.getMonitor(), "ScaServiceNameNotUnique", resolver);
 
                             SpringSCAServiceElement service =
                                 new SpringSCAServiceElement(reader.getAttributeValue(null, "name"),
@@ -354,7 +361,7 @@ public class SpringXMLComponentTypeLoade
                             // element MUST be unique amongst the @name attributes of the <sca:reference/> subelements, 
                             // of the <beans/> element.
                             if (!references.isEmpty() && (references.contains(reader.getAttributeValue(null, "name"))))
-                                error("ScaReferenceNameNotUnique", resolver);
+                                error(context.getMonitor(), "ScaReferenceNameNotUnique", resolver);
 
                             SpringSCAReferenceElement reference =
                                 new SpringSCAReferenceElement(reader.getAttributeValue(null, "name"),
@@ -369,7 +376,7 @@ public class SpringXMLComponentTypeLoade
                             // of the <beans/> element.
                             if (!scaproperties.isEmpty() && (scaproperties.contains(reader.getAttributeValue(null,
                                                                                                              "name"))))
-                                error("ScaPropertyNameNotUnique", resolver);
+                                error(context.getMonitor(), "ScaPropertyNameNotUnique", resolver);
 
                             SpringSCAPropertyElement scaproperty =
                                 new SpringSCAPropertyElement(reader.getAttributeValue(null, "name"),
@@ -875,7 +882,8 @@ public class SpringXMLComponentTypeLoade
     private void validateBeans(List<SpringBeanElement> beans,
                                List<SpringSCAServiceElement> services,
                                List<SpringSCAReferenceElement> references,
-                               List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException {
+                               List<SpringSCAPropertyElement> scaproperties,
+                               Monitor monitor) throws ContributionReadException {
 
         // The @target attribute of a <service/> subelement of a <beans/> element 
         // MUST have the value of the @name attribute of one of the <bean/> 
@@ -891,7 +899,7 @@ public class SpringXMLComponentTypeLoade
                     targetBeanExists = true;
             }
             if (!targetBeanExists)
-                error("TargetBeanDoesNotExist", beans);
+                error(monitor, "TargetBeanDoesNotExist", beans);
         } // end while
 
         // The value of the @name attribute of an <sca:reference/> subelement of a <beans/> 
@@ -922,9 +930,9 @@ public class SpringXMLComponentTypeLoade
                     isUniqueReferenceName = false;
             }
             if (!defaultBeanExists)
-                error("DefaultBeanDoesNotExist", beans);
+                error(monitor, "DefaultBeanDoesNotExist", beans);
             if (!isUniqueReferenceName)
-                error("ScaReferenceNameNotUnique", beans);
+                error(monitor, "ScaReferenceNameNotUnique", beans);
         } // end while
 
         // The value of the @name attribute of an <sca:property/> subelement of a <beans/> 
@@ -947,7 +955,7 @@ public class SpringXMLComponentTypeLoade
                     isUniquePropertyName = false;
             }
             if (!isUniquePropertyName)
-                error("ScaPropertyNameNotUnique", beans);
+                error(monitor, "ScaPropertyNameNotUnique", beans);
         } // end while
     }
 

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java?rev=980219&r1=980218&r2=980219&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java Wed Jul 28 21:01:49 2010
@@ -207,7 +207,7 @@ public class SpringImplementationProcess
 
         Monitor monitor = context.getMonitor();
         /* Load the Spring component type by reading the Spring application context */
-        SpringXMLComponentTypeLoader springLoader = new SpringXMLComponentTypeLoader(registry, monitor);
+        SpringXMLComponentTypeLoader springLoader = new SpringXMLComponentTypeLoader(registry);
         try {
             // Load the Spring Implementation information from its application context file...
             springLoader.load(springImplementation, resolver, context);