1 25 26 package org.objectweb.jonas_ws.wsgen.generator; 27 28 import java.io.File ; 29 import java.util.Enumeration ; 30 import java.util.Vector ; 31 32 import org.objectweb.common.Cmd; 33 34 import org.objectweb.jonas_lib.I18n; 35 import org.objectweb.jonas_lib.genbase.GenBaseException; 36 import org.objectweb.jonas_lib.genbase.generator.AbsGenerator; 37 import org.objectweb.jonas_lib.genbase.generator.Config; 38 39 import org.objectweb.jonas_ws.wsgen.WsGenException; 40 41 import org.objectweb.util.monolog.api.BasicLevel; 42 43 51 public abstract class Generator extends AbsGenerator { 52 53 56 private static I18n i18n = I18n.getInstance(Generator.class); 57 58 66 public Generator(Config config) throws GenBaseException { 67 super(config); 68 } 69 70 75 public abstract void generate() throws WsGenException; 76 77 82 public void compile() throws WsGenException { 83 try { 84 Vector srcs = new Vector (); 86 addJavaSources(getSources(), srcs); 87 88 Cmd cmd = new Cmd(getConfig().getJavaHomeBin() + getConfig().getNameJavac()); 89 cmd.addArgument("-classpath"); 90 cmd.addArgument(getConfig().getClasspath()); 91 cmd.addArgument("-d"); 92 cmd.addArgument(getClasses().getCanonicalPath()); 93 cmd.addArguments(getConfig().getJavacOpts()); 94 95 if (srcs.size() != 0) { 96 for (Enumeration e = srcs.elements(); e.hasMoreElements();) { 97 String srcName = ((File ) e.nextElement()).getCanonicalPath(); 98 cmd.addArgument(srcName); 99 } 100 101 getLogger().log(BasicLevel.DEBUG, "Running '" + cmd.toString() + "'"); 102 if (cmd.run()) { 103 getLogger().log(BasicLevel.INFO, "WebServices Classes successfully compiled."); 104 } else { 105 String err = getI18n().getMessage("Generator.compile.error"); 106 getLogger().log(BasicLevel.ERROR, err); 107 throw new WsGenException(err); 108 } 109 } 110 } catch (Exception e) { 111 String err = getI18n().getMessage("Generator.compile.error"); 112 getLogger().log(BasicLevel.ERROR, err); 113 throw new WsGenException(err, e); 114 } 115 } 116 117 118 121 protected static I18n getI18n() { 122 return i18n; 123 } 124 } | Popular Tags |