summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules
diff options
context:
space:
mode:
authorramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68>2009-03-26 10:24:11 +0000
committerramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68>2009-03-26 10:24:11 +0000
commit1db9c0136867e3ed83097365bb7d80a368b4d11e (patch)
treefed7a019e255605fc758fde51e2af54d24dbdf51 /branches/sca-java-1.x/modules
parent94aadd0d3038eb9be60642ff6eb0d1a11a600be4 (diff)
Fixes for TUSCANY-2906
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@758583 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules')
-rw-r--r--branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java51
1 files changed, 38 insertions, 13 deletions
diff --git a/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java b/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
index f05a2e4cbe..c12116f786 100644
--- a/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
+++ b/branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java
@@ -85,8 +85,27 @@ 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
String namespace = definition.getNamespace();
+ XSDefinition resolved = null;
+
+ // Lookup for a definition using the non-sca mechanism
+ if (definition.getDocument() != null) {
+ try {
+ List<XSDefinition> list = new ArrayList<XSDefinition>();
+ list.add(definition);
+ map.put(namespace, list);
+ resolved = aggregate(list);
+ // no exception thrown, then its resolved.
+ if (resolved != null && !resolved.isUnresolved()) {
+ return modelClass.cast(resolved);
+ }
+ } catch (ContributionRuntimeException e) {
+ // do nothing, lookup using sca mechanism
+ }
+ }
+
+ // Lookup a definition for the given namespace within the
+ // current contribution.
List<XSDefinition> list = map.get(namespace);
XSDefinition modelXSD = null;
if (list != null && definition.getDocument() != null) {
@@ -96,17 +115,10 @@ public class XSDModelResolver implements ModelResolver {
modelXSD = list.get(index);
modelXSD.setDocument(definition.getDocument());
}
- }
- if (list == null && definition.getDocument() != null) {
- // Hit for the 1st time
- list = new ArrayList<XSDefinition>();
- list.add(definition);
- map.put(namespace, list);
- }
- XSDefinition resolved = null;
+ }
try {
resolved = aggregate(list);
- } catch (IOException e) {
+ } catch (ContributionRuntimeException e) {
throw new ContributionRuntimeException(e);
}
if (resolved != null && !resolved.isUnresolved()) {
@@ -147,7 +159,7 @@ public class XSDModelResolver implements ModelResolver {
return modelClass.cast(unresolved);
}
- private void loadOnDemand(XSDefinition definition) throws IOException {
+ private void loadOnDemand(XSDefinition definition) throws ContributionRuntimeException {
if (definition.getSchema() != null) {
return;
}
@@ -155,6 +167,14 @@ public class XSDModelResolver implements ModelResolver {
String uri = null;
if (definition.getLocation() != null) {
uri = definition.getLocation().toString();
+ }
+ for (XmlSchema d : schemaCollection.getXmlSchemas()) {
+ if (d.getSourceURI() != null && d.getSourceURI().equals(uri)) {
+ definition.setSchemaCollection(schemaCollection);
+ definition.setSchema(d);
+ definition.setUnresolved(false);
+ return;
+ }
}
XmlSchema schema = null;
try {
@@ -176,7 +196,12 @@ public class XSDModelResolver implements ModelResolver {
return;
}
// Read an XSD document
- InputSource xsd = XMLDocumentHelper.getInputSource(definition.getLocation().toURL());
+ InputSource xsd;
+ try {
+ xsd = XMLDocumentHelper.getInputSource(definition.getLocation().toURL());
+ } catch (IOException e) {
+ throw new ContributionRuntimeException(e);
+ }
for (XmlSchema d : schemaCollection.getXmlSchemas()) {
if (isSameNamespace(d.getTargetNamespace(), definition.getNamespace())) {
if (d.getSourceURI().equals(definition.getLocation().toString()))
@@ -214,7 +239,7 @@ public class XSDModelResolver implements ModelResolver {
* namespace
* @return The aggregated XmlSchema
*/
- private XSDefinition aggregate(List<XSDefinition> definitions) throws IOException {
+ private XSDefinition aggregate(List<XSDefinition> definitions) throws ContributionRuntimeException {
if (definitions == null || definitions.size() == 0) {
return null;
}