if (b == null) {
b = BusFactory.getThreadDefaultBus(false);
}
Schema schema = serviceInfo.getProperty(Schema.class.getName(), Schema.class);
if (schema == null) {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Map<String, byte[]> schemaSourcesMap = new LinkedHashMap<String, byte[]>();
Map<String, Source> schemaSourcesMap2 = new LinkedHashMap<String, Source>();
XMLStreamWriter writer = null;
try {
for (SchemaInfo si : serviceInfo.getSchemas()) {
Element el = si.getElement();
unsetReadonly(el);
String baseURI = null;
try {
baseURI = el.getBaseURI();
} catch (Exception ex) {
//ignore - not DOM level 3
}
if (baseURI == null) {
baseURI = si.getSystemId();
}
DOMSource ds = new DOMSource(el, baseURI);
schemaSourcesMap2.put(si.getSystemId() + ":" + si.getNamespaceURI(), ds);
LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream();
writer = StaxUtils.createXMLStreamWriter(out);
StaxUtils.copy(el, writer);
writer.flush();
schemaSourcesMap.put(si.getSystemId() + ":" + si.getNamespaceURI(), out.toByteArray());
}
for (XmlSchema sch : serviceInfo.getXmlSchemaCollection().getXmlSchemas()) {
if (sch.getSourceURI() != null
&& !schemaSourcesMap.containsKey(sch.getSourceURI() + ":"
+ sch.getTargetNamespace())) {
InputStream ins = null;
try {
URL url = new URL(sch.getSourceURI());
ins = url.openStream();
} catch (Exception e) {
//ignore, we'll just use what we have. (though
//bugs in XmlSchema could make this less useful)
}
LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream();
if (ins == null) {
sch.write(out);
} else {
IOUtils.copyAndCloseInput(ins, out);
}
schemaSourcesMap.put(sch.getSourceURI() + ":"
+ sch.getTargetNamespace(), out.toByteArray());
Source source = new StreamSource(out.createInputStream(), sch.getSourceURI());
schemaSourcesMap2.put(sch.getSourceURI() + ":"
+ sch.getTargetNamespace(), source);
}
}
factory.setResourceResolver(new SchemaLSResourceResolver(schemaSourcesMap, b));
schema = factory.newSchema(schemaSourcesMap2.values()
.toArray(new Source[schemaSourcesMap2.size()]));
} catch (Exception ex) {
// Something not right with the schema from the wsdl.