String name, File[] xsdFiles,
File[] wsdlFiles, File[] configFiles, ResourceLoader cpResourceLoader,
boolean download, boolean noUpa, boolean noPvr, Set mdefNamespaces,
File baseDir, Map sourcesToCopyMap, Collection outerErrorListener)
{
XmlErrorWatcher errorListener = new XmlErrorWatcher(outerErrorListener);
// For parsing XSD and WSDL files, we should use the SchemaDocument
// classloader rather than the thread context classloader. This is
// because in some situations (such as when being invoked by ant
// underneath the ide) the context classloader is potentially weird
// (because of the design of ant).
SchemaTypeLoader loader = XmlBeans.typeLoaderForClassLoader(SchemaDocument.class.getClassLoader());
// step 1, parse all the XSD files.
ArrayList scontentlist = new ArrayList();
if (xsdFiles != null)
{
for (int i = 0; i < xsdFiles.length; i++)
{
try
{
XmlOptions options = new XmlOptions();
options.setLoadLineNumbers();
options.setLoadMessageDigest();
options.setLoadSubstituteNamespaces(MAP_COMPATIBILITY_CONFIG_URIS);
XmlObject schemadoc = loader.parse(xsdFiles[i], null, options);
if (!(schemadoc instanceof SchemaDocument))
{
StscState.addError(errorListener, "Document " + xsdFiles[i] + " is not a schema file", XmlErrorContext.CANNOT_LOAD_XSD_FILE, schemadoc);
}
else
{
StscState.addInfo(errorListener, "Loading schema file " + xsdFiles[i]);
XmlOptions opts = new XmlOptions().setErrorListener(errorListener);
if (schemadoc.validate(opts))
scontentlist.add(((SchemaDocument)schemadoc).getSchema());
}
}
catch (XmlException e)
{
errorListener.add(e.getError());
}
catch (Exception e)
{
StscState.addError(errorListener, "Cannot load file " + xsdFiles[i] + ": " + e, XmlErrorContext.CANNOT_LOAD_XSD_FILE, xsdFiles[i]);
}
}
}
// step 2, parse all WSDL files
if (wsdlFiles != null)
{
for (int i = 0; i < wsdlFiles.length; i++)
{
try
{
XmlOptions options = new XmlOptions();
options.setLoadLineNumbers();
options.setLoadSubstituteNamespaces(Collections.singletonMap(
"http://schemas.xmlsoap.org/wsdl/", "http://www.apache.org/internal/xmlbeans/wsdlsubst"
));
XmlObject wsdldoc = loader.parse(wsdlFiles[i], null, options);
if (!(wsdldoc instanceof org.apache.internal.xmlbeans.wsdlsubst.DefinitionsDocument))
StscState.addError(errorListener, "Document " + wsdlFiles[i] + " is not a wsdl file", XmlErrorContext.CANNOT_LOAD_XSD_FILE, wsdldoc);
else
{
if (wsdlContainsEncoded(wsdldoc))
StscState.addWarning(errorListener, "The WSDL " + wsdlFiles[i] + " uses SOAP encoding. SOAP encoding is not compatible with literal XML Schema.", XmlErrorContext.CANNOT_LOAD_XSD_FILE, wsdldoc);
StscState.addInfo(errorListener, "Loading wsdl file " + wsdlFiles[i]);
XmlObject[] types = ((org.apache.internal.xmlbeans.wsdlsubst.DefinitionsDocument)wsdldoc).getDefinitions().getTypesArray();
int count = 0;
for (int j = 0; j < types.length; j++)
{
XmlObject[] schemas = types[j].selectPath("declare namespace xs=\"http://www.w3.org/2001/XMLSchema\" xs:schema");
if (schemas.length == 0)
{
StscState.addWarning(errorListener, "The WSDL " + wsdlFiles[i] + " did not have any schema documents in namespace 'http://www.w3.org/2001/XMLSchema'", XmlErrorContext.GENERIC_ERROR, wsdldoc);
continue;
}
for (int k = 0; k < schemas.length; k++)
{
if (schemas[k] instanceof SchemaDocument.Schema &&
schemas[k].validate(new XmlOptions().setErrorListener(errorListener)))
{
count++;
scontentlist.add(schemas[k]);
}
}
}
StscState.addInfo(errorListener, "Processing " + count + " schema(s) in " + wsdlFiles[i].toString());
}
}
catch (XmlException e)
{
errorListener.add(e.getError());
}
catch (Exception e)
{
StscState.addError(errorListener, "Cannot load file " + wsdlFiles[i] + ": " + e, XmlErrorContext.CANNOT_LOAD_XSD_FILE, wsdlFiles[i]);
}
}
}
SchemaDocument.Schema[] sdocs = (SchemaDocument.Schema[])scontentlist.toArray(new SchemaDocument.Schema[scontentlist.size()]);
// now the config files.
ArrayList cdoclist = new ArrayList();
if (configFiles != null)
{
for (int i = 0; i < configFiles.length; i++)
{
try
{
XmlOptions options = new XmlOptions();
options.put( XmlOptions.LOAD_LINE_NUMBERS );
options.setLoadSubstituteNamespaces(MAP_COMPATIBILITY_CONFIG_URIS);
XmlObject configdoc = loader.parse(configFiles[i], null, options);
if (!(configdoc instanceof ConfigDocument))
StscState.addError(errorListener, "Document " + configFiles[i] + " is not an xsd config file", XmlErrorContext.CANNOT_LOAD_XSD_FILE, configdoc);
else
{
StscState.addInfo(errorListener, "Loading config file " + configFiles[i]);
if (configdoc.validate(new XmlOptions().setErrorListener(errorListener)))
cdoclist.add(((ConfigDocument)configdoc).getConfig());
}
}
catch (XmlException e)
{
errorListener.add(e.getError());
}
catch (Exception e)
{
StscState.addError(errorListener, "Cannot load xsd config file " + configFiles[i] + ": " + e, XmlErrorContext.CANNOT_LOAD_XSD_CONFIG_FILE, configFiles[i]);
}