diff options
author | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-15 11:05:19 +0000 |
---|---|---|
committer | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-15 11:05:19 +0000 |
commit | 3570ea7c8fba83ef7cb70132b830f0205621360d (patch) | |
tree | c8ed44478281270f7d3ea17fc775341f929844a1 /java/sca/modules | |
parent | 83dbdcd69a062a74fb7b7b14ee4ef1174487b6ad (diff) |
Fixes for TUSCANY-3079
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@784727 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
5 files changed, 153 insertions, 62 deletions
diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java index 9e586e1f4f..47f64934b4 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java @@ -19,7 +19,10 @@ package org.apache.tuscany.sca.implementation.bpel.xml; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.xml.namespace.QName; @@ -30,6 +33,7 @@ import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; /** * A Model Resolver for BPEL process models. @@ -56,27 +60,50 @@ public class BPELDocumentModelResolver implements ModelResolver { public <T> T resolveModel(Class<T> modelClass, T unresolved) { - // Lookup a definition for the given namespace - QName qname = ((BPELProcessDefinition)unresolved).getName(); - BPELProcessDefinition resolved = (BPELProcessDefinition) map.get(qname); - if (resolved != null) { - return modelClass.cast(resolved); - } - - // No definition found, delegate the resolution to the imports + BPELProcessDefinition resolved = null; + QName qname = ((BPELProcessDefinition)unresolved).getName(); + + // Lookup a definition for the given namespace, from imports + List<String> locations = new ArrayList<String>(); + // Collection of namespace imports with location + Map<String, NamespaceImport> locationMap = new HashMap<String, NamespaceImport>(); for (Import import_ : this.contribution.getImports()) { if (import_ instanceof NamespaceImport) { NamespaceImport namespaceImport = (NamespaceImport)import_; if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) { - - // Delegate the resolution to the import resolver - resolved = namespaceImport.getModelResolver().resolveModel(BPELProcessDefinition.class, (BPELProcessDefinition)unresolved); - if (!resolved.isUnresolved()) { - return modelClass.cast(resolved); + if (namespaceImport.getLocation() == null) { + // Delegate the resolution to the import resolver + resolved = namespaceImport.getModelResolver().resolveModel(BPELProcessDefinition.class, (BPELProcessDefinition)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } else { + // We might have multiple imports for the same namespace, + // need to search them in lexical order. + locations.add(namespaceImport.getLocation()); } } } } + // Search namespace imports with locations in lexical order + Collections.sort(locations); + for (String location : locations) { + NamespaceImport namespaceImport = (NamespaceImport)locationMap.get(location); + // Delegate the resolution to the namespace import resolver + resolved = + namespaceImport.getModelResolver().resolveModel(BPELProcessDefinition.class, (BPELProcessDefinition)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } + + + // Not found, Lookup a definition for the given namespace, within contribution + resolved = (BPELProcessDefinition) map.get(qname); + if (resolved != null) { + return modelClass.cast(resolved); + } + return (T)unresolved; } diff --git a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java index 8c77acc93d..686236d1c2 100644 --- a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java +++ b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Collections; import javax.wsdl.Definition; import javax.wsdl.Operation; @@ -284,29 +285,32 @@ public class WSDLModelResolver implements ModelResolver { public <T> T resolveModel(Class<T> modelClass, T unresolved) { - // Lookup a definition for the given namespace - String namespace = ((WSDLDefinition)unresolved).getNamespace(); - if (namespace == null) { + WSDLDefinition resolved = null; + String namespace = ((WSDLDefinition)unresolved).getNamespace(); + if (namespace == null) { return modelClass.cast(unresolved); - } - List<WSDLDefinition> list = map.get(namespace); - WSDLDefinition resolved = aggregate(list); - if (resolved != null && !resolved.isUnresolved()) { - return modelClass.cast(resolved); - } - - // No definition found, delegate the resolution to the imports + } + + // Lookup a definition for the given namespace, from imports + List<String> locations = new ArrayList<String>(); + // Collection of namespace imports with location + Map<String, NamespaceImport> locationMap = new HashMap<String, NamespaceImport>(); for (Import import_ : this.contribution.getImports()) { if (import_ instanceof NamespaceImport) { NamespaceImport namespaceImport = (NamespaceImport)import_; if (namespaceImport.getNamespace().equals(namespace)) { - - // Delegate the resolution to the namespace import resolver - resolved = - namespaceImport.getModelResolver().resolveModel(WSDLDefinition.class, - (WSDLDefinition)unresolved); - if (!resolved.isUnresolved()) { - return modelClass.cast(resolved); + if (namespaceImport.getLocation() == null) { + // Delegate the resolution to the namespace import resolver + resolved = + namespaceImport.getModelResolver().resolveModel(WSDLDefinition.class, + (WSDLDefinition)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } else { + // We might have multiple imports for the same namespace, + // need to search them in lexical order. + locations.add(namespaceImport.getLocation()); } } } else if (import_ instanceof DefaultImport) { @@ -319,7 +323,28 @@ public class WSDLModelResolver implements ModelResolver { return modelClass.cast(resolved); } } + } + // Search namespace imports with locations in lexical order + Collections.sort(locations); + for (String location : locations) { + NamespaceImport namespaceImport = (NamespaceImport)locationMap.get(location); + // Delegate the resolution to the namespace import resolver + resolved = + namespaceImport.getModelResolver().resolveModel(WSDLDefinition.class, + (WSDLDefinition)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } + + + // Not found, lookup a definition for the given namespace, within contribution + List<WSDLDefinition> list = map.get(namespace); + resolved = aggregate(list); + if (resolved != null && !resolved.isUnresolved()) { + return modelClass.cast(resolved); } + return modelClass.cast(unresolved); } diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java index 9009469d23..502d0a8a2d 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java @@ -28,8 +28,13 @@ import java.net.URL; import javax.xml.namespace.QName;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
@@ -45,16 +50,23 @@ import org.junit.Test; public class WSDLTestCase {
private ExtensibleURLArtifactProcessor documentProcessor;
+ private ContributionFactory contributionFactory;
private WSDLModelResolver wsdlResolver;
+ private ModelResolver resolver;
@Before
public void setUp() throws Exception {
ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
-
+
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
- wsdlResolver = new WSDLModelResolver(null, modelFactories);
+ contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ Contribution contribution = contributionFactory.createContribution();
+ ModelResolverExtensionPoint modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
+ resolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories);
+ contribution.setModelResolver(resolver);
+ wsdlResolver = new WSDLModelResolver(contribution, modelFactories);
}
@Test
diff --git a/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java b/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java index c30d3ebbd6..2f303a295c 100644 --- a/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java +++ b/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Collections; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; @@ -84,9 +85,54 @@ public class XSDModelResolver implements ModelResolver { public <T> T resolveModel(Class<T> modelClass, T unresolved) { - XSDefinition definition = (XSDefinition)unresolved; - // Lookup a definition for the given namespace + XSDefinition definition = (XSDefinition)unresolved; String namespace = definition.getNamespace(); + XSDefinition resolved = null; + + // Lookup a definition for the given namespace, from imports + List<String> locations = new ArrayList<String>(); + // Collection of namespace imports with location + Map<String, NamespaceImport> locationMap = new HashMap<String, NamespaceImport>(); + for (Import import_ : this.contribution.getImports()) { + if (import_ instanceof NamespaceImport) { + NamespaceImport namespaceImport = (NamespaceImport)import_; + if (namespaceImport.getNamespace().equals(namespace)) { + if (namespaceImport.getLocation() == null) { + // Delegate the resolution to the namespace import resolver + resolved = + namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } else { + // We might have multiple imports for the same namespace, + // need to search them in lexical order. + locations.add(namespaceImport.getLocation()); + } + } + } else if (import_ instanceof DefaultImport) { + + // Delegate the resolution to the default import resolver + resolved = + import_.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } + } + // Search namespace imports with location in lexical order + Collections.sort(locations); + for (String location : locations) { + NamespaceImport namespaceImport = (NamespaceImport)locationMap.get(location); + // Delegate the resolution to the namespace import resolver + resolved = + namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } + + // Not found, lookup a definition for the given namespace, within the contribution List<XSDefinition> list = map.get(namespace); XSDefinition modelXSD = null; if (list != null && definition.getDocument() != null) { @@ -102,8 +148,7 @@ public class XSDModelResolver implements ModelResolver { list = new ArrayList<XSDefinition>(); list.add(definition); map.put(namespace, list); - } - XSDefinition resolved = null; + } try { resolved = aggregate(list); } catch (IOException e) { @@ -120,30 +165,7 @@ public class XSDModelResolver implements ModelResolver { } return modelClass.cast(resolved); } - - // No definition found, delegate the resolution to the imports - for (Import import_ : this.contribution.getImports()) { - if (import_ instanceof NamespaceImport) { - NamespaceImport namespaceImport = (NamespaceImport)import_; - if (namespaceImport.getNamespace().equals(namespace)) { - - // Delegate the resolution to the namespace import resolver - resolved = - namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); - if (!resolved.isUnresolved()) { - return modelClass.cast(resolved); - } - } - } else if (import_ instanceof DefaultImport) { - - // Delegate the resolution to the default import resolver - resolved = - import_.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); - if (!resolved.isUnresolved()) { - return modelClass.cast(resolved); - } - } - } + return modelClass.cast(unresolved); } diff --git a/java/sca/modules/xsd/src/test/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessorTestCase.java b/java/sca/modules/xsd/src/test/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessorTestCase.java index a20d5f6f58..3862973eca 100644 --- a/java/sca/modules/xsd/src/test/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessorTestCase.java +++ b/java/sca/modules/xsd/src/test/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessorTestCase.java @@ -24,6 +24,8 @@ import java.net.URL; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; @@ -44,6 +46,7 @@ import org.junit.Test; */ public class XSDDocumentProcessorTestCase { private URLArtifactProcessor<Object> documentProcessor; + private ContributionFactory contributionFactory; private ModelResolver resolver; /** @@ -55,7 +58,9 @@ public class XSDDocumentProcessorTestCase { URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - resolver = new XSDModelResolver(null, modelFactories); + contributionFactory = modelFactories.getFactory(ContributionFactory.class); + Contribution contribution = contributionFactory.createContribution(); + resolver = new XSDModelResolver(contribution, modelFactories); } @Test |