Generator.java

00001 
00026 package org.objectweb.jonas_ws.wsgen.generator;
00027 
00028 import java.io.File;
00029 import java.util.Enumeration;
00030 import java.util.Vector;
00031 
00032 import org.objectweb.common.Cmd;
00033 
00034 import org.objectweb.jonas_lib.I18n;
00035 import org.objectweb.jonas_lib.genbase.GenBaseException;
00036 import org.objectweb.jonas_lib.genbase.generator.AbsGenerator;
00037 import org.objectweb.jonas_lib.genbase.generator.Config;
00038 
00039 import org.objectweb.jonas_ws.wsgen.WsGenException;
00040 
00041 import org.objectweb.util.monolog.api.BasicLevel;
00042 
00051 public abstract class Generator extends AbsGenerator {
00052 
00056     private static I18n i18n = I18n.getInstance(Generator.class);
00057 
00066     public Generator(Config config) throws GenBaseException {
00067         super(config);
00068     }
00069 
00075     public abstract void generate() throws WsGenException;
00076 
00082     public void compile() throws WsGenException {
00083         try {
00084             // get all java files contained in the sources dir
00085             Vector srcs = new Vector();
00086             addJavaSources(getSources(), srcs);
00087 
00088             Cmd cmd = new Cmd(getConfig().getJavaHomeBin() + getConfig().getNameJavac());
00089             cmd.addArgument("-classpath");
00090             cmd.addArgument(getConfig().getClasspath());
00091             cmd.addArgument("-d");
00092             cmd.addArgument(getClasses().getCanonicalPath());
00093             cmd.addArguments(getConfig().getJavacOpts());
00094 
00095             if (srcs.size() != 0) {
00096                 for (Enumeration e = srcs.elements(); e.hasMoreElements();) {
00097                     String srcName = ((File) e.nextElement()).getCanonicalPath();
00098                     cmd.addArgument(srcName);
00099                 }
00100 
00101                 getLogger().log(BasicLevel.DEBUG, "Running '" + cmd.toString() + "'");
00102                 if (cmd.run()) {
00103                     getLogger().log(BasicLevel.INFO, "WebServices Classes successfully compiled.");
00104                 } else {
00105                     String err = getI18n().getMessage("Generator.compile.error");
00106                     getLogger().log(BasicLevel.ERROR, err);
00107                     throw new WsGenException(err);
00108                 }
00109             }
00110         } catch (Exception e) {
00111             String err = getI18n().getMessage("Generator.compile.error");
00112             getLogger().log(BasicLevel.ERROR, err);
00113             throw new WsGenException(err, e);
00114         }
00115     }
00116 
00117 
00121     protected static I18n getI18n() {
00122         return i18n;
00123     }
00124 }

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