1 17 package org.apache.geronimo.axis.builder; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.net.URI ; 22 import java.net.URISyntaxException ; 23 import java.net.URL ; 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.Stack ; 31 import java.util.jar.JarFile ; 32 import java.util.zip.ZipEntry ; 33 import javax.wsdl.Definition; 34 import javax.wsdl.Import; 35 import javax.wsdl.Port; 36 import javax.wsdl.Service; 37 import javax.wsdl.Types; 38 import javax.wsdl.WSDLException; 39 import javax.wsdl.extensions.ExtensibilityElement; 40 import javax.wsdl.extensions.UnknownExtensibilityElement; 41 import javax.wsdl.extensions.ExtensionRegistry; 42 import javax.wsdl.extensions.schema.Schema; 43 import javax.wsdl.extensions.soap.SOAPAddress; 44 import javax.wsdl.factory.WSDLFactory; 45 import javax.wsdl.xml.WSDLLocator; 46 import javax.wsdl.xml.WSDLReader; 47 import javax.xml.namespace.QName ; 48 49 import org.apache.commons.logging.Log; 50 import org.apache.commons.logging.LogFactory; 51 import org.apache.geronimo.common.DeploymentException; 52 import org.apache.geronimo.schema.SchemaConversionUtils; 53 import org.apache.xmlbeans.SchemaField; 54 import org.apache.xmlbeans.SchemaGlobalElement; 55 import org.apache.xmlbeans.SchemaParticle; 56 import org.apache.xmlbeans.SchemaType; 57 import org.apache.xmlbeans.SchemaTypeSystem; 58 import org.apache.xmlbeans.XmlBeans; 59 import org.apache.xmlbeans.XmlCursor; 60 import org.apache.xmlbeans.XmlError; 61 import org.apache.xmlbeans.XmlException; 62 import org.apache.xmlbeans.XmlObject; 63 import org.apache.xmlbeans.XmlOptions; 64 import org.w3.x2001.xmlSchema.SchemaDocument; 65 import org.w3c.dom.Element ; 66 import org.xml.sax.EntityResolver ; 67 import org.xml.sax.InputSource ; 68 import org.xml.sax.SAXException ; 69 import com.ibm.wsdl.extensions.PopulatedExtensionRegistry; 70 import com.ibm.wsdl.extensions.schema.SchemaConstants; 71 72 75 public class SchemaInfoBuilder { 76 private static final Log log = LogFactory.getLog(SchemaInfoBuilder.class); 77 private static final SchemaTypeSystem basicTypeSystem; 78 private static final String [] errorNames = {"Error", "Warning", "Info"}; 79 80 static { 81 URL url = WSDescriptorParser.class.getClassLoader().getResource("soap_encoding_1_1.xsd"); 82 if (url == null) { 83 throw new RuntimeException ("Could not locate soap encoding schema"); 84 } 85 Collection errors = new ArrayList (); 86 XmlOptions xmlOptions = new XmlOptions(); 87 xmlOptions.setErrorListener(errors); 88 try { 89 XmlObject xmlObject = SchemaConversionUtils.parse(url); 90 basicTypeSystem = XmlBeans.compileXsd(new XmlObject[]{xmlObject}, XmlBeans.getBuiltinTypeSystem(), xmlOptions); 91 if (errors.size() > 0) { 92 throw new RuntimeException ("Could not compile schema type system: errors: " + errors); 93 } 94 } catch (XmlException e) { 95 throw new RuntimeException ("Could not compile schema type system", e); 96 } catch (IOException e) { 97 throw new RuntimeException ("Could not compile schema type system", e); 98 } 99 } 100 101 private final JarFile moduleFile; 102 private final Definition definition; 103 private final Stack uris = new Stack (); 104 private final Map wsdlMap = new HashMap (); 105 private final Map schemaTypeKeyToSchemaTypeMap; 106 private final Map complexTypeMap; 107 private final Map elementMap; 108 private final Map simpleTypeMap; 109 private final Map portMap; 110 111 112 public SchemaInfoBuilder(JarFile moduleFile, URI wsdlUri) throws DeploymentException { 113 this(moduleFile, wsdlUri, null, null); 114 } 115 116 public SchemaInfoBuilder(JarFile moduleFile, Definition definition) throws DeploymentException { 117 this(moduleFile, null, definition, null); 118 } 119 120 SchemaInfoBuilder(JarFile moduleFile, URI uri, SchemaTypeSystem schemaTypeSystem) throws DeploymentException { 121 this(moduleFile, uri, null, schemaTypeSystem); 122 } 123 124 SchemaInfoBuilder(JarFile moduleFile, URI uri, Definition definition, SchemaTypeSystem schemaTypeSystem) throws DeploymentException { 125 this.moduleFile = moduleFile; 126 if (uri != null) { 127 uris.push(uri); 128 if (definition == null && schemaTypeSystem == null) { 129 definition = readWsdl(moduleFile, uri); 130 } 131 } else if (definition != null) { 132 try { 133 uri = new URI (definition.getDocumentBaseURI()); 134 uris.push(uri); 135 } catch (URISyntaxException e) { 136 throw new DeploymentException("Could not locate definition", e); 137 } 138 } else { 139 throw new DeploymentException("You must supply uri or definition"); 140 } 141 if (schemaTypeSystem == null) { 142 schemaTypeSystem = compileSchemaTypeSystem(definition); 143 } 144 this.definition = definition; 145 schemaTypeKeyToSchemaTypeMap = buildSchemaTypeKeyToSchemaTypeMap(schemaTypeSystem); 146 complexTypeMap = buildComplexTypeMap(); 147 simpleTypeMap = buildSimpleTypeMap(); 148 elementMap = buildElementMap(); 149 portMap = buildPortMap(); 150 } 151 152 public Map getSchemaTypeKeyToSchemaTypeMap() { 153 return schemaTypeKeyToSchemaTypeMap; 154 } 155 156 public Definition getDefinition() { 157 return definition; 158 } 159 160 public Map getWsdlMap() { 161 return wsdlMap; 162 } 163 164 170 public Map getComplexTypesInWsdl() { 171 return complexTypeMap; 172 } 173 174 private Map buildComplexTypeMap() { 175 Map complexTypeMap = new HashMap (); 176 for (Iterator iterator = schemaTypeKeyToSchemaTypeMap.entrySet().iterator(); iterator.hasNext();) { 177 Map.Entry entry = (Map.Entry ) iterator.next(); 178 SchemaTypeKey key = (SchemaTypeKey) entry.getKey(); 179 if (!key.isSimpleType() && !key.isAnonymous()) { 180 QName qName = key.getqName(); 181 SchemaType schemaType = (SchemaType) entry.getValue(); 182 complexTypeMap.put(qName, schemaType); 183 } 184 } 185 return complexTypeMap; 186 } 187 188 public Map getElementToTypeMap() { 189 return elementMap; 190 } 191 192 private Map buildElementMap() { 193 Map elementToTypeMap = new HashMap (); 194 for (Iterator iterator = schemaTypeKeyToSchemaTypeMap.entrySet().iterator(); iterator.hasNext();) { 195 Map.Entry entry = (Map.Entry ) iterator.next(); 196 SchemaTypeKey key = (SchemaTypeKey) entry.getKey(); 197 if (key.isElement()) { 198 QName elementQName = key.getqName(); 199 SchemaType schemaType = (SchemaType) entry.getValue(); 200 QName typeQName = schemaType.getName(); 201 elementToTypeMap.put(elementQName, typeQName); 202 } 203 } 204 return elementToTypeMap; 205 } 206 207 214 215 public Map getPortMap() { 216 return portMap; 217 } 218 219 private Map buildPortMap() { 220 HashMap ports = new HashMap (); 221 if (definition != null) { 222 Collection services = definition.getServices().values(); 223 for (Iterator iterator = services.iterator(); iterator.hasNext();) { 224 Service service = (Service) iterator.next(); 225 ports.putAll(service.getPorts()); 226 } 227 } 228 return ports; 229 } 230 231 public Map getSimpleTypeMap() { 232 return simpleTypeMap; 233 } 234 235 private Map buildSimpleTypeMap() { 236 Map simpleTypeMap = new HashMap (); 237 for (Iterator iterator = schemaTypeKeyToSchemaTypeMap.entrySet().iterator(); iterator.hasNext();) { 238 Map.Entry entry = (Map.Entry ) iterator.next(); 239 SchemaTypeKey key = (SchemaTypeKey) entry.getKey(); 240 if (key.isSimpleType() && !key.isAnonymous()) { 241 QName qName = key.getqName(); 242 SchemaType schemaType = (SchemaType) entry.getValue(); 243 simpleTypeMap.put(qName, schemaType); 244 } 245 } 246 return simpleTypeMap; 247 } 248 249 public SchemaTypeSystem compileSchemaTypeSystem(Definition definition) throws DeploymentException { 250 List schemaList = new ArrayList (); 251 addImportsFromDefinition(definition, schemaList); 252 Collection errors = new ArrayList (); 254 XmlOptions xmlOptions = new XmlOptions(); 255 xmlOptions.setErrorListener(errors); 256 xmlOptions.setEntityResolver(new JarEntityResolver()); 257 XmlObject[] schemas = (XmlObject[]) schemaList.toArray(new XmlObject[schemaList.size()]); 258 try { 259 SchemaTypeSystem schemaTypeSystem = XmlBeans.compileXsd(schemas, basicTypeSystem, xmlOptions); 260 if (errors.size() > 0) { 261 boolean wasError = false; 262 for (Iterator iterator = errors.iterator(); iterator.hasNext();) { 263 XmlError xmlError = (XmlError) iterator.next(); 264 log.info("Severity: " + errorNames[xmlError.getSeverity()] + ", message: " + xmlError); 265 if (xmlError.getSeverity() == XmlError.SEVERITY_ERROR) { 266 wasError = true; 267 } 268 } 269 if (wasError) { 270 throw new DeploymentException("Could not compile schema type system, see log for errors"); 271 } 272 } 273 return schemaTypeSystem; 274 } catch (XmlException e) { 275 throw new DeploymentException("Could not compile schema type system", e); 276 } 277 } 278 279 private void addImportsFromDefinition(Definition definition, List schemaList) throws DeploymentException { 280 Map namespaceMap = definition.getNamespaces(); 281 Types types = definition.getTypes(); 282 if (types != null) { 283 List schemas = types.getExtensibilityElements(); 284 for (Iterator iterator = schemas.iterator(); iterator.hasNext();) { 285 Object o = iterator.next(); 286 if (o instanceof Schema) { 287 Schema unknownExtensibilityElement = (Schema) o; 288 QName elementType = unknownExtensibilityElement.getElementType(); 289 if (new QName ("http://www.w3.org/2001/XMLSchema", "schema").equals(elementType)) { 290 Element element = unknownExtensibilityElement.getElement(); 291 addSchemaElement(element, namespaceMap, schemaList); 292 } 293 } else if (o instanceof UnknownExtensibilityElement) { 294 UnknownExtensibilityElement unknownExtensibilityElement = (UnknownExtensibilityElement) o; 297 Element element = unknownExtensibilityElement.getElement(); 298 String elementNamespace = element.getNamespaceURI(); 299 String elementLocalName = element.getNodeName(); 300 if ("http://www.w3.org/2001/XMLSchema".equals(elementNamespace) && "schema".equals(elementLocalName)) { 301 addSchemaElement(element, namespaceMap, schemaList); 302 } 303 } 304 } 305 } 306 Map imports = definition.getImports(); 307 if (imports != null) { 308 for (Iterator iterator = imports.entrySet().iterator(); iterator.hasNext();) { 309 Map.Entry entry = (Map.Entry ) iterator.next(); 310 String namespaceURI = (String ) entry.getKey(); 311 List importList = (List ) entry.getValue(); 312 for (Iterator iterator1 = importList.iterator(); iterator1.hasNext();) { 313 Import anImport = (Import) iterator1.next(); 314 Definition definition1 = anImport.getDefinition(); 317 if (definition1 != null) { 318 try { 319 URI uri = new URI (definition1.getDocumentBaseURI()); 320 uris.push(uri); 321 } catch (URISyntaxException e) { 322 throw new DeploymentException("Could not locate definition", e); 323 } 324 try { 325 addImportsFromDefinition(definition1, schemaList); 326 } finally { 327 uris.pop(); 328 } 329 } else { 330 log.warn("Missing definition in import for namespace " + namespaceURI); 331 } 332 } 333 } 334 } 335 } 336 337 private void addSchemaElement(Element element, Map namespaceMap, List schemaList) throws DeploymentException { 338 try { 339 XmlObject xmlObject = parseWithNamespaces(element, namespaceMap); 340 schemaList.add(xmlObject); 341 } catch (XmlException e) { 342 throw new DeploymentException("Could not parse schema element", e); 343 } 344 } 345 346 static XmlObject parseWithNamespaces(Element element, Map namespaceMap) throws XmlException { 347 XmlObject xmlObject = SchemaConversionUtils.parse(element); 348 XmlCursor cursor = xmlObject.newCursor(); 349 try { 350 cursor.toFirstContentToken(); 351 for (Iterator namespaces = namespaceMap.entrySet().iterator(); namespaces.hasNext();) { 352 Map.Entry entry = (Map.Entry ) namespaces.next(); 353 cursor.insertNamespace((String ) entry.getKey(), (String ) entry.getValue()); 354 } 355 } finally { 356 cursor.dispose(); 357 } 358 return xmlObject; 359 } 360 361 367 private Map buildSchemaTypeKeyToSchemaTypeMap(SchemaTypeSystem schemaTypeSystem) { 368 Map qnameMap = new HashMap (); 369 SchemaType[] globalTypes = schemaTypeSystem.globalTypes(); 370 for (int i = 0; i < globalTypes.length; i++) { 371 SchemaType globalType = globalTypes[i]; 372 QName typeQName = globalType.getName(); 373 addSchemaType(typeQName, globalType, false, qnameMap); 374 } 375 SchemaGlobalElement[] globalElements = schemaTypeSystem.globalElements(); 376 for (int i = 0; i < globalElements.length; i++) { 377 SchemaGlobalElement globalElement = globalElements[i]; 378 addElement(globalElement, null, qnameMap); 379 } 380 return qnameMap; 381 } 382 383 private void addElement(SchemaField element, SchemaTypeKey key, Map qnameMap) { 384 QName elementName = element.getName(); 386 String elementNamespace = elementName.getNamespaceURI(); 387 if (elementNamespace == null || elementNamespace.equals("")) { 389 elementNamespace = key.getqName().getNamespaceURI(); 390 } 391 String elementQNameLocalName; 392 SchemaTypeKey elementKey = null; 393 if (key == null) { 394 elementQNameLocalName = elementName.getLocalPart(); 396 elementKey = new SchemaTypeKey(elementName, true, false, false, elementName); 397 } else { 398 QName enclosingTypeQName = key.getqName(); 400 String enclosingTypeLocalName = enclosingTypeQName.getLocalPart(); 401 elementQNameLocalName = enclosingTypeLocalName + ">" + elementName.getLocalPart(); 402 QName subElementName = new QName (elementNamespace, elementQNameLocalName); 403 elementKey = new SchemaTypeKey(subElementName, true, false, true, elementName); 404 } 405 SchemaType schemaType = element.getType(); 406 qnameMap.put(elementKey, schemaType); 407 if (element instanceof SchemaParticle) { 411 addArrayForms((SchemaParticle) element, elementKey.getqName(), qnameMap, schemaType); 412 } else { 413 log.warn("element is not a schemaParticle! " + element); 414 } 415 String typeQNameLocalPart = ">" + elementQNameLocalName; 417 QName typeQName = new QName (elementNamespace, typeQNameLocalPart); 418 boolean isAnonymous = true; 419 addSchemaType(typeQName, schemaType, isAnonymous, qnameMap); 420 } 421 422 private void addSchemaType(QName typeQName, SchemaType schemaType, boolean anonymous, Map qnameMap) { 423 SchemaTypeKey typeKey = new SchemaTypeKey(typeQName, false, schemaType.isSimpleType(), anonymous, null); 424 qnameMap.put(typeKey, schemaType); 425 SchemaParticle schemaParticle = schemaType.getContentModel(); 428 if (schemaParticle != null) { 429 addSchemaParticle(schemaParticle, typeKey, qnameMap); 430 } 431 } 432 433 434 private void addSchemaParticle(SchemaParticle schemaParticle, SchemaTypeKey key, Map qnameMap) { 435 if (schemaParticle.getParticleType() == SchemaParticle.ELEMENT) { 436 SchemaType elementType = schemaParticle.getType(); 437 SchemaField element = elementType.getContainerField(); 438 if (element != null) { 440 addElement(element, key, qnameMap); 441 } else { 442 QName keyQName = key.getqName(); 443 String localPart = schemaParticle.getName().getLocalPart(); 446 QName elementName = new QName (keyQName.getNamespaceURI(), localPart); 447 addArrayForms(schemaParticle, elementName, qnameMap, elementType); 448 localPart = keyQName.getLocalPart() + ">" + schemaParticle.getName().getLocalPart(); 450 elementName = new QName (keyQName.getNamespaceURI(), localPart); 451 addArrayForms(schemaParticle, elementName, qnameMap, elementType); 452 } 453 } else { 454 try { 455 SchemaParticle[] children = schemaParticle.getParticleChildren(); 456 for (int i = 0; i < children.length; i++) { 457 SchemaParticle child = children[i]; 458 addSchemaParticle(child, key, qnameMap); 459 } 460 } catch (NullPointerException e) { 461 } 463 } 464 } 465 466 private void addArrayForms(SchemaParticle schemaParticle, QName keyName, Map qnameMap, SchemaType elementType) { 467 if (schemaParticle.getIntMaxOccurs() > 1) { 469 String maxOccurs = schemaParticle.getMaxOccurs() == null ? "unbounded" : "" + schemaParticle.getIntMaxOccurs(); 470 int minOccurs = schemaParticle.getIntMinOccurs(); 471 QName elementName = schemaParticle.getName(); 472 String arrayQNameLocalName = keyName.getLocalPart() + "[" + minOccurs + "," + maxOccurs + "]"; 473 String elementNamespace = elementName.getNamespaceURI(); 474 if (elementNamespace == null || elementNamespace.equals("")) { 475 elementNamespace = keyName.getNamespaceURI(); 476 } 477 QName arrayName = new QName (elementNamespace, arrayQNameLocalName); 478 SchemaTypeKey arrayKey = new SchemaTypeKey(arrayName, false, false, true, elementName); 479 qnameMap.put(arrayKey, elementType); 481 if (minOccurs == 1) { 483 arrayQNameLocalName = keyName.getLocalPart() + "[," + maxOccurs + "]"; 484 arrayName = new QName (elementNamespace, arrayQNameLocalName); 485 arrayKey = new SchemaTypeKey(arrayName, false, false, true, elementName); 486 qnameMap.put(arrayKey, elementType); 488 } 489 } 490 } 491 492 493 public Definition readWsdl(JarFile moduleFile, URI wsdlURI) throws DeploymentException { 494 Definition definition; 495 WSDLFactory wsdlFactory = null; 496 try { 497 wsdlFactory = WSDLFactory.newInstance(); 498 } catch (WSDLException e) { 499 throw new DeploymentException("Could not create WSDLFactory", e); 500 } 501 WSDLReader wsdlReaderNoImport = wsdlFactory.newWSDLReader(); 502 wsdlReaderNoImport.setFeature("javax.wsdl.importDocuments", false); 503 ExtensionRegistry extensionRegistry = new PopulatedExtensionRegistry(); 504 extensionRegistry.mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_1999, 505 UnknownExtensibilityElement.class); 506 extensionRegistry.registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999, 507 extensionRegistry.getDefaultDeserializer()); 508 extensionRegistry.registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_1999, 509 extensionRegistry.getDefaultSerializer()); 510 511 extensionRegistry.mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2000, 512 UnknownExtensibilityElement.class); 513 extensionRegistry.registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000, 514 extensionRegistry.getDefaultDeserializer()); 515 extensionRegistry.registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2000, 516 extensionRegistry.getDefaultSerializer()); 517 518 extensionRegistry.mapExtensionTypes(Types.class, SchemaConstants.Q_ELEM_XSD_2001, 519 UnknownExtensibilityElement.class); 520 extensionRegistry.registerDeserializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001, 521 extensionRegistry.getDefaultDeserializer()); 522 extensionRegistry.registerSerializer(Types.class, SchemaConstants.Q_ELEM_XSD_2001, 523 extensionRegistry.getDefaultSerializer()); 524 wsdlReaderNoImport.setExtensionRegistry(extensionRegistry); 525 JarWSDLLocator wsdlLocator = new JarWSDLLocator(wsdlURI, wsdlReaderNoImport); 526 WSDLReader wsdlReader = wsdlFactory.newWSDLReader(); 527 try { 528 definition = wsdlReader.readWSDL(wsdlLocator); 529 } catch (WSDLException e) { 530 throw new DeploymentException("Failed to read wsdl document", e); 531 } 532 return definition; 533 } 534 535 public static ExtensibilityElement getExtensibilityElement(Class clazz, List extensibilityElements) throws DeploymentException { 536 for (Iterator iterator = extensibilityElements.iterator(); iterator.hasNext();) { 537 ExtensibilityElement extensibilityElement = (ExtensibilityElement) iterator.next(); 538 if (clazz.isAssignableFrom(extensibilityElement.getClass())) { 539 return extensibilityElement; 540 } 541 } 542 throw new DeploymentException("No element of class " + clazz.getName() + " found"); 543 } 544 545 public static void updatePortLocations(Service service, Map portLocations) throws DeploymentException { 546 for (Iterator iterator = portLocations.entrySet().iterator(); iterator.hasNext();) { 547 Map.Entry entry = (Map.Entry ) iterator.next(); 548 String portName = (String ) entry.getKey(); 549 String location = (String ) entry.getValue(); 550 Port port = service.getPort(portName); 551 if (port == null) { 552 throw new DeploymentException("No port named " + portName + " found in service " + service.getQName()); 553 } 554 SOAPAddress soapAddress = (SOAPAddress) getExtensibilityElement(SOAPAddress.class, port.getExtensibilityElements()); 555 soapAddress.setLocationURI(location); 556 } 557 } 558 559 private class JarEntityResolver implements EntityResolver { 560 561 private final static String PROJECT_URL_PREFIX = "project://local/"; 562 public InputSource resolveEntity(String publicId, String systemId) throws SAXException , IOException { 563 if (systemId.indexOf(PROJECT_URL_PREFIX) > -1) { 565 systemId = systemId.substring(PROJECT_URL_PREFIX.length()); 566 } 567 URI location = ((URI ) uris.peek()).resolve(systemId); 568 InputStream wsdlInputStream = null; 569 try { 570 ZipEntry entry = moduleFile.getEntry(location.toString()); 571 wsdlInputStream = moduleFile.getInputStream(entry); 572 XmlObject xmlObject = SchemaDocument.Factory.parse(wsdlInputStream); 573 wsdlMap.put(location, xmlObject); 574 wsdlInputStream.close(); 575 wsdlInputStream = moduleFile.getInputStream(entry); 576 } catch (XmlException e) { 577 throw (IOException )new IOException ("Could not parse schema document").initCause(e); 578 } 579 return new InputSource (wsdlInputStream); 580 } 581 } 582 583 class JarWSDLLocator implements WSDLLocator { 584 585 private final URI wsdlURI; 586 private final WSDLReader wsdlReader; 587 private URI latestImportURI; 588 589 public JarWSDLLocator(URI wsdlURI, WSDLReader wsdlReader) { 590 this.wsdlURI = wsdlURI; 591 this.wsdlReader = wsdlReader; 592 } 593 594 public InputSource getBaseInputSource() { 595 InputStream wsdlInputStream = null; 596 try { 597 ZipEntry entry = moduleFile.getEntry(wsdlURI.toString()); 598 wsdlInputStream = moduleFile.getInputStream(entry); 599 Definition definition = wsdlReader.readWSDL(wsdlURI.toString(), new InputSource (wsdlInputStream)); 600 wsdlMap.put(wsdlURI, definition); 601 wsdlInputStream.close(); 602 wsdlInputStream = moduleFile.getInputStream(entry); 603 } catch (Exception e) { 604 throw new RuntimeException ("Could not open stream to wsdl file", e); 605 } 606 return new InputSource (wsdlInputStream); 607 } 608 609 public String getBaseURI() { 610 return wsdlURI.toString(); 611 } 612 613 public InputSource getImportInputSource(String parentLocation, String relativeLocation) { 614 URI parentURI = URI.create(parentLocation); 615 latestImportURI = parentURI.resolve(relativeLocation); 616 InputStream importInputStream = null; 617 try { 618 ZipEntry entry = moduleFile.getEntry(latestImportURI.toString()); 619 importInputStream = moduleFile.getInputStream(entry); 620 try { 621 Definition definition = wsdlReader.readWSDL(wsdlURI.toString(), new InputSource (importInputStream)); 622 wsdlMap.put(latestImportURI, definition); 623 importInputStream.close(); 624 } catch (WSDLException e) { 625 } 627 importInputStream = moduleFile.getInputStream(entry); 628 } catch (Exception e) { 629 throw new RuntimeException ("Could not open stream to import file", e); 630 } 631 InputSource inputSource = new InputSource (importInputStream); 632 inputSource.setSystemId(getLatestImportURI()); 633 return inputSource; 634 } 635 636 public String getLatestImportURI() { 637 return latestImportURI.toString(); 638 } 639 } 640 } 641 | Popular Tags |