KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > wsgen > modifier > EjbJarModifier


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2003-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EjbJarModifier.java,v 1.10 2005/07/18 23:53:31 mwringe Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas_ws.wsgen.modifier;
26
27 import java.io.File JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
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 JavaDoc;
51
52 /**
53  * Modify a given EjbJar.
54  *
55  * @author Guillaume Sauthier
56  */

57 public class EjbJarModifier extends ArchiveModifier {
58
59     /** modified ejbjar */
60     private EjbJar ejbjar = null;
61
62     /**
63      * Creates a new EjbJarModifier object.
64      *
65      * @param ejbjar EjbJar Archive
66      */

67     public EjbJarModifier(EjbJar ejbjar) {
68         super(ejbjar);
69         this.ejbjar = ejbjar;
70     }
71
72     /**
73      * modify the current EjbJar. If EjbJar is contained in not an application
74      * and have webservices endpoints, A DummyApplication is created and
75      * modification process launched against the newly created application. If
76      * EjbJar is contained in an application + webservices endpoints, a
77      * DummyWebApp is created to hold "facade" servlet managing SOAP processing.
78      *
79      * @return an EjbJar or an Application Archive
80      *
81      * @throws GenBaseException When generation or storing fails
82      */

83     public Archive modify() throws GenBaseException {
84
85         getLogger().log(BasicLevel.INFO, "Processing EjbJar " + ejbjar.getName());
86
87         GeneratorFactory gf = GeneratorFactory.getInstance();
88         Document JavaDoc jejbjar = ejbjar.getJonasEjbJarDoc();
89
90         // Webservices endpoint
91
List JavaDoc sds = ejbjar.getServiceDescs();
92
93         if (sds.size() != 0) {
94             if (ejbjar.getApplication() == null) {
95                 // we have webservices outside of an application
96

97                 /**
98                  * Process : - create a default Application - add EjbJar within -
99                  * return ApplicationModifier.modify()
100                  */

101                 String JavaDoc ejbName = ejbjar.getRootFile().getName();
102                 String JavaDoc 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                 // we have webservices inside of an application
112

113                 /**
114                  * Process : - create a default WebApp - add in Application -
115                  * iterate over the services - add files in web instead of
116                  * ejbjar
117                  */

118
119                 String JavaDoc warName = null;
120                 String JavaDoc war = ejbjar.getWarName();
121                 if (war != null) {
122                     warName = war;
123                 } else {
124                     String JavaDoc ejbName = ejbjar.getRootFile().getName();
125                     String JavaDoc 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 JavaDoc i = sds.iterator(); i.hasNext();) {
133                     ServiceDesc sd = (ServiceDesc) i.next();
134
135                     // create dd modifier
136
WsEndpointDDModifier ddm = new WsEndpointDDModifier(web.getWebAppDoc());
137
138                     // launch generation
139
Generator g = gf.newGenerator(sd, ddm, null, ejbjar);
140                     g.generate();
141                     g.compile();
142                     // add files in web archive
143
g.addFiles(web);
144
145                     //Now generate the security for the web app
146
ContextDDModifier cddm = new ContextDDModifier(web.getContextDoc());
147                     WebJettyDDModifier wjddm = new WebJettyDDModifier(web.getWebJettyDoc());
148                     Document JavaDoc jonaswebservices = ejbjar.getJonasWebservicesDoc();
149                     SecurityGenerator sm = new SecurityGenerator (ejbjar.getJonasWebservicesDoc());
150                     sm.generate(ddm, cddm, wjddm);
151
152
153                 }
154                 // save webapp
155
application.addWebApp(new WebApp(save(gf.getConfiguration(),
156                         "webapps" + File.separator + web.getName(), web)), ejbjar.getContextRoot());
157             }
158         }
159
160         // add client files
161
List JavaDoc ejbs = ejbjar.getEjbs();
162         for (Iterator JavaDoc i = ejbs.iterator(); i.hasNext();) {
163             Ejb ejb = (Ejb) i.next();
164             List JavaDoc refs = ejb.getServiceRefDescs();
165             for (Iterator JavaDoc j = refs.iterator(); j.hasNext();) {
166                 ServiceRefDesc ref = (ServiceRefDesc) j.next();
167
168                 // create dd modifier
169
WsClientDDModifier ddm = new WsClientDDModifier(ref.getServiceRefName(), jejbjar, ejb.getJonasBeanElement());
170
171                 // launch generation
172
Generator g = gf.newGenerator(ref, ddm, ejbjar);
173                 g.generate();
174                 g.compile();
175                 // add files in web archive
176
g.addFiles(ejbjar);
177             }
178         }
179
180         return save(gf.getConfiguration(), "ejbjars" + File.separator + ejbjar.getRootFile().getName());
181
182     }
183 }
Popular Tags