File baseDir,
File schemasDir,
EntityResolver entResolver) {
SchemaTypeLoader loader = XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader());
// parse all the XSD files.
List<SchemaDocument.Schema> scontentlist = new ArrayList<SchemaDocument.Schema>();
try {
URL url = new URL(wsdlFile);
XmlOptions options = new XmlOptions();
options.setLoadLineNumbers();
options.setLoadSubstituteNamespaces(Collections
.singletonMap("http://schemas.xmlsoap.org/wsdl/",
"http://www.apache.org/internal/xmlbeans/wsdlsubst"));
options.setEntityResolver(entResolver);
options.setGenerateJavaVersion(XmlOptions.GENERATE_JAVA_15);
XmlObject urldoc = loader.parse(url, null, options);
if (urldoc instanceof org.apache.xmlbeans.impl.xb.substwsdl.DefinitionsDocument) {
org.apache.xmlbeans.impl.xb.substwsdl.DefinitionsDocument wsdldoc =
(org.apache.xmlbeans.impl.xb.substwsdl.DefinitionsDocument)urldoc;
addWsdlSchemas(url.toString(),
wsdldoc,
errorListener, scontentlist);
for (TImport imp : wsdldoc.getDefinitions().getImportArray()) {
if (imp.getLocation().toLowerCase().endsWith(".xsd")) {
URL url1 = new URL(url, imp.getLocation());
XmlObject urldoc2 = loader.parse(url1, null, options);
addSchema(url1.toString(), (SchemaDocument)urldoc2, errorListener, false,
scontentlist);
}
}
} else if (urldoc instanceof SchemaDocument) {
addSchema(url.toString(), (SchemaDocument)urldoc, errorListener, false,
scontentlist);
} else {
StscState.addError(errorListener, XmlErrorCodes.INVALID_DOCUMENT_TYPE, new Object[] {
url, "wsdl or schema"
}, urldoc);
}
} catch (XmlException e) {
errorListener.add(e.getError());
} catch (Exception e) {
StscState.addError(errorListener, XmlErrorCodes.CANNOT_LOAD_FILE, new Object[] {
"url", wsdlFile, e.getMessage()
}, (URL)null);
}
SchemaDocument.Schema[] sdocs = (SchemaDocument.Schema[])scontentlist
.toArray(new SchemaDocument.Schema[scontentlist.size()]);
// now the config files.
List<ConfigDocument.Config> cdoclist = new ArrayList<ConfigDocument.Config>();
List<File> javaFiles = new ArrayList<File>();
if (configFiles != null) {
for (int i = 0; i < configFiles.length; i++) {
if (configFiles[i].endsWith(".java")) {
javaFiles.add(new File(configFiles[i]));
continue;
}
if (!configFiles[i].endsWith(".xsdconfig")) {
//jaxws/jaxb customization file or something else
continue;
}
try {
XmlOptions options = new XmlOptions();
options.put(XmlOptions.LOAD_LINE_NUMBERS);
options.setEntityResolver(entResolver);
options.setLoadSubstituteNamespaces(MAP_COMPATIBILITY_CONFIG_URIS);
URI uri = new URI(configFiles[i]);
XmlObject configdoc = null;
if ("file".equals(uri.getRawSchemeSpecificPart())) {
configdoc = loader.parse(new File(uri), null, options);
} else {
InputSource source = new InputSource(configFiles[i]);
Document doc = XMLUtils.parse(source);
configdoc = loader.parse(doc, null, options);
}
if (!(configdoc instanceof ConfigDocument)) {
StscState.addError(errorListener, XmlErrorCodes.INVALID_DOCUMENT_TYPE, new Object[] {
configFiles[i], "xsd config"
}, configdoc);
} else {
StscState.addInfo(errorListener, "Loading config file " + configFiles[i]);
if (configdoc.validate(new XmlOptions().setErrorListener(errorListener))) {
ConfigDocument.Config config = ((ConfigDocument)configdoc).getConfig();
cdoclist.add(config);
config.setExtensionArray(new Extensionconfig[] {});
}
}
} catch (XmlException e) {
errorListener.add(e.getError());
} catch (Exception e) {
StscState.addError(errorListener, XmlErrorCodes.CANNOT_LOAD_FILE, new Object[] {
"xsd config", configFiles[i], e.getMessage()
}, new File(configFiles[i]));
}
}
}
ConfigDocument.Config[] cdocs = (ConfigDocument.Config[])cdoclist
.toArray(new ConfigDocument.Config[cdoclist.size()]);
SchemaTypeLoader linkTo = SchemaTypeLoaderImpl.build(null, cpResourceLoader, null);
URI baseURI = null;
if (baseDir != null) {
baseURI = baseDir.toURI();
}