1 package org.objectweb.celtix.tools; 2 3 import java.util.HashSet ; 4 import java.util.Set ; 5 6 import org.objectweb.celtix.common.i18n.Message; 7 import org.objectweb.celtix.tools.common.ProcessorEnvironment; 8 import org.objectweb.celtix.tools.common.ToolConstants; 9 import org.objectweb.celtix.tools.common.ToolException; 10 import org.objectweb.celtix.tools.common.toolspec.ToolRunner; 11 import org.objectweb.celtix.tools.common.toolspec.ToolSpec; 12 import org.objectweb.celtix.tools.common.toolspec.parser.BadUsageException; 13 import org.objectweb.celtix.tools.common.toolspec.parser.CommandDocument; 14 import org.objectweb.celtix.tools.common.toolspec.parser.ErrorVisitor; 15 import org.objectweb.celtix.tools.processors.wsdl2.validators.WSDL11Validator; 16 17 public class WSDLValidator extends AbstractCeltixToolContainer { 18 19 private static final String TOOL_NAME = "wsdlvalidator"; 20 private static String [] args; 21 22 public WSDLValidator(ToolSpec toolspec) throws Exception { 23 super(TOOL_NAME, toolspec); 24 } 25 26 private Set getArrayKeys() { 27 Set <String > set = new HashSet <String >(); 28 set.add(ToolConstants.CFG_SCHEMA_URL); 29 return set; 30 } 31 32 public void execute(boolean exitOnFinish) { 33 try { 34 super.execute(exitOnFinish); 35 if (!hasInfoOption()) { 36 ProcessorEnvironment env = new ProcessorEnvironment(); 37 env.setParameters(getParametersMap(getArrayKeys())); 38 if (isVerboseOn()) { 39 env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE); 40 } 41 42 env.put(ToolConstants.CFG_CMD_ARG, args); 43 44 String schemaDir = (String )env.get(ToolConstants.CFG_SCHEMA_DIR); 45 if (schemaDir == null) { 46 throw new ToolException("Schema search directory should " 47 + "be defined before validating wsdl."); 48 } 49 50 WSDL11Validator wsdlValidator = new WSDL11Validator(null, env); 51 if (wsdlValidator.isValid()) { 52 System.out.println("Passed Validation : Valid WSDL "); 53 } 54 } 55 } catch (ToolException ex) { 56 System.err.println("Error : " + ex.getMessage()); 57 if (ex.getCause() instanceof BadUsageException) { 58 getInstance().printUsageException(TOOL_NAME, (BadUsageException)ex.getCause()); 59 } 60 System.err.println(); 61 if (isVerboseOn()) { 62 ex.printStackTrace(); 63 } 64 } catch (Exception ex) { 65 System.err.println("Error : " + ex.getMessage()); 66 System.err.println(); 67 if (isVerboseOn()) { 68 ex.printStackTrace(); 69 } 70 } 71 } 72 73 public static void main(String [] pargs) { 74 args = pargs; 75 76 try { 77 ToolRunner.runTool(WSDLValidator.class, WSDLValidator.class 78 .getResourceAsStream(ToolConstants.TOOLSPECS_BASE + "wsdlvalidator.xml"), false, args); 79 } catch (BadUsageException ex) { 80 getInstance().printUsageException(TOOL_NAME, ex); 81 } catch (Exception ex) { 82 System.err.println("Error : " + ex.getMessage()); 83 System.err.println(); 84 ex.printStackTrace(); 85 } 86 } 87 88 public void checkParams(ErrorVisitor errors) throws ToolException { 89 CommandDocument doc = super.getCommandDocument(); 90 91 if (!doc.hasParameter("wsdlurl")) { 92 errors.add(new ErrorVisitor.UserError("WSDL/SCHEMA URL has to be specified")); 93 } 94 if (errors.getErrors().size() > 0) { 95 Message msg = new Message("PARAMETER_MISSING", LOG); 96 throw new ToolException(msg, new BadUsageException(getUsage(), errors)); 97 } 98 } 99 } 100 | Popular Tags |