WSDLExtensibilityElement extensiblityElt;
SchemaTypeSystem sts;
Vector xmlObjectsVector = new Vector();
//create the type mapper
JavaTypeMapper mapper = new JavaTypeMapper();
for (int i = 0; i < typesArray.size(); i++) {
extensiblityElt = (WSDLExtensibilityElement) typesArray.get(i);
Schema schema;
if (ExtensionConstants.SCHEMA.equals(extensiblityElt.getType())) {
schema = (Schema) extensiblityElt;
XmlOptions options = new XmlOptions();
options.setLoadAdditionalNamespaces(
configuration.getWom().getNamespaces()); //add the namespaces
Stack importedSchemaStack = schema.getImportedSchemaStack();
File schemaFolder = null;
if(debug) {
schemaFolder = new File(configuration.getOutputLocation(), SCHEMA_FOLDER);
schemaFolder.mkdir();
}
//compile these schemas
while (!importedSchemaStack.isEmpty()) {
Element element = (Element) importedSchemaStack.pop();
String tagetNamespace = element.getAttribute("targetNamespace");
if (!processedSchemas.contains(tagetNamespace)) {
if(debug) {
// we are not using DOM toString method here, as it seems it depends on the
// JDK version that is being used.
String s = DOM2Writer.nodeToString(element);
//write the schema to a file
File tempFile = File.createTempFile("temp", ".xsd", schemaFolder);
FileWriter writer = new FileWriter(tempFile);
writer.write(s);
writer.flush();
writer.close();
}
xmlObjectsVector.add(
XmlObject.Factory.parse(
element
, options));
processedSchemas.add(tagetNamespace);
}
}
}
}
// add the third party schemas
//todo perhaps checking the namespaces would be a good idea to
//make the generated code work efficiently
for (int i = 0; i < additionalSchemas.length; i++) {
xmlObjectsVector.add(XmlObject.Factory.parse(
additionalSchemas[i]
, null));
}
//compile the type system
XmlObject[] objeArray = convertToXMLObjectArray(xmlObjectsVector);
BindingConfig config = new Axis2BindingConfig();
//set the STS name to null. it makes the generated class include a unique (but random) STS name
sts = XmlBeans.compileXmlBeans(null, null,
objeArray,
config, XmlBeans.getContextTypeLoader(),
new Axis2Filer(),
null);
// prune the generated schema type system and add the list of base64 types
FindBase64Types(sts);
findPlainBase64Types(sts);
//get the schematypes and add the document types to the type mapper
SchemaType[] schemaType = sts.documentTypes();
SchemaType type;
for (int j = 0; j < schemaType.length; j++) {
type = schemaType[j];
mapper.addTypeMappingName(type.getDocumentElementName(),
type.getFullJavaName());
}
//set the type mapper to the config
configuration.setTypeMapper(mapper);
if(debug) {
// write the mapper to a file for later retriival
writeMappingsToFile(mapper.getAllMappedNames());
}
} catch (Exception e) {
throw new RuntimeException(e);
}