From 1db9c0136867e3ed83097365bb7d80a368b4d11e Mon Sep 17 00:00:00 2001 From: ramkumar Date: Thu, 26 Mar 2009 10:24:11 +0000 Subject: Fixes for TUSCANY-2906 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@758583 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/xsd/xml/XSDModelResolver.java | 51 ++++++++++++++++------ 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'branches/sca-java-1.x/modules') 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 resolveModel(Class 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 list = new ArrayList(); + 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 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(); - 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 definitions) throws IOException { + private XSDefinition aggregate(List definitions) throws ContributionRuntimeException { if (definitions == null || definitions.size() == 0) { return null; } -- cgit v1.2.3