diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-08 05:47:21 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-08 05:47:21 +0000 |
commit | ab5e85568fbb24bc9412afd79854892cb067bdd8 (patch) | |
tree | c1c00d3adac3b776a5608c6602c98b94faa820af /sca-java-2.x/trunk/modules/implementation-widget/src | |
parent | 22333d2e9bed64dbc8507faad881ff8b705fe3b0 (diff) |
Allowing more flexible resolution for the widget artifact
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1043310 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/implementation-widget/src')
-rw-r--r-- | sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java b/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java index bf84a15aa6..39e6ae0606 100644 --- a/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java @@ -20,7 +20,11 @@ package org.apache.tuscany.sca.implementation.widget; import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import javax.xml.namespace.QName; @@ -61,7 +65,6 @@ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor imp implementationFactory = modelFactories.getFactory(WidgetImplementationFactory.class); } - public QName getArtifactType() { // Returns the QName of the XML element processed by this processor return WidgetImplementation.TYPE; @@ -103,26 +106,48 @@ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor imp public void resolve(WidgetImplementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (implementation != null) { - // Resolve the resource directory location + // Resolve the resource directory location Artifact artifact = contributionFactory.createArtifact(); artifact.setURI(implementation.getLocation()); Artifact resolved = resolver.resolveModel(Artifact.class, artifact, context); - if (resolved.getLocation() != null) { - try { - implementation.setLocationURL(new URL(resolved.getLocation())); - - //introspect implementation - WidgetImplementationIntrospector widgetIntrospector = - new WidgetImplementationIntrospector(registry, implementation); - widgetIntrospector.introspectImplementation(); - - implementation.setUnresolved(false); - } catch (IOException e) { - ContributionResolveException ce = new ContributionResolveException(e); - error(context.getMonitor(), "ContributionResolveException", resolver, ce); - //throw ce; + + if(resolved.getLocation() == null) { + URL resource = null; + URI uri = URI.create(implementation.getLocation()); + Artifact parent = context.getArtifact(); + if (!uri.isAbsolute()) { + 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)); + } + } + } + + + // The resource can be out of scope of the contribution root + if (parent != null && parent.getLocation() != null) { + try { + resource = new URL(new URL(parent.getLocation()), implementation.getLocation()); + + implementation.setLocationURL(resource); + + //introspect implementation + WidgetImplementationIntrospector widgetIntrospector = + new WidgetImplementationIntrospector(registry, implementation); + widgetIntrospector.introspectImplementation(); + + implementation.setUnresolved(false); + } catch (MalformedURLException e) { + ContributionResolveException ce = new ContributionResolveException(e); + error(context.getMonitor(), "ContributionResolveException", resolver, ce); + } } - } else { + } + + if (implementation.isUnresolved()) { error(context.getMonitor(), "CouldNotResolveLocation", resolver, implementation.getLocation()); //throw new ContributionResolveException("Could not resolve implementation.widget location: " + implementation.getLocation()); } |