WsGen.java

00001 
00029 package org.objectweb.jonas_ws.wsgen;
00030 
00031 import java.io.File;
00032 import java.util.StringTokenizer;
00033 
00034 import org.objectweb.jonas_lib.genbase.archive.Archive;
00035 import org.objectweb.jonas_lib.genbase.generator.Config;
00036 import org.objectweb.jonas_lib.genbase.generator.GeneratorFactories;
00037 import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier;
00038 
00039 import org.objectweb.jonas_lib.genbase.utils.TempRepository;
00040 
00041 import org.objectweb.jonas_ws.wsgen.generator.GeneratorFactory;
00042 import org.objectweb.jonas_ws.wsgen.modifier.ModifierFactory;
00043 
00044 import org.objectweb.jonas.common.Log;
00045 
00046 import org.objectweb.util.monolog.api.BasicLevel;
00047 import org.objectweb.util.monolog.api.Logger;
00048 
00053 public class WsGen {
00054 
00056     private static Logger logger = Log.getLogger(Log.JONAS_WSGEN_PREFIX);
00057 
00061     private boolean inputModified = true;
00062 
00066     public WsGen() { }
00067 
00073     public static void main(String[] args) throws Exception {
00074         WsGen wsgen = new WsGen();
00075         wsgen.execute(args);
00076     }
00077 
00085     public String execute(String[] args) throws Exception {
00086         GeneratorFactory gf = GeneratorFactory.getInstance();
00087 
00088         // store configuration properties
00089         Config config = parseInput(args);
00090 
00091         if (config.isHelp() || config.isError() || config.getInputname() == null) {
00092             // display usage message
00093             usage();
00094             return null;
00095         }
00096 
00097         // Make sure that DTD is turned to off
00098         config.setDTDsAllowed(false);
00099 
00100         // setup configuration
00101         gf.setConfiguration(config);
00102         GeneratorFactories.setCurrentFactory(gf);
00103 
00104         // get the ArchiveModifier
00105         try {
00106             ArchiveModifier am = ModifierFactory.getModifier(config.getInputname());
00107 
00108             logger.log(BasicLevel.INFO, "WebServices generation for '" + config.getInputname() + "'");
00109 
00110             // modify the given archive
00111             Archive modifiedArchive = am.modify();
00112 
00113             // delete all the temporary files created
00114             TempRepository.getInstance().deleteAll();
00115 
00116             return modifiedArchive.getRootFile().getCanonicalPath();
00117 
00118         } catch (NoJ2EEWebservicesException e) {
00119             TempRepository.getInstance().deleteAll();
00120             logger.log(BasicLevel.WARN, config.getInputname() + " is using DTDs, WsGen needs Schema only : "
00121                     + e.getMessage());
00122             inputModified = false;
00123             return config.getInputname();
00124         }
00125 
00126     }
00127 
00133     private static Config parseInput(String[] args) {
00134         Config config = new Config();
00135 
00136         // Get args
00137         for (int argn = 0; argn < args.length; argn++) {
00138             String arg = args[argn];
00139 
00140             if (arg.equals("-help") || arg.equals("-?")) {
00141                 config.setHelp(true);
00142 
00143                 continue;
00144             }
00145 
00146             if (arg.equals("-verbose")) {
00147                 config.setVerbose(true);
00148 
00149                 continue;
00150             }
00151 
00152             if (arg.equals("-debug")) {
00153                 config.setDebug(true);
00154                 config.setVerbose(true);
00155 
00156                 continue;
00157             }
00158 
00159             if (arg.equals("-keepgenerated")) {
00160                 config.setKeepGenerated(true);
00161 
00162                 continue;
00163             }
00164 
00165             if (arg.equals("-noconfig")) {
00166                 config.setNoConfig(true);
00167 
00168                 continue;
00169             }
00170 
00171             if (arg.equals("-novalidation")) {
00172                 config.setParseWithValidation(false);
00173 
00174                 continue;
00175             }
00176 
00177             if (arg.equals("-javac")) {
00178                 config.setNameJavac(args[++argn]);
00179 
00180                 continue;
00181             }
00182 
00183             if (arg.equals("-javacopts")) {
00184                 argn++;
00185 
00186                 if (argn < args.length) {
00187                     StringTokenizer st = new StringTokenizer(args[argn]);
00188 
00189                     while (st.hasMoreTokens()) {
00190                         config.getJavacOpts().add(st.nextToken());
00191                     }
00192                 } else {
00193                     config.setError(true);
00194                 }
00195 
00196                 continue;
00197             }
00198 
00199             if (arg.equals("-d")) {
00200                 argn++;
00201 
00202                 if (argn < args.length) {
00203                     config.setOut(new File(args[argn]));
00204                 } else {
00205                     config.setError(true);
00206                 }
00207 
00208                 continue;
00209             }
00210 
00211             if (args[argn] != null) {
00212                 config.setInputname(args[argn]);
00213             } else {
00214                 config.setError(true);
00215             }
00216         }
00217 
00218         return config;
00219 
00220     }
00221 
00225     public static void usage() {
00226         StringBuffer msg = new StringBuffer();
00227         msg.append("Usage: java org.objectweb.jonas_ws.wsgen.WsGen -help \n");
00228         msg.append("   to print this help message \n");
00229         msg.append(" or java org.objectweb.jonas_ws.wsgen.WsGen <Options> <Input_File> \n");
00230         msg.append("Options include: \n");
00231         msg.append("    -d <output_dir>  specify where to place the generated files \n");
00232         msg.append("    -novalidation parse the XML deployment descriptors without \n");
00233         msg.append("      validation \n");
00234         msg.append("    -javac  <opt> specify the java compiler to use \n");
00235         msg.append("    -javacopts <opt> specify the options to pass to the java compiler \n");
00236         msg.append("    -keepgenerated   do not delete intermediate generated files \n");
00237         msg.append("    -noconfig  do not generate configuration files (require \n");
00238         msg.append("      user provided files) \n");
00239         msg.append("    -verbose \n");
00240         msg.append("    -debug \n");
00241         msg.append(" \n");
00242         msg.append("    Input_File    the ejb-jar, war or ear filename\n");
00243         System.out.println(msg.toString());
00244     }
00245 
00249     public boolean isInputModified() {
00250         return inputModified;
00251     }
00252 }

Generated on Tue Feb 15 15:06:02 2005 for JOnAS by  doxygen 1.3.9.1