summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/xsd-xml
diff options
context:
space:
mode:
authornash <nash@13f79535-47bb-0310-9956-ffa450edef68>2008-12-01 01:50:28 +0000
committernash <nash@13f79535-47bb-0310-9956-ffa450edef68>2008-12-01 01:50:28 +0000
commitbe5b76b69f4bd8f8e401cc284fcca5879e8b0d7c (patch)
treea21ccd13ba605ffe0c4f73506408c4d9e55df8d4 /branches/sca-java-1.x/modules/xsd-xml
parent5a47268dd3aa80c86d829fa0db1567ecf82278aa (diff)
Fix TUSCANY-2698
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@721944 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/xsd-xml')
-rw-r--r--branches/sca-java-1.x/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java47
1 files changed, 40 insertions, 7 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 3e22b49d31..f05a2e4cbe 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
@@ -156,7 +156,17 @@ public class XSDModelResolver implements ModelResolver {
if (definition.getLocation() != null) {
uri = definition.getLocation().toString();
}
- XmlSchema schema = schemaCollection.read(definition.getDocument(), uri, null);
+ XmlSchema schema = null;
+ try {
+ schema = schemaCollection.read(definition.getDocument(), uri, null);
+ } catch (RuntimeException e) {
+ // find original cause of the problem
+ Throwable cause = e;
+ while (cause.getCause() != null) {
+ cause = cause.getCause();
+ }
+ throw new ContributionRuntimeException(cause);
+ }
definition.setSchemaCollection(schemaCollection);
definition.setSchema(schema);
definition.setUnresolved(false);
@@ -168,17 +178,35 @@ public class XSDModelResolver implements ModelResolver {
// Read an XSD document
InputSource xsd = XMLDocumentHelper.getInputSource(definition.getLocation().toURL());
for (XmlSchema d : schemaCollection.getXmlSchemas()) {
- if (d.getTargetNamespace().equals(definition.getNamespace())) {
+ if (isSameNamespace(d.getTargetNamespace(), definition.getNamespace())) {
if (d.getSourceURI().equals(definition.getLocation().toString()))
return;
}
}
- XmlSchema schema = schemaCollection.read(xsd, null);
+ XmlSchema schema = null;
+ try {
+ schema = schemaCollection.read(xsd, null);
+ } catch (RuntimeException e) {
+ // find original cause of the problem
+ Throwable cause = e;
+ while (cause.getCause() != null) {
+ cause = cause.getCause();
+ }
+ throw new ContributionRuntimeException(cause);
+ }
definition.setSchemaCollection(schemaCollection);
definition.setSchema(schema);
}
}
+ private boolean isSameNamespace(String ns1, String ns2) {
+ if (ns1 == null) {
+ return ns2 == null;
+ } else {
+ return ns1.equals(ns2);
+ }
+ }
+
/**
* Create a facade XmlSchema which includes all the definitions
*
@@ -249,9 +277,7 @@ public class XSDModelResolver implements ModelResolver {
this.contribution = contribution;
}
- public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace,
- java.lang.String schemaLocation,
- java.lang.String baseUri) {
+ public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) {
try {
if (schemaLocation == null) {
return null;
@@ -266,12 +292,19 @@ public class XSDModelResolver implements ModelResolver {
break;
}
}
+ if (url == null) {
+ // URI not found in the contribution; return a default InputSource
+ // so that the XmlSchema code will produce a useful diagnostic
+ return new InputSource(schemaLocation);
+ }
} else {
url = new URL(new URL(baseUri), schemaLocation);
}
return XMLDocumentHelper.getInputSource(url);
} catch (IOException e) {
- return null;
+ // Invalid URI; return a default InputSource so that the
+ // XmlSchema code will produce a useful diagnostic
+ return new InputSource(schemaLocation);
}
}
}