From 785dac0b33e8dad10dbb5a65e8f2f4280c29a517 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 28 Jul 2010 21:01:49 +0000 Subject: Add parent artifact to the ProcessorContext git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@980219 13f79535-47bb-0310-9956-ffa450edef68 --- .../introspect/SpringXMLComponentTypeLoader.java | 38 +++++++++++++--------- .../spring/xml/SpringImplementationProcessor.java | 2 +- 2 files changed, 24 insertions(+), 16 deletions(-) (limited to 'sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org') 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 subelement of a // element MUST be unique amongst the subelements of the 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 subelements, // of the 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 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 beans, List services, List references, - List scaproperties) throws ContributionReadException { + List scaproperties, + Monitor monitor) throws ContributionReadException { // The @target attribute of a subelement of a element // MUST have the value of the @name attribute of one of the @@ -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 subelement of a @@ -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 subelement of a @@ -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); -- cgit v1.2.3