summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/xsd/src
diff options
context:
space:
mode:
authorramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68>2009-06-15 11:05:19 +0000
committerramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68>2009-06-15 11:05:19 +0000
commit3570ea7c8fba83ef7cb70132b830f0205621360d (patch)
treec8ed44478281270f7d3ea17fc775341f929844a1 /java/sca/modules/xsd/src
parent83dbdcd69a062a74fb7b7b14ee4ef1174487b6ad (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/xsd/src')
-rw-r--r--java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java78
-rw-r--r--java/sca/modules/xsd/src/test/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessorTestCase.java7
2 files changed, 56 insertions, 29 deletions
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