return schema;
}
public static Schema createSchema(List<String> locations, String catalogLocation, final Bus bus) {
SchemaFactory factory = SchemaFactory.newInstance(WSDLConstants.NS_SCHEMA_XSD);
Schema s = null;
try {
List<Source> sources = new ArrayList<Source>();
for (String loc : locations) {
URL url = ResourceUtils.getResourceURL(loc, bus);
if (url == null) {
throw new IllegalArgumentException("Cannot find XML schema location: " + loc);
}
Reader r = new BufferedReader(
new InputStreamReader(url.openStream(), "UTF-8"));
StreamSource source = new StreamSource(r);
source.setSystemId(url.toString());
sources.add(source);
}
final OASISCatalogManager catalogResolver = OASISCatalogManager.getCatalogManager(bus);
if (catalogResolver != null) {
catalogLocation = catalogLocation == null
? SchemaHandler.DEFAULT_CATALOG_LOCATION : catalogLocation;
URL catalogURL = ResourceUtils.getResourceURL(catalogLocation, bus);
if (catalogURL != null) {
try {
catalogResolver.loadCatalog(catalogURL);
factory.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId,
String systemId, String baseURI) {
try {
String resolvedLocation = catalogResolver.resolveSystem(systemId);
if (resolvedLocation == null) {
resolvedLocation = catalogResolver.resolveURI(namespaceURI);
}
if (resolvedLocation == null) {
resolvedLocation = catalogResolver.resolvePublic(publicId, systemId);
}
if (resolvedLocation != null) {
InputStream resourceStream =
ResourceUtils.getResourceStream(resolvedLocation, bus);
if (resourceStream != null) {
return new LSInputImpl(publicId, systemId, resourceStream);
}
}
} catch (Exception ex) {
// ignore
}
return null;
}
});
} catch (IOException ex) {
throw new IllegalArgumentException("Catalog " + catalogLocation + " can not be loaded", ex);
}
}
}
s = factory.newSchema(sources.toArray(new Source[sources.size()]));
} catch (Exception ex) {
throw new IllegalArgumentException("Failed to load XML schema : " + ex.getMessage(), ex);
}
return s;