@SuppressWarnings("unchecked")
public void initialize(ToolContext c) throws ToolException {
this.context = c;
SchemaCompilerImpl schemaCompiler = (SchemaCompilerImpl)XJC.createSchemaCompiler();
ClassCollector classCollector = context.get(ClassCollector.class);
ClassNameAllocatorImpl allocator = new ClassNameAllocatorImpl(classCollector);
schemaCompiler.setClassNameAllocator(allocator);
JAXBBindErrorListener listener = new JAXBBindErrorListener(context.isVerbose());
schemaCompiler.setErrorListener(listener);
// Collection<SchemaInfo> schemas = serviceInfo.getSchemas();
List<InputSource> jaxbBindings = context.getJaxbBindingFile();
Map<String, Element> schemaLists = (Map<String, Element>)context.get(ToolConstants.SCHEMA_MAP);
Set<String> keys = schemaLists.keySet();
for (String key : keys) {
Element ele = schemaLists.get(key);
this.removeImportElement(ele);
String tns = ele.getAttribute("targetNamespace");
if (StringUtils.isEmpty(tns)) {
continue;
}
if (context.get(ToolConstants.CFG_VALIDATE_WSDL) != null) {
validateSchema(ele);
}
schemaCompiler.parseSchema(key, ele);
}
for (InputSource binding : jaxbBindings) {
schemaCompiler.parseSchema(binding);
}
Map<String, String> nsPkgMap = context.getNamespacePackageMap();
for (String ns : nsPkgMap.keySet()) {
File file = JAXBUtils.getPackageMappingSchemaBindingFile(ns, context.mapPackageName(ns));
try {
InputSource ins = new InputSource(file.toURI().toString());
schemaCompiler.parseSchema(ins);
} finally {
FileUtils.delete(file);
}
}
if (context.getPackageName() != null) {
schemaCompiler.setDefaultPackageName(context.getPackageName());
}
Options opts = null;
opts = getOptions(schemaCompiler);
Vector<String> args = new Vector<String>();
if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null) {
//hard code to enabale jaxb extensions
args.add("-extension");
URL bindingFileUrl = getClass().getResource("W3CEPRJaxbBinding.xml");
InputSource ins = new InputSource(bindingFileUrl.toString());
schemaCompiler.parseSchema(ins);
}
if (context.get(ToolConstants.CFG_XJC_ARGS) != null) {
String xjcArgs = (String)context.get(ToolConstants.CFG_XJC_ARGS);
StringTokenizer tokenizer = new StringTokenizer(xjcArgs, ",", false);
while (tokenizer.hasMoreTokens()) {
String arg = tokenizer.nextToken();
args.add(arg);
LOG.log(Level.FINE, "xjc arg:" + arg);
}
}
if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null
|| context.get(ToolConstants.CFG_XJC_ARGS) != null) {
try {
// keep parseArguments happy, supply dummy required command-line
// opts
opts.addGrammar(new InputSource("null"));
opts.parseArguments(args.toArray(new String[] {}));
} catch (BadCommandLineException e) {
String msg = "XJC reported 'BadCommandLineException' for -xjc argument:";
for (String arg : args) {
msg = msg + arg + " ";
}
LOG.log(Level.FINE, msg, e);
if (opts != null) {
String pluginUsage = getPluginUsageString(opts);
msg = msg + System.getProperty("line.separator");
if (args.contains("-X")) {
msg = pluginUsage;
} else {
msg += pluginUsage;
}
}
throw new ToolException(msg, e);
}
}
rawJaxbModelGenCode = schemaCompiler.bind();
addedEnumClassToCollector(schemaLists, allocator);
if (context.get(ToolConstants.CFG_DEFAULT_VALUES) != null) {
String cname = (String)context.get(ToolConstants.CFG_DEFAULT_VALUES);