diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-28 21:01:49 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-28 21:01:49 +0000 |
commit | 785dac0b33e8dad10dbb5a65e8f2f4280c29a517 (patch) | |
tree | 75c78883848a06c3514ad5849f7aa570d268236a /sca-java-2.x/trunk | |
parent | 9dafe3e2c4d2476cb3ea7789e3f3063418340059 (diff) |
Add parent artifact to the ProcessorContext
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@980219 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
4 files changed, 76 insertions, 27 deletions
diff --git a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java index 75cfab4924..d464af40f2 100644 --- a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java +++ b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java @@ -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.MonitorFactory; */ 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; + } + } diff --git a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java index 232bf9c72f..40a92d74f3 100644 --- a/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java +++ b/sca-java-2.x/trunk/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java @@ -139,7 +139,7 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso 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 ContributionContentProcessor implements ExtendedURLArtifactProcesso } } finally { monitor.popContext(); - context.setContribution(old); + context.setArtifact(oldArtifact); } } @@ -252,23 +252,32 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso 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); diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java index 2cf6d6c031..ec44bc591a 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java @@ -97,10 +97,9 @@ public class SpringXMLComponentTypeLoader { 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 SpringXMLComponentTypeLoader { 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 SpringXMLComponentTypeLoader { * @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 SpringXMLComponentTypeLoader { * @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 SpringXMLComponentTypeLoader { 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 SpringXMLComponentTypeLoader { 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 SpringXMLComponentTypeLoader { // 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 SpringXMLComponentTypeLoader { // 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 SpringXMLComponentTypeLoader { // 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 SpringXMLComponentTypeLoader { 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 SpringXMLComponentTypeLoader { 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 SpringXMLComponentTypeLoader { 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 SpringXMLComponentTypeLoader { isUniquePropertyName = false; } if (!isUniquePropertyName) - error("ScaPropertyNameNotUnique", beans); + error(monitor, "ScaPropertyNameNotUnique", beans); } // end while } diff --git a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java index af3a16cd5d..4b4144f0c8 100644 --- a/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java @@ -207,7 +207,7 @@ public class SpringImplementationProcessor extends BaseStAXArtifactProcessor imp 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); |