1 25 26 package org.objectweb.jonas_lib.genclientstub.generator; 27 28 import java.io.File ; 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import java.util.Map ; 32 33 import org.objectweb.carol.util.configuration.ConfigurationRepository; 34 35 import org.objectweb.common.Cmd; 36 37 import org.objectweb.jonas_lib.I18n; 38 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc; 39 import org.objectweb.jonas_lib.genbase.GenBaseException; 40 import org.objectweb.jonas_lib.genbase.archive.Archive; 41 import org.objectweb.jonas_lib.genbase.archive.Client; 42 import org.objectweb.jonas_lib.genbase.archive.EjbJar; 43 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive; 44 import org.objectweb.jonas_lib.genbase.archive.WebApp; 45 import org.objectweb.jonas_lib.genbase.generator.AbsGenerator; 46 import org.objectweb.jonas_lib.genbase.generator.Config; 47 import org.objectweb.jonas_lib.genclientstub.ClientStubGenException; 48 import org.objectweb.jonas_lib.loader.AbsModuleClassLoader; 49 50 import org.objectweb.util.monolog.api.BasicLevel; 51 52 56 public class Generator extends AbsGenerator { 57 58 61 private static I18n i18n = I18n.getInstance(Generator.class); 62 63 66 private EjbRefDesc ejbRef = null; 67 68 71 private String intfStubClassName = null; 72 73 76 private Archive archive = null; 77 78 87 public Generator(Config config, EjbRefDesc ejbRef, String intfStubClassName, Archive archive) throws GenBaseException { 88 super(config); 89 this.ejbRef = ejbRef; 90 this.intfStubClassName = intfStubClassName; 91 this.archive = archive; 92 } 93 94 98 public void generate() throws ClientStubGenException { 99 100 try { 101 String archiveClasspath = null; 103 104 J2EEArchive arch = (J2EEArchive) this.archive; 105 AbsModuleClassLoader loader = (AbsModuleClassLoader) arch.getModuleClassloader(); 106 107 archiveClasspath = loader.getClasspath(); 108 109 String itfClass = null; 111 if (ejbRef != null) { 112 itfClass = ejbRef.getHome(); 113 } else { 114 itfClass = intfStubClassName; 115 } 116 117 119 String classpath = getConfig().getClasspath() + File.separator + archiveClasspath; 121 122 124 Map commands = new HashMap (); 126 127 String rmiName = ConfigurationRepository.getCurrentConfiguration().getProtocol().getName(); 129 130 135 143 if (rmiName.equalsIgnoreCase("iiop")) { 144 Cmd iiopCmd = new Cmd(getConfig().getJavaHomeBin() + getConfig().getNameRmic()); 145 iiopCmd.addArgument("-classpath"); 146 iiopCmd.addArgument(classpath); 147 iiopCmd.addArgument("-iiop"); 148 iiopCmd.addArgument("-poa"); 149 iiopCmd.addArgument("-always"); 150 iiopCmd.addArgument("-keepgenerated"); 151 iiopCmd.addArgument("-g"); 152 commands.put("iiop", iiopCmd); 153 } 154 155 156 for (Iterator itCmd = commands.keySet().iterator(); itCmd.hasNext();) { 157 String protocol = (String ) itCmd.next(); 158 Cmd cmd = (Cmd) commands.get(protocol); 159 cmd.addArgument("-d"); 160 cmd.addArgument(getClasses().getCanonicalPath()); 161 cmd.addArguments(getConfig().getJavacOpts()); 162 163 cmd.addArgument(itfClass); 165 166 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 167 getLogger().log(BasicLevel.DEBUG, "Running '" + cmd.toString() + "'"); 168 } 169 if (cmd.run()) { 170 getLogger().log(BasicLevel.INFO, 171 "Client stubs for classname '" + itfClass + "' successfully generated for protocol '" + protocol + "'."); 172 } else { 173 String err = i18n.getMessage("Generator.generate.error"); 174 getLogger().log(BasicLevel.ERROR, err); 175 throw new ClientStubGenException(err); 176 } 177 } 178 179 } catch (Exception e) { 180 String err = i18n.getMessage("Generator.generate.error"); 181 getLogger().log(BasicLevel.ERROR, err); 182 throw new ClientStubGenException(err, e); 183 } 184 185 } 186 187 192 public void compile() throws ClientStubGenException { 193 } 194 195 201 public void addFiles(Archive archive) throws ClientStubGenException { 202 if (archive instanceof WebApp) { 203 archive.addDirectoryIn("WEB-INF/classes/", getClasses()); 204 } else if (archive instanceof EjbJar) { 205 archive.addDirectory(getClasses()); 206 } else if (archive instanceof Client) { 207 archive.addDirectory(getClasses()); 208 } 209 } 210 211 } | Popular Tags |