1 package org.objectweb.celtix.tools; 2 3 import java.io.File ; 4 import java.util.HashSet ; 5 import java.util.Set ; 6 7 import org.objectweb.celtix.common.i18n.Message; 8 import org.objectweb.celtix.tools.common.ProcessorEnvironment; 9 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.CommandDocument; 15 import org.objectweb.celtix.tools.common.toolspec.parser.ErrorVisitor; 16 import org.objectweb.celtix.tools.processors.wsdl2.WSDLToServiceProcessor; 17 18 public class WSDLToService extends AbstractCeltixToolContainer { 19 20 static final String TOOL_NAME = "wsdl2service"; 21 private static String [] args; 22 23 public WSDLToService(ToolSpec toolspec) throws Exception { 24 super(TOOL_NAME, toolspec); 25 } 26 27 private Set getArrayKeys() { 28 return new HashSet <String >(); 29 } 30 31 public void execute(boolean exitOnFinish) { 32 WSDLToServiceProcessor processor = new WSDLToServiceProcessor(); 33 try { 34 super.execute(exitOnFinish); 35 if (!hasInfoOption()) { 36 ProcessorEnvironment env = new ProcessorEnvironment(); 37 env.setParameters(getParametersMap(getArrayKeys())); 38 39 if (isVerboseOn()) { 40 env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE); 41 } 42 43 env.put(ToolConstants.CFG_CMD_ARG, args); 44 45 validate(env); 46 47 processor.setEnvironment(env); 48 processor.process(); 49 } 50 } catch (ToolException ex) { 51 System.err.println("Error : " + ex.getMessage()); 52 if (ex.getCause() instanceof BadUsageException) { 53 getInstance().printUsageException(TOOL_NAME, (BadUsageException)ex.getCause()); 54 } 55 System.err.println(); 56 if (isVerboseOn()) { 57 ex.printStackTrace(); 58 } 59 } catch (Exception ex) { 60 System.err.println("Error : " + ex.getMessage()); 61 System.err.println(); 62 if (isVerboseOn()) { 63 ex.printStackTrace(); 64 } 65 } 66 } 67 68 private void validate(ProcessorEnvironment env) throws ToolException { 69 String outdir = (String )env.get(ToolConstants.CFG_OUTPUTDIR); 70 if (outdir != null) { 71 File dir = new File (outdir); 72 if (!dir.exists()) { 73 Message msg = new Message("DIRECTORY_NOT_EXIST", LOG, outdir); 74 throw new ToolException(msg); 75 } 76 if (!dir.isDirectory()) { 77 Message msg = new Message("NOT_A_DIRECTORY", LOG, outdir); 78 throw new ToolException(msg); 79 } 80 } 81 } 82 83 public static void main(String [] pargs) { 84 args = pargs; 85 try { 86 String toolSpecFile = ToolConstants.TOOLSPECS_BASE + "wsdl2service.xml"; 87 ToolRunner.runTool(WSDLToService.class, WSDLToService.class.getResourceAsStream(toolSpecFile), 88 false, args); 89 } catch (BadUsageException ex) { 90 getInstance().printUsageException(TOOL_NAME, ex); 91 } catch (Exception ex) { 92 System.err.println("Error : " + ex.getMessage()); 93 System.err.println(); 94 ex.printStackTrace(); 95 } 96 } 97 98 public void checkParams(ErrorVisitor errors) throws ToolException { 99 CommandDocument doc = super.getCommandDocument(); 100 101 if (!doc.hasParameter("wsdlurl")) { 102 errors.add(new ErrorVisitor.UserError("WSDL/SCHEMA URL has to be specified")); 103 } 104 if (errors.getErrors().size() > 0) { 105 Message msg = new Message("PARAMETER_MISSING", LOG); 106 throw new ToolException(msg, new BadUsageException(getUsage(), errors)); 107 } 108 } 109 } 110 | Popular Tags |