public void enableDebugging(){
cer.enableDebugging();
}
}
final Listener listener = new Listener();
ErrorReceiverFilter receiver = new ErrorReceiverFilter(listener) {
public void info(SAXParseException exception) {
if (options.verbose)
super.info(exception);
}
public void warning(SAXParseException exception) {
if (!options.quiet)
super.warning(exception);
}
@Override
public void pollAbort() throws AbortException {
if (listener.isCanceled())
throw new AbortException();
}
@Override
public void debug(SAXParseException exception){
if(options.debugMode){
listener.debug(exception);
}
}
};
for (String arg : args) {
if (arg.equals("-version")) {
listener.message(ToolVersion.VERSION.BUILD_VERSION);
return true;
}
}
try {
options.parseArguments(args);
options.validate();
if(options.debugMode)
listener.enableDebugging();
options.parseBindings(receiver);
try {
if( !options.quiet )
listener.message(WscompileMessages.WSIMPORT_PARSING_WSDL());
//set auth info
//if(options.authFile != null)
Authenticator.setDefault(new DefaultAuthenticator(receiver, options.authFile));
WSDLModeler wsdlModeler = new WSDLModeler(options, receiver);
Model wsdlModel = wsdlModeler.buildModel();
if (wsdlModel == null) {
listener.message(WsdlMessages.PARSING_PARSE_FAILED());
return false;
}
SchemaCompilerEx schemaCompilerEx = (SchemaCompilerEx) (options
.getSchemaCompiler());
Outline outline = schemaCompilerEx.getOutline();
if (outline == null) {
listener.message(WsdlMessages.PARSING_PARSE_FAILED());
return false;
}
XjcErrorReceiverAdapter xjcErrorReceiver = new XjcErrorReceiverAdapter(receiver);
CGModel jaxbCodeGenModel = ModelBuilder.buildCodeGenModel(outline, xjcErrorReceiver);
SEIModelBuilder seiModelBuilder = new SEIModelBuilder(wsdlModel, receiver);
WSCodeGenModel wsCodeGenModel = seiModelBuilder.buildSEIModel();
CGConfig cgConfig = new CGConfig();
cgConfig.picoPrefix = options.prefix;
cgConfig.picoServiceGroup = wsCodeGenModel.getServiceEndpointInterfaces().get(0).getName();
// demo only configs
cgConfig.eBaySOAService = options.eBaySOAPService;
cgConfig.eBayShoppingAPI = options.eBayShoppingAPI;
cgConfig.eBayTradingAPI = options.eBayTradingAPI;
// for nano binding
cgConfig.nanoPrivateField = options.privateField;
// use specific client module to generate code
Set<FileInfo> targetFiles = new HashSet<FileInfo>();
try {
// generate types first
ClientModule clientModule = ModuleFactory.getModule(options.module);
clientModule.setErrorReceiver(xjcErrorReceiver);// enable reporting
clientModule.init();
Set<FileInfo> typeFiles = clientModule.generate(jaxbCodeGenModel, cgConfig);
// then generate ws client
WSClientModule wsClientModule = WSModuleFactory.getModule(options.module);
wsClientModule.setErrorReceiver(receiver);
wsClientModule.init();
Set<FileInfo> wsFiles = wsClientModule.generate(wsCodeGenModel, cgConfig);
targetFiles.addAll(typeFiles);
targetFiles.addAll(wsFiles);
} catch (XjcModuleException e1) {
receiver.error(e1);
return false;
} catch (WscModuleException e1) {
receiver.error(e1);
return false;
}
//generated code
if( !options.quiet )
listener.message(WscompileMessages.WSIMPORT_GENERATING_CODE());
try {
ICodeWriter cw = new FileCodeWriter(options.destDir, false);
if( !options.quiet ) {
XjcErrorListenerAdapter xjcErrorListenerAdapter = new XjcErrorListenerAdapter(listener);
cw = new ProgressCodeWriter(cw,xjcErrorListenerAdapter, targetFiles.size());
}
// then print them out
CodeBuilder.build(targetFiles, cw);
} catch (IOException e) {
//e.printStackTrace();
receiver.error(e);
return false;
}
listener.message("done.");