1 25 26 package org.objectweb.jonas_ws.wsgen; 27 28 import java.io.File ; 29 import java.util.StringTokenizer ; 30 31 import org.objectweb.jonas_lib.genbase.archive.Archive; 32 import org.objectweb.jonas_lib.genbase.generator.Config; 33 import org.objectweb.jonas_lib.genbase.generator.GeneratorFactories; 34 import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier; 35 36 import org.objectweb.jonas_lib.genbase.utils.TempRepository; 37 38 import org.objectweb.jonas_ws.wsgen.generator.GeneratorFactory; 39 import org.objectweb.jonas_ws.wsgen.modifier.ModifierFactory; 40 41 import org.objectweb.jonas.common.Log; 42 43 import org.objectweb.util.monolog.api.BasicLevel; 44 import org.objectweb.util.monolog.api.Logger; 45 46 50 public class WsGen { 51 52 53 private static Logger logger = Log.getLogger(Log.JONAS_WSGEN_PREFIX); 54 55 58 private boolean inputModified = true; 59 60 63 public WsGen() { } 64 65 70 public static void main(String [] args) throws Exception { 71 WsGen wsgen = new WsGen(); 72 wsgen.execute(args); 73 } 74 75 82 public String execute(String [] args) throws Exception { 83 GeneratorFactory gf = GeneratorFactory.getInstance(); 84 85 Config config = parseInput(args); 87 88 if (config.isHelp() || config.isError() || config.getInputname() == null) { 89 usage(); 91 return null; 92 } 93 94 config.setDTDsAllowed(false); 96 97 gf.setConfiguration(config); 99 GeneratorFactories.setCurrentFactory(gf); 100 Archive modifiedArchive = null; 101 ArchiveModifier am = null; 102 try { 104 am = ModifierFactory.getModifier(config.getInputname()); 105 106 logger.log(BasicLevel.INFO, "WebServices generation for '" + config.getInputname() + "'"); 107 108 modifiedArchive = am.modify(); 110 111 TempRepository.getInstance().deleteAll(); 113 114 return modifiedArchive.getRootFile().getCanonicalPath(); 115 116 } catch (NoJ2EEWebservicesException e) { 117 logger.log(BasicLevel.WARN, config.getInputname() + " is using DTDs, WsGen needs Schema only : " 118 + e.getMessage()); 119 inputModified = false; 120 return config.getInputname(); 121 } finally { 122 if (modifiedArchive != null) { 124 modifiedArchive.close(); 125 } 126 modifiedArchive = null; 127 am = null; 128 129 TempRepository.getInstance().deleteAll(); 131 } 132 133 } 134 135 140 private static Config parseInput(String [] args) { 141 Config config = new Config(); 142 143 for (int argn = 0; argn < args.length; argn++) { 145 String arg = args[argn]; 146 147 if (arg.equals("-help") || arg.equals("-?")) { 148 config.setHelp(true); 149 150 continue; 151 } 152 153 if (arg.equals("-verbose")) { 154 config.setVerbose(true); 155 156 continue; 157 } 158 159 if (arg.equals("-debug")) { 160 config.setDebug(true); 161 config.setVerbose(true); 162 163 continue; 164 } 165 166 if (arg.equals("-keepgenerated")) { 167 config.setKeepGenerated(true); 168 169 continue; 170 } 171 172 if (arg.equals("-noconfig")) { 173 config.setNoConfig(true); 174 175 continue; 176 } 177 178 if (arg.equals("-novalidation")) { 179 config.setParseWithValidation(false); 180 181 continue; 182 } 183 184 if (arg.equals("-javac")) { 185 config.setNameJavac(args[++argn]); 186 187 continue; 188 } 189 190 if (arg.equals("-javacopts")) { 191 argn++; 192 193 if (argn < args.length) { 194 StringTokenizer st = new StringTokenizer (args[argn]); 195 196 while (st.hasMoreTokens()) { 197 config.getJavacOpts().add(st.nextToken()); 198 } 199 } else { 200 config.setError(true); 201 } 202 203 continue; 204 } 205 206 if (arg.equals("-d")) { 207 argn++; 208 209 if (argn < args.length) { 210 config.setOut(new File (args[argn])); 211 } else { 212 config.setError(true); 213 } 214 215 continue; 216 } 217 218 if (args[argn] != null) { 219 config.setInputname(args[argn]); 220 } else { 221 config.setError(true); 222 } 223 } 224 225 return config; 226 227 } 228 229 232 public static void usage() { 233 StringBuffer msg = new StringBuffer (); 234 msg.append("Usage: java org.objectweb.jonas_ws.wsgen.WsGen -help \n"); 235 msg.append(" to print this help message \n"); 236 msg.append(" or java org.objectweb.jonas_ws.wsgen.WsGen <Options> <Input_File> \n"); 237 msg.append("Options include: \n"); 238 msg.append(" -d <output_dir> specify where to place the generated files \n"); 239 msg.append(" -novalidation parse the XML deployment descriptors without \n"); 240 msg.append(" validation \n"); 241 msg.append(" -javac <opt> specify the java compiler to use \n"); 242 msg.append(" -javacopts <opt> specify the options to pass to the java compiler \n"); 243 msg.append(" -keepgenerated do not delete intermediate generated files \n"); 244 msg.append(" -noconfig do not generate configuration files (require \n"); 245 msg.append(" user provided files) \n"); 246 msg.append(" -verbose \n"); 247 msg.append(" -debug \n"); 248 msg.append(" \n"); 249 msg.append(" Input_File the ejb-jar, war or ear filename\n"); 250 System.out.println(msg.toString()); 251 } 252 253 256 public boolean isInputModified() { 257 return inputModified; 258 } 259 } | Popular Tags |