private void writeImports(QName elementName, List<MessagePart> parts) { Set<String> uris = new HashSet<String>(); for (MessagePart p : parts) { String ns = p.getDescriptor().getNamespaceURI(); if (!uris.contains(ns) && !ns.equals("http://www.w3.org/2001/XMLSchema") && !ns.equals(elementName.getNamespaceURI())) { print("<xs:import namespace=''{0}''/>", ns); uris.add(ns); } } }
private void build(QName elementName, List<MessagePart> allParts) { print( "<xs:schema xmlns:xs=''http://www.w3.org/2001/XMLSchema''" + " xmlns:jaxb=''http://java.sun.com/xml/ns/jaxb''" + " xmlns:xjc=''http://java.sun.com/xml/ns/jaxb/xjc''" + " jaxb:extensionBindingPrefixes=''xjc''" + " jaxb:version=''1.0''" + " targetNamespace=''{0}''>", elementName.getNamespaceURI()); writeImports(elementName, allParts); if (!asyncRespBeanBinding) { print( "<xs:annotation><xs:appinfo>" + " <jaxb:schemaBindings>" + " <jaxb:package name=''{0}'' />" + " </jaxb:schemaBindings>" + "</xs:appinfo></xs:annotation>", wsdlModeler.getJavaPackage()); asyncRespBeanBinding = true; } print("<xs:element name=''{0}''>", elementName.getLocalPart()); print("<xs:complexType>"); print("<xs:sequence>"); for (MessagePart p : allParts) { // rpclit wsdl:part must reference schema type not element, also it must exclude headers and // mime parts if (p.getDescriptorKind() == SchemaKinds.XSD_ELEMENT) { print( "<xs:element ref=''types:{0}'' xmlns:types=''{1}''/>", p.getDescriptor().getLocalPart(), p.getDescriptor().getNamespaceURI()); } else { print( "<xs:element name=''{0}'' type=''{1}'' xmlns=''{2}'' />", p.getName(), p.getDescriptor().getLocalPart(), p.getDescriptor().getNamespaceURI()); } } print("</xs:sequence>"); print("</xs:complexType>"); print("</xs:element>"); print("</xs:schema>"); // reset the StringWriter, so that next operation element could be written if (buf.toString().length() > 0) { // System.out.println("Response bean Schema for operation========> "+ elementName+"\n\n"+buf); InputSource is = new InputSource(new StringReader(buf.toString())); schemas.add(is); buf.getBuffer().setLength(0); } }