01: package org.objectweb.celtix.tools;
02:
03: import java.util.HashSet;
04:
05: import javax.wsdl.Definition;
06:
07: import org.objectweb.celtix.common.i18n.Message;
08: import org.objectweb.celtix.tools.common.ProcessorEnvironment;
09: import org.objectweb.celtix.tools.common.ToolConstants;
10: import org.objectweb.celtix.tools.common.ToolException;
11: import org.objectweb.celtix.tools.common.toolspec.ToolRunner;
12: import org.objectweb.celtix.tools.common.toolspec.ToolSpec;
13: import org.objectweb.celtix.tools.common.toolspec.parser.BadUsageException;
14: import org.objectweb.celtix.tools.common.toolspec.parser.ErrorVisitor;
15: import org.objectweb.celtix.tools.processors.java2.JavaToWSDLProcessor;
16:
17: public class JavaToWSDL extends AbstractCeltixToolContainer {
18:
19: private static final String TOOL_NAME = "java2wsdl";
20: private static String[] args;
21: private static Definition definition;
22:
23: public JavaToWSDL(ToolSpec toolspec) throws Exception {
24: super (TOOL_NAME, toolspec);
25: }
26:
27: public void execute(boolean exitOnFinish) throws ToolException {
28: JavaToWSDLProcessor processor = new JavaToWSDLProcessor();
29:
30: try {
31: super .execute(exitOnFinish);
32: if (!hasInfoOption()) {
33: ProcessorEnvironment env = new ProcessorEnvironment();
34: env.setParameters(getParametersMap(new HashSet()));
35: if (isVerboseOn()) {
36: env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
37: }
38: processor.setEnvironment(env);
39: processor.process();
40: definition = processor.getModel().getDefinition();
41: }
42: } catch (ToolException ex) {
43: if (ex.getCause() instanceof BadUsageException) {
44: getInstance().printUsageException(TOOL_NAME,
45: (BadUsageException) ex.getCause());
46: }
47: throw ex;
48: } catch (Exception ex) {
49: throw new ToolException(ex.getMessage(), ex.getCause());
50: }
51: }
52:
53: public static void main(String[] pargs) {
54: try {
55: runTool(pargs);
56: } catch (BadUsageException ex) {
57: System.err.println("Error : " + ex.getMessage());
58: getInstance().printUsageException(TOOL_NAME, ex);
59: if (getInstance().isVerboseOn()) {
60: ex.printStackTrace();
61: }
62: } catch (Exception ex) {
63: System.err.println("Error : " + ex.getMessage());
64: System.err.println();
65: if (getInstance().isVerboseOn()) {
66: ex.printStackTrace();
67: }
68: }
69: }
70:
71: public static void runTool(String[] pargs) throws Exception {
72: args = pargs;
73: ToolRunner.runTool(JavaToWSDL.class, JavaToWSDL.class
74: .getResourceAsStream(ToolConstants.TOOLSPECS_BASE
75: + "java2wsdl.xml"), false, args);
76: }
77:
78: public void checkParams(ErrorVisitor errors) throws ToolException {
79: if (errors.getErrors().size() > 0) {
80: Message msg = new Message("PARAMETER_MISSSING", LOG);
81: throw new ToolException(msg, new BadUsageException(
82: getUsage(), errors));
83: }
84: }
85:
86: public static Definition getDefinition() {
87: return definition;
88: }
89: }
|