ClientStubGen.java

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

Generated on Tue Feb 15 15:05:54 2005 for JOnAS by  doxygen 1.3.9.1