if (serviceInfo == null) {
return null;
}
Schema schema = serviceInfo.getProperty(Schema.class.getName(), Schema.class);
if (schema == null) {
SchemaFactory factory = SchemaFactory.newInstance(
XMLConstants.W3C_XML_SCHEMA_NS_URI);
List<Source> schemaSources = new ArrayList<Source>();
final XmlSchemaCollection sc = serviceInfo.getXmlSchemaCollection();
for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
Source source = new DOMSource(schemaInfo.getElement());
if (source != null) {
source.setSystemId(schemaInfo.getElement().getBaseURI());
schemaSources.add(source);
}
}
try {
factory.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId,
String systemId, String baseURI) {
for (XmlSchema sch : sc.getXmlSchemas()) {
if (namespaceURI.equals(sch.getTargetNamespace())) {
LSInputImpl impl = new LSInputImpl();
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)
}
if (ins == null) {
LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream();
sch.write(out);
ins = out.createInputStream();
}
impl.setByteStream(ins);
return impl;
}
}
return null;
}
});
schema = factory.newSchema(schemaSources.toArray(
new Source[schemaSources.size()]));
if (schema != null) {
serviceInfo.setProperty(Schema.class.getName(), schema);
LOG.log(Level.FINE, "Obtained schema from ServiceInfo");
}