1 25 package org.objectweb.jonas_ws.wsgen.modifier; 26 27 import java.io.File ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import org.objectweb.jonas_lib.genbase.GenBaseException; 32 import org.objectweb.jonas_lib.genbase.archive.Application; 33 import org.objectweb.jonas_lib.genbase.archive.Archive; 34 import org.objectweb.jonas_lib.genbase.archive.DummyApplication; 35 import org.objectweb.jonas_lib.genbase.archive.DummyWebApp; 36 import org.objectweb.jonas_lib.genbase.archive.Ejb; 37 import org.objectweb.jonas_lib.genbase.archive.EjbJar; 38 import org.objectweb.jonas_lib.genbase.archive.WebApp; 39 import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier; 40 import org.objectweb.jonas_ws.deployment.api.ServiceDesc; 41 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc; 42 import org.objectweb.jonas_ws.wsgen.ddmodifier.ContextDDModifier; 43 import org.objectweb.jonas_ws.wsgen.ddmodifier.WebJettyDDModifier; 44 import org.objectweb.jonas_ws.wsgen.ddmodifier.WsClientDDModifier; 45 import org.objectweb.jonas_ws.wsgen.ddmodifier.WsEndpointDDModifier; 46 import org.objectweb.jonas_ws.wsgen.generator.Generator; 47 import org.objectweb.jonas_ws.wsgen.generator.GeneratorFactory; 48 import org.objectweb.jonas_ws.wsgen.generator.SecurityGenerator; 49 import org.objectweb.util.monolog.api.BasicLevel; 50 import org.w3c.dom.Document ; 51 52 57 public class EjbJarModifier extends ArchiveModifier { 58 59 60 private EjbJar ejbjar = null; 61 62 67 public EjbJarModifier(EjbJar ejbjar) { 68 super(ejbjar); 69 this.ejbjar = ejbjar; 70 } 71 72 83 public Archive modify() throws GenBaseException { 84 85 getLogger().log(BasicLevel.INFO, "Processing EjbJar " + ejbjar.getName()); 86 87 GeneratorFactory gf = GeneratorFactory.getInstance(); 88 Document jejbjar = ejbjar.getJonasEjbJarDoc(); 89 90 List sds = ejbjar.getServiceDescs(); 92 93 if (sds.size() != 0) { 94 if (ejbjar.getApplication() == null) { 95 97 101 String ejbName = ejbjar.getRootFile().getName(); 102 String earName = ejbName.substring(0, ejbName.length() - ".jar".length()) + ".ear"; 103 Application application = new DummyApplication(earName); 104 ejbjar.setApplication(application); 105 application.addEjbJar(ejbjar); 106 ApplicationModifier am = new ApplicationModifier(application); 107 108 return am.modify(); 109 110 } else { 111 113 118 119 String warName = null; 120 String war = ejbjar.getWarName(); 121 if (war != null) { 122 warName = war; 123 } else { 124 String ejbName = ejbjar.getRootFile().getName(); 125 String contextName = ejbName.substring(0, ejbName.length() - ".jar".length()); 126 warName = contextName + ".war"; 127 } 128 129 Application application = ejbjar.getApplication(); 130 WebApp web = new DummyWebApp(application, warName); 131 132 for (Iterator i = sds.iterator(); i.hasNext();) { 133 ServiceDesc sd = (ServiceDesc) i.next(); 134 135 WsEndpointDDModifier ddm = new WsEndpointDDModifier(web.getWebAppDoc()); 137 138 Generator g = gf.newGenerator(sd, ddm, null, ejbjar); 140 g.generate(); 141 g.compile(); 142 g.addFiles(web); 144 145 ContextDDModifier cddm = new ContextDDModifier(web.getContextDoc()); 147 WebJettyDDModifier wjddm = new WebJettyDDModifier(web.getWebJettyDoc()); 148 Document jonaswebservices = ejbjar.getJonasWebservicesDoc(); 149 SecurityGenerator sm = new SecurityGenerator (ejbjar.getJonasWebservicesDoc()); 150 sm.generate(ddm, cddm, wjddm); 151 152 153 } 154 application.addWebApp(new WebApp(save(gf.getConfiguration(), 156 "webapps" + File.separator + web.getName(), web)), ejbjar.getContextRoot()); 157 } 158 } 159 160 List ejbs = ejbjar.getEjbs(); 162 for (Iterator i = ejbs.iterator(); i.hasNext();) { 163 Ejb ejb = (Ejb) i.next(); 164 List refs = ejb.getServiceRefDescs(); 165 for (Iterator j = refs.iterator(); j.hasNext();) { 166 ServiceRefDesc ref = (ServiceRefDesc) j.next(); 167 168 WsClientDDModifier ddm = new WsClientDDModifier(ref.getServiceRefName(), jejbjar, ejb.getJonasBeanElement()); 170 171 Generator g = gf.newGenerator(ref, ddm, ejbjar); 173 g.generate(); 174 g.compile(); 175 g.addFiles(ejbjar); 177 } 178 } 179 180 return save(gf.getConfiguration(), "ejbjars" + File.separator + ejbjar.getRootFile().getName()); 181 182 } 183 } | Popular Tags |