From 94aadd0d3038eb9be60642ff6eb0d1a11a600be4 Mon Sep 17 00:00:00 2001 From: ramkumar Date: Thu, 26 Mar 2009 10:22:47 +0000 Subject: Fixes for TUSCANY-2906 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@758582 13f79535-47bb-0310-9956-ffa450edef68 --- .../interfacedef/wsdl/xml/WSDLModelResolver.java | 82 ++++++++++++++++------ 1 file changed, 62 insertions(+), 20 deletions(-) (limited to 'branches/sca-java-1.x/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml') diff --git a/branches/sca-java-1.x/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java b/branches/sca-java-1.x/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java index 9c23458743..cb7072de62 100644 --- a/branches/sca-java-1.x/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java +++ b/branches/sca-java-1.x/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java @@ -205,7 +205,7 @@ public class WSDLModelResolver implements ModelResolver { } latestImportURI = url.toString(); return XMLDocumentHelper.getInputSource(url); - } catch (Exception e) { + } catch (IOException e) { throw new ContributionRuntimeException(e); } } @@ -247,18 +247,18 @@ public class WSDLModelResolver implements ModelResolver { * @param definitions A list of the WSDL definitions under the same target namespace * @return The aggregated WSDL definition */ - private WSDLDefinition aggregate(List definitions) { + private WSDLDefinition aggregate(List definitions) throws ContributionReadException { if (definitions == null || definitions.size() == 0) { return null; } if (definitions.size() == 1) { WSDLDefinition d = definitions.get(0); - loadOnDemand(d); + loadDefinition(d); return d; } WSDLDefinition aggregated = wsdlFactory.createWSDLDefinition(); for (WSDLDefinition d : definitions) { - loadOnDemand(d); + loadDefinition(d); } Definition facade = wsdl4jFactory.newDefinition(); String ns = definitions.get(0).getNamespace(); @@ -290,7 +290,12 @@ public class WSDLModelResolver implements ModelResolver { return modelClass.cast(unresolved); } List list = map.get(namespace); - WSDLDefinition resolved = aggregate(list); + WSDLDefinition resolved = null; + try { + resolved = aggregate(list); + } catch (ContributionReadException e) { + throw new RuntimeException(e); + } if (resolved != null && !resolved.isUnresolved()) { return modelClass.cast(resolved); } @@ -322,23 +327,37 @@ public class WSDLModelResolver implements ModelResolver { } return modelClass.cast(unresolved); } - - /** - * Load the WSDL definition on demand - * @param def - */ - private void loadOnDemand(WSDLDefinition def) { - if (def.getDefinition() == null && def.getLocation() != null) { - // Load the definition on-demand + + // Use non-sca mechanism to resolve the import location, if not + // found then use the sca mechanism + private T resolveImports (Class modelClass, WSDLDefinition unresolved) { + + WSDLDefinition resolved = null; + if (unresolved.getDefinition() == null && unresolved.getLocation() != null) { try { - loadDefinition(def); + // Load the definition using non-sca mechanism. + List list = new ArrayList(); + list.add(unresolved); + map.put(unresolved.getNamespace(), list); + resolved = aggregate(list); + // if no exception then its resolved. + if (unresolved.getNamespace().equals(resolved.getDefinition().getTargetNamespace())) { + resolved.setNamespace(resolved.getDefinition().getTargetNamespace()); + resolved.setUnresolved(false); + resolved.setURI(resolved.getLocation()); + return modelClass.cast(resolved); + } } catch (ContributionReadException e) { - throw new RuntimeException(e); + // Load the definition using sca mechanism. + resolved = resolveModel(WSDLDefinition.class, unresolved); + if (resolved != null && !resolved.isUnresolved()) { + return modelClass.cast(resolved); + } } } - } - - // private Map loadedDefinitions = new Hashtable(); + + return modelClass.cast(unresolved); + } /** * Load the WSDL definition and inline schemas @@ -373,7 +392,30 @@ public class WSDLModelResolver implements ModelResolver { WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); wsdlDefinition.setUnresolved(true); wsdlDefinition.setNamespace(entry.getKey()); - WSDLDefinition resolved = resolveModel(WSDLDefinition.class, wsdlDefinition); + WSDLDefinition resolved = null; + for (javax.wsdl.Import imp : entry.getValue()) { + try { + wsdlDefinition.setLocation(new URI(imp.getDefinition().getDocumentBaseURI())); + resolved = resolveImports(WSDLDefinition.class, wsdlDefinition); + if (!resolved.isUnresolved()) { + if (resolved.getDefinition().getDocumentBaseURI().equals(imp.getDefinition().getDocumentBaseURI())) { + // this WSDLDefinition contains the imported document + wsdlDef.getImportedDefinitions().add(resolved); + } else { + // this is a facade, so look in its imported definitions + for (WSDLDefinition def : resolved.getImportedDefinitions()) { + if (def.getDefinition().getDocumentBaseURI().equals(imp.getDefinition().getDocumentBaseURI())) { + wsdlDef.getImportedDefinitions().add(def); + break; + } + } + } + } + } catch (Exception e) { + throw new ContributionReadException(e); + } + } + /*resolved = resolveImports(WSDLDefinition.class, wsdlDefinition); if (!resolved.isUnresolved()) { for (javax.wsdl.Import imp : entry.getValue()) { if (resolved.getDefinition().getDocumentBaseURI().equals(imp.getDefinition().getDocumentBaseURI())) { @@ -389,7 +431,7 @@ public class WSDLModelResolver implements ModelResolver { } } } - } + }*/ } } -- cgit v1.2.3