use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class WSDLToJava method main.
public static void main(String[] pargs) {
System.setProperty("org.apache.cxf.JDKBugHacks.defaultUsesCaches", "true");
CommandInterfaceUtils.commandCommonMain();
WSDLToJava w2j = new WSDLToJava(pargs);
try {
w2j.run(new ToolContext());
} catch (ToolException ex) {
System.err.println();
System.err.println("WSDLToJava Error: " + ex.getMessage());
System.err.println();
if (w2j.isVerbose()) {
ex.printStackTrace();
}
if (w2j.isExitOnFinish()) {
System.exit(1);
}
} catch (Exception ex) {
System.err.println("WSDLToJava Error: " + ex.getMessage());
System.err.println();
if (w2j.isVerbose()) {
ex.printStackTrace();
}
if (w2j.isExitOnFinish()) {
System.exit(1);
}
}
if (w2j.isExitOnFinish()) {
System.exit(0);
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class WSDLToJavaContainer method execute.
public void execute() throws ToolException {
if (hasInfoOption()) {
return;
}
buildToolContext();
boolean isWsdlList = context.optionSet(ToolConstants.CFG_WSDLLIST);
if (isWsdlList) {
BufferedReader reader = null;
try {
ToolContext initialContextState = context.makeCopy();
String wsdlURL = (String) context.get(ToolConstants.CFG_WSDLURL);
wsdlURL = URIParserUtil.getAbsoluteURI(wsdlURL);
URL url = new URL(wsdlURL);
InputStream is = (InputStream) url.getContent();
reader = new BufferedReader(new InputStreamReader(is));
String tempLine = null;
while ((tempLine = reader.readLine()) != null) {
ToolContext freshContext = initialContextState.makeCopy();
freshContext.put(ToolConstants.CFG_WSDLURL, tempLine);
setContext(freshContext);
buildToolContext();
processWsdl();
}
if (context.getErrorListener().getErrorCount() > 0) {
context.getErrorListener().throwToolException();
}
} catch (IOException e) {
throw new ToolException(e);
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
throw new ToolException(e);
}
}
} else {
processWsdl();
if (context.getErrorListener().getErrorCount() > 0) {
context.getErrorListener().throwToolException();
}
}
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class WSDLToJavaContainerTest method testWsdlLocationDefaultSchemeIsFile.
@Test
public void testWsdlLocationDefaultSchemeIsFile() throws Exception {
WSDLToJavaContainer container = new WSDLToJavaContainer("dummy", null);
ToolContext context = new ToolContext();
context.put(ToolConstants.CFG_WSDLURL, getLocation("hello_world.wsdl"));
container.setContext(context);
container.validate(context);
String wsdlLocation = (String) context.get(ToolConstants.CFG_WSDLLOCATION);
assertTrue("default scheme for wsdlLocation is file", wsdlLocation.startsWith("file:"));
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class AbstractGeneratorTest method testOverwrite.
@Test
public void testOverwrite() throws Exception {
gen = new DummyGenerator();
util = new FileWriterUtil(output.toString(), null);
context = new ToolContext();
context.put(ToolConstants.CFG_OUTPUTDIR, output.toString());
gen.setEnvironment(context);
Writer writer = util.getWriter(packageName, className + ".java");
writer.write("hello world");
writer.flush();
writer.close();
assertNotNull(gen.parseOutputName(packageName, className));
}
use of org.apache.cxf.tools.common.ToolContext in project cxf by apache.
the class JavaToJS method execute.
public void execute(boolean exitOnFinish) {
Processor processor = new JavaToJSProcessor();
try {
super.execute(exitOnFinish);
if (!hasInfoOption()) {
ToolContext env = new ToolContext();
env.setParameters(getParametersMap(new HashSet<>()));
if (env.get(ToolConstants.CFG_OUTPUTDIR) == null) {
env.put(ToolConstants.CFG_OUTPUTDIR, ".");
}
if (isVerboseOn()) {
env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
}
env.put(ToolConstants.CFG_CMD_ARG, getArgument());
validate(env);
processor.setEnvironment(env);
processor.process();
}
} catch (ToolException ex) {
if (ex.getCause() instanceof BadUsageException) {
printUsageException(TOOL_NAME, (BadUsageException) ex.getCause());
}
err.println();
err.println("JavaToJS Error : " + ex.getMessage());
if (isVerboseOn()) {
ex.printStackTrace(err);
}
} catch (Exception ex) {
err.println();
err.println("JavaToJS Error : " + ex.getMessage());
if (isVerboseOn()) {
ex.printStackTrace(err);
}
} finally {
tearDown();
}
}
Aggregations