1 25 26 package org.objectweb.jonas_lib.genclientstub; 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 import org.objectweb.jonas_lib.genbase.utils.TempRepository; 36 import org.objectweb.jonas_lib.genclientstub.generator.GeneratorFactory; 37 import org.objectweb.jonas_lib.genclientstub.modifier.ModifierFactory; 38 39 import org.objectweb.jonas_ws.wsgen.NoJ2EEWebservicesException; 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 51 public class ClientStubGen { 52 53 56 private static Logger logger = Log.getLogger(Log.JONAS_CLIENTSTUBGEN_PREFIX); 57 58 61 private boolean inputModified = true; 62 63 66 public ClientStubGen() { 67 } 68 69 74 public static void main(String [] args) throws Exception { 75 ClientStubGen stubGen = new ClientStubGen(); 76 stubGen.execute(args); 77 } 78 79 86 public String execute(String [] args) throws Exception { 87 GeneratorFactory gf = GeneratorFactory.getInstance(); 88 89 Config config = parseInput(args); 91 92 if (config.isHelp() || config.isError() || config.getInputname() == null) { 93 usage(); 95 return null; 96 } 97 98 config.setDTDsAllowed(true); 100 101 gf.setConfiguration(config); 103 GeneratorFactories.setCurrentFactory(gf); 104 Archive modifiedArchive = null; 105 ArchiveModifier am = null; 106 try { 108 am = ModifierFactory.getModifier(config.getInputname()); 110 111 logger.log(BasicLevel.INFO, "Client stub generation for '" + config.getInputname() + "'"); 112 113 modifiedArchive = am.modify(); 115 116 String path = modifiedArchive.getRootFile().getCanonicalPath(); 118 119 return path; 120 } catch (NoJ2EEWebservicesException e) { 121 logger.log(BasicLevel.WARN, config.getInputname() + "Error while generating stubs : '" + e.getMessage() 122 + "'"); 123 inputModified = false; 124 return config.getInputname(); 125 } finally { 126 if (modifiedArchive != null) { 128 modifiedArchive.close(); 129 } 130 modifiedArchive = null; 131 am = null; 132 133 TempRepository.getInstance().deleteAll(); 135 } 136 137 } 138 139 144 private static Config parseInput(String [] args) { 145 Config config = new Config(); 146 147 for (int argn = 0; argn < args.length; argn++) { 149 String arg = args[argn]; 150 151 if (arg.equals("-help") || arg.equals("-?")) { 152 config.setHelp(true); 153 154 continue; 155 } 156 157 if (arg.equals("-verbose")) { 158 config.setVerbose(true); 159 160 continue; 161 } 162 163 if (arg.equals("-debug")) { 164 config.setDebug(true); 165 config.setVerbose(true); 166 167 continue; 168 } 169 170 if (arg.equals("-keepgenerated")) { 171 config.setKeepGenerated(true); 172 173 continue; 174 } 175 176 if (arg.equals("-noconfig")) { 177 config.setNoConfig(true); 178 179 continue; 180 } 181 182 if (arg.equals("-novalidation")) { 183 config.setParseWithValidation(false); 184 185 continue; 186 } 187 188 if (arg.equals("-javac")) { 189 config.setNameJavac(args[++argn]); 190 191 continue; 192 } 193 194 if (arg.equals("-javacopts")) { 195 argn++; 196 197 if (argn < args.length) { 198 StringTokenizer st = new StringTokenizer (args[argn]); 199 200 while (st.hasMoreTokens()) { 201 config.getJavacOpts().add(st.nextToken()); 202 } 203 } else { 204 config.setError(true); 205 } 206 207 continue; 208 } 209 210 if (arg.equals("-d")) { 211 argn++; 212 213 if (argn < args.length) { 214 config.setOut(new File (args[argn])); 215 } else { 216 config.setError(true); 217 } 218 219 continue; 220 } 221 222 if (args[argn] != null) { 223 config.setInputname(args[argn]); 224 } else { 225 config.setError(true); 226 } 227 } 228 229 return config; 230 231 } 232 233 236 public static void usage() { 237 StringBuffer msg = new StringBuffer (); 238 msg.append("Usage: java org.objectweb.jonas_lib.genclientstub.ClientStubgen -help \n"); 239 msg.append(" to print this help message \n"); 240 msg.append(" or java org.objectweb.jonas_lib.genclientstub.ClientStubgen <Options> <Input_File> \n"); 241 msg.append("Options include: \n"); 242 msg.append(" -d <output_dir> specify where to place the generated files \n"); 243 msg.append(" -novalidation parse the XML deployment descriptors without \n"); 244 msg.append(" validation \n"); 245 msg.append(" -javac <opt> specify the java compiler to use \n"); 246 msg.append(" -javacopts <opt> specify the options to pass to the java compiler \n"); 247 msg.append(" -keepgenerated do not delete intermediate generated files \n"); 248 msg.append(" -noconfig do not generate configuration files (require \n"); 249 msg.append(" user provided files) \n"); 250 msg.append(" -verbose \n"); 251 msg.append(" -debug \n"); 252 msg.append(" \n"); 253 msg.append(" Input_File the ejb-jar, war or ear filename\n"); 254 System.out.println(msg.toString()); 255 } 256 257 260 public boolean isInputModified() { 261 return inputModified; 262 } 263 } | Popular Tags |