WSDLExtensibilityElement extensiblityElt;
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;
// TODO: FIXME
// Map namespaceMap = configuration.getWom().getNamespaces();
// if (namespaceMap != null && !namespaceMap.isEmpty()) {
// Iterator nameSpaces = namespaceMap.keySet().iterator();
// String nsPrefix;
// String nsURI;
// while (nameSpaces.hasNext()) {
// nsPrefix = (String) nameSpaces.next();
// nsURI = namespaceMap.get(nsPrefix).toString();
// parser.addImport(nsURI, null);
// }
// }
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)) {
String s = DOM2Writer.nodeToString(element);
xmlObjectsVector.add(new InputSource(new StringReader(s)));
processedSchemas.add(tagetNamespace);
}
}
}
}
// TODO: FIXME
// Element[] additionalSchemas = loadAdditionalSchemas();
// // Need to add the third party schemas
// for (int i = 0; i < additionalSchemas.length; i++) {
// String s = DOM2Writer.nodeToString(additionalSchemas[i]);
// xmlObjectsVector.add(new InputSource(new StringReader(s)));
// }
File outputDir = new File(configuration.getOutputLocation(), "src");
JAXBSchemaReader reader = new JAXBSchemaReader();
reader.setSupportingExtensions(true);
GeneratorImpl generator = new GeneratorImpl();
generator.setTargetDirectory(outputDir);
generator.setForcingOverwrite(false);
generator.setSchemaReader(reader);
for (int i = 0; i < xmlObjectsVector.size(); i++) {
SchemaSG sg = generator.generate((InputSource) xmlObjectsVector.elementAt(i));
ObjectSG[] elements = sg.getElements();
for(int j=0;j<elements.length;j++){
XsQName qName = elements[j].getName();
JavaQName name = elements[j].getClassContext().getXMLInterfaceName();
mapper.addTypeMappingName(new QName(qName.getNamespaceURI(), qName.getLocalName()),
name.getPackageName() + '.' + name.getClassName());
}
TypeSG[] types = sg.getTypes();
for(int j=0;j<types.length;j++){
XsQName qName = types[j].getName();
JavaQName name = types[j].getRuntimeType();
mapper.addTypeMappingName(new QName(qName.getNamespaceURI(), qName.getLocalName()),
name.getPackageName() + '.' + name.getClassName());
}
GroupSG[] groups = sg.getGroups();
for(int j=0;j<groups.length;j++){
XsQName qName = groups[j].getName();
JavaQName name = groups[j].getClassContext().getXMLInterfaceName();
mapper.addTypeMappingName(new QName(qName.getNamespaceURI(), qName.getLocalName()),
name.getPackageName() + '.' + name.getClassName());
}
}
// TODO: FIXME
// // prune the generated schema type system and add the list of base64 types
// FindBase64Types(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);
}