public static void invoke(CodeGenConfiguration configuration) throws Exception {
List schemaList = new ArrayList();
// add all the schemas to the list
List services = configuration.getAxisServices();
for (Iterator iter = services.iterator();iter.hasNext();){
schemaList.addAll(((AxisService)iter.next()).getSchema());
}
//hashmap that keeps the targetnamespace and the xmlSchema object
//this is a convenience to locate the relevant schema quickly
//by looking at the target namespace
Map schemaMap = new HashMap();
populateSchemaMap(schemaMap, schemaList);
if (schemaList == null || schemaList.isEmpty()) {
//there are no types to be code generated
//However if the type mapper is left empty it will be a problem for the other
//processes. Hence the default type mapper is set to the configuration
configuration.setTypeMapper(new DefaultTypeMapper());
return;
}
//call the schema compiler
CompilerOptions options = new CompilerOptions();
//set the default options
populateDefaultOptions(options, configuration);
//set the user parameters. the user parameters get the preference over
//the default ones. But the user better know what he's doing if he
//used module specific parameters
populateUserparameters(options, configuration);
SchemaCompiler schemaCompiler = new SchemaCompiler(options);
// run the schema compiler
schemaCompiler.compile(schemaList);
//create the type mapper
//First try to take the one that is already there
TypeMapper mapper = configuration.getTypeMapper();
if (mapper == null) {
if (configuration.getOutputLanguage() != null &&
!configuration.getOutputLanguage().trim().equals("") &&
configuration.getOutputLanguage().toLowerCase().equals("c")) {
mapper = new CTypeMapper();
} else {
mapper = new JavaTypeMapper();
}
}
if (options.isWriteOutput()) {
//get the processed element map and transfer it to the type mapper
Map processedMap = schemaCompiler.getProcessedElementMap();
Iterator processedkeys = processedMap.keySet().iterator();
QName qNameKey;
while (processedkeys.hasNext()) {
qNameKey = (QName) processedkeys.next();
mapper.addTypeMappingName(qNameKey, processedMap.get(qNameKey).toString());
}
} else {
//get the processed model map and transfer it to the type mapper
//since the options mentiond that its not writable, it should have
//populated the model map
Map processedModelMap = schemaCompiler.getProcessedModelMap();
Iterator processedkeys = processedModelMap.keySet().iterator();
QName qNameKey;
while (processedkeys.hasNext()) {
qNameKey = (QName) processedkeys.next();
mapper.addTypeMappingObject(qNameKey, processedModelMap.get(qNameKey));
}
Map processedMap = schemaCompiler.getProcessedElementMap();
processedkeys = processedMap.keySet().iterator();
while (processedkeys.hasNext()) {
qNameKey = (QName) processedkeys.next();
mapper.addTypeMappingName(qNameKey, processedMap.get(qNameKey).toString());
}
//get the ADB template from the schema compilers property bag and set the
//template
configuration.putProperty(Constants.EXTERNAL_TEMPLATE_PROPERTY_KEY,
schemaCompiler.getCompilerProperties().getProperty(
SchemaConstants.SchemaPropertyNames.BEAN_WRITER_TEMPLATE_KEY));
}
//process the unwrapped parameters
if (!configuration.isParametersWrapped()) {
//figure out the unwrapped operations
List axisServices = configuration.getAxisServices();
AxisService axisService;
for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
axisService = (AxisService) servicesIter.next();
for (Iterator operations = axisService.getOperations();
operations.hasNext();) {
AxisOperation op = (AxisOperation) operations.next();
if (WSDLUtil.isInputPresentForMEP(op.getMessageExchangePattern())) {
walkSchema(op.getMessage(
WSDLConstants.MESSAGE_LABEL_IN_VALUE),
mapper,
schemaMap,
op.getName().getLocalPart(),
WSDLConstants.INPUT_PART_QNAME_SUFFIX);
}
// TODO: support for xml beans
if (configuration.getDatabindingType().equals("adb")) {
if (WSDLUtil.isOutputPresentForMEP(op.getMessageExchangePattern())) {
walkSchema(op.getMessage(
WSDLConstants.MESSAGE_LABEL_OUT_VALUE),
mapper,
schemaMap,
op.getName().getLocalPart(),
WSDLConstants.OUTPUT_PART_QNAME_SUFFIX);
}
}
}
}
}
//put the complext types for the top level elements having them
// this is needed in unwrapping and to provide backwordCompatibility
if (!configuration.isParametersWrapped() || configuration.isBackwordCompatibilityMode()) {
List axisServices = configuration.getAxisServices();
AxisService axisService;
for (Iterator servicesIter = axisServices.iterator(); servicesIter.hasNext();) {
axisService = (AxisService) servicesIter.next();
AxisOperation axisOperation;
AxisMessage axisMessage;
for (Iterator operators = axisService.getOperations(); operators.hasNext();) {
axisOperation = (AxisOperation) operators.next();
if (WSDLUtil.isInputPresentForMEP(axisOperation.getMessageExchangePattern())) {
axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
setComplexTypeName(axisMessage);
}
if (WSDLUtil.isOutputPresentForMEP(axisOperation.getMessageExchangePattern())) {
axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
setComplexTypeName(axisMessage);
}
}
}
}
//set the type mapper to the config
configuration.setTypeMapper(mapper);
}
|