{
// Initialize the SDO runtime
DataObjectUtil.initRuntime();
EPackage.Registry packageRegistry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);
ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(packageRegistry);
HelperContext context = new HelperContextImpl(extendedMetaData, false);
XSDHelper xsdHelper = context.getXSDHelper();
try {
// Load the WSDL file
File inputFile = new File(wsdlFileName).getAbsoluteFile();
InputStream inputStream = new FileInputStream(inputFile);
// Define SDO metadata
xsdHelper.define(inputStream, inputFile.toURI().toString());
if (targetDirectory == null) {
targetDirectory = new File(wsdlFileName).getCanonicalFile().getParent();
} else {
targetDirectory = new File(targetDirectory).getCanonicalPath();
}
// Populate the typeMapping table that will be given to the Axis2 WSDL2Java
Map<QName, SDODataBindingTypeMappingEntry> typeMapping =
new HashMap<QName, SDODataBindingTypeMappingEntry>();
if (!packageRegistry.values().isEmpty()) {
ResourceSet resourceSet = DataObjectUtil.createResourceSet();
// Populate list of GenPackages and a map of GenClasses keyed by EClass
List<GenPackage> genPackages = new ArrayList<GenPackage>();
Map<EClass, GenClass> genClasses = new HashMap<EClass, GenClass>();
for (Iterator iter = packageRegistry.values().iterator(); iter.hasNext();) {
EPackage currentEPackage = (EPackage)iter.next();
String currentBasePackage = extractBasePackageName(currentEPackage, xsdJavaPackage);
String currentPrefix = CodeGenUtil.capName(currentEPackage.getName());
GenPackage currentGenPackage = createGenPackage(currentEPackage, currentBasePackage,
currentPrefix, genOptions, resourceSet);
genPackages.add(currentGenPackage);
for (GenClass genClass : (List<GenClass>)currentGenPackage.getGenClasses()) {
genClasses.put(genClass.getEcoreClass(), genClass);
}
}
// Process all the SDO packages
// Populate the QName -> interfaceName typeMapping table
for (GenPackage currentGenPackage : genPackages) {
EPackage currentEPackage = currentGenPackage.getEcorePackage();
// Populate the type mappings for all the complex types
for (GenClass genClass : (List<GenClass>)currentGenPackage.getGenClasses()) {
QName qname = new QName(extendedMetaData.getNamespace(currentEPackage),
extendedMetaData.getName(genClass.getEcoreClass()));
String interfaceName = (DYNAMIC_SDO & genOptions) == DYNAMIC_SDO ? "commonj.sdo.DataObject" : currentGenPackage
.getInterfacePackageName()
+ '.' + genClass.getInterfaceName();
SDODataBindingTypeMappingEntry typeMappingEntry =
new SDODataBindingTypeMappingEntry(interfaceName, false, null);
typeMapping.put(qname, typeMappingEntry);
}
// Process all the global XSD elements
EClass documentRoot = extendedMetaData.getDocumentRoot(currentEPackage);
if (documentRoot != null) {
for (EStructuralFeature element : (List<EStructuralFeature>)extendedMetaData
.getElements(documentRoot)) {
EClassifier elementType = element.getEType();
// Handle a complex type
if (elementType instanceof EClass) {
EClass eClass = (EClass)elementType;
GenClass genClass = genClasses.get(elementType);
QName qname = new QName(extendedMetaData.getNamespace(currentEPackage),
extendedMetaData.getName(element));
String interfaceName = (DYNAMIC_SDO & genOptions) == DYNAMIC_SDO ? "commonj.sdo.DataObject" : genClass
.getGenPackage().getInterfacePackageName()
+ '.' + genClass.getInterfaceName();
boolean anonymous = extendedMetaData.isAnonymous(eClass);
// Build list of property class names
List<String> propertyClassNames=new ArrayList<String>();
for (EStructuralFeature feature : (List<EStructuralFeature>)eClass.getEStructuralFeatures()) {
EClassifier propertyType = feature.getEType();
if (propertyType instanceof EClass) {
GenClass propertyGenClass = genClasses.get(propertyType);
String propertyClassName = (DYNAMIC_SDO & genOptions) == DYNAMIC_SDO ? "commonj.sdo.DataObject"
: propertyGenClass.getGenPackage().getInterfacePackageName() + '.'
+ '.' + propertyGenClass.getInterfaceName();
propertyClassNames.add(propertyClassName);
} else if (propertyType instanceof EClassifier) {
String propertyClassName = propertyType.getInstanceClass().getName();
propertyClassNames.add(propertyClassName);
}
}
SDODataBindingTypeMappingEntry typeMappingEntry =
new SDODataBindingTypeMappingEntry(interfaceName, anonymous, propertyClassNames);
typeMapping.put(qname, typeMappingEntry);
} else {
// Handle a simple type
QName qname = new QName(extendedMetaData.getNamespace(currentEPackage),
extendedMetaData.getName(element));
String className = elementType.getInstanceClass().getName();
SDODataBindingTypeMappingEntry typeMappingEntry =
new SDODataBindingTypeMappingEntry(className, false, null);
typeMapping.put(qname, typeMappingEntry);
}