001: package org.objectweb.celtix.tools;
002:
003: import java.io.File;
004: import java.util.HashSet;
005: import java.util.Set;
006:
007: import org.objectweb.celtix.common.i18n.Message;
008: import org.objectweb.celtix.tools.common.ProcessorEnvironment;
009: import org.objectweb.celtix.tools.common.ToolConstants;
010: import org.objectweb.celtix.tools.common.ToolException;
011: import org.objectweb.celtix.tools.common.toolspec.ToolRunner;
012: import org.objectweb.celtix.tools.common.toolspec.ToolSpec;
013: import org.objectweb.celtix.tools.common.toolspec.parser.BadUsageException;
014: import org.objectweb.celtix.tools.common.toolspec.parser.CommandDocument;
015: import org.objectweb.celtix.tools.common.toolspec.parser.ErrorVisitor;
016: import org.objectweb.celtix.tools.processors.wsdl2.WSDLToServiceProcessor;
017:
018: public class WSDLToService extends AbstractCeltixToolContainer {
019:
020: static final String TOOL_NAME = "wsdl2service";
021: private static String[] args;
022:
023: public WSDLToService(ToolSpec toolspec) throws Exception {
024: super (TOOL_NAME, toolspec);
025: }
026:
027: private Set getArrayKeys() {
028: return new HashSet<String>();
029: }
030:
031: public void execute(boolean exitOnFinish) {
032: WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
033: try {
034: super .execute(exitOnFinish);
035: if (!hasInfoOption()) {
036: ProcessorEnvironment env = new ProcessorEnvironment();
037: env.setParameters(getParametersMap(getArrayKeys()));
038:
039: if (isVerboseOn()) {
040: env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
041: }
042:
043: env.put(ToolConstants.CFG_CMD_ARG, args);
044:
045: validate(env);
046:
047: processor.setEnvironment(env);
048: processor.process();
049: }
050: } catch (ToolException ex) {
051: System.err.println("Error : " + ex.getMessage());
052: if (ex.getCause() instanceof BadUsageException) {
053: getInstance().printUsageException(TOOL_NAME,
054: (BadUsageException) ex.getCause());
055: }
056: System.err.println();
057: if (isVerboseOn()) {
058: ex.printStackTrace();
059: }
060: } catch (Exception ex) {
061: System.err.println("Error : " + ex.getMessage());
062: System.err.println();
063: if (isVerboseOn()) {
064: ex.printStackTrace();
065: }
066: }
067: }
068:
069: private void validate(ProcessorEnvironment env)
070: throws ToolException {
071: String outdir = (String) env.get(ToolConstants.CFG_OUTPUTDIR);
072: if (outdir != null) {
073: File dir = new File(outdir);
074: if (!dir.exists()) {
075: Message msg = new Message("DIRECTORY_NOT_EXIST", LOG,
076: outdir);
077: throw new ToolException(msg);
078: }
079: if (!dir.isDirectory()) {
080: Message msg = new Message("NOT_A_DIRECTORY", LOG,
081: outdir);
082: throw new ToolException(msg);
083: }
084: }
085: }
086:
087: public static void main(String[] pargs) {
088: args = pargs;
089: try {
090: String toolSpecFile = ToolConstants.TOOLSPECS_BASE
091: + "wsdl2service.xml";
092: ToolRunner.runTool(WSDLToService.class, WSDLToService.class
093: .getResourceAsStream(toolSpecFile), false, args);
094: } catch (BadUsageException ex) {
095: getInstance().printUsageException(TOOL_NAME, ex);
096: } catch (Exception ex) {
097: System.err.println("Error : " + ex.getMessage());
098: System.err.println();
099: ex.printStackTrace();
100: }
101: }
102:
103: public void checkParams(ErrorVisitor errors) throws ToolException {
104: CommandDocument doc = super .getCommandDocument();
105:
106: if (!doc.hasParameter("wsdlurl")) {
107: errors.add(new ErrorVisitor.UserError(
108: "WSDL/SCHEMA URL has to be specified"));
109: }
110: if (errors.getErrors().size() > 0) {
111: Message msg = new Message("PARAMETER_MISSING", LOG);
112: throw new ToolException(msg, new BadUsageException(
113: getUsage(), errors));
114: }
115: }
116: }
|