001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: WebAppModifier.java 9457 2006-08-24 12:58:41Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ws.wsgen.modifier;
025:
026: import java.io.File;
027: import java.util.Iterator;
028: import java.util.List;
029: import java.util.jar.Attributes;
030:
031: import org.w3c.dom.Document;
032: import org.w3c.dom.Element;
033:
034: import org.objectweb.jonas_lib.genbase.GenBaseException;
035: import org.objectweb.jonas_lib.genbase.archive.Archive;
036: import org.objectweb.jonas_lib.genbase.archive.WebApp;
037: import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier;
038: import org.objectweb.jonas_lib.version.Version;
039:
040: import org.objectweb.jonas_ws.deployment.api.ServiceDesc;
041: import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
042: import org.objectweb.jonas_ws.wsgen.ddmodifier.ContextDDModifier;
043: import org.objectweb.jonas_ws.wsgen.ddmodifier.WebJettyDDModifier;
044: import org.objectweb.jonas_ws.wsgen.ddmodifier.WebServicesDDModifier;
045: import org.objectweb.jonas_ws.wsgen.ddmodifier.WsClientDDModifier;
046: import org.objectweb.jonas_ws.wsgen.ddmodifier.WsEndpointDDModifier;
047: import org.objectweb.jonas_ws.wsgen.generator.Generator;
048: import org.objectweb.jonas_ws.wsgen.generator.GeneratorFactory;
049: import org.objectweb.jonas_ws.wsgen.generator.SecurityGenerator;
050:
051: import org.objectweb.util.monolog.api.BasicLevel;
052:
053: /**
054: * Modify a given WebApp.
055: *
056: * @author Guillaume Sauthier
057: */
058: public class WebAppModifier extends ArchiveModifier {
059:
060: /** webapp */
061: private WebApp web;
062:
063: /**
064: * Creates a new WebAppModifier
065: *
066: * @param webapp
067: * the WebApp J2EE archive
068: */
069: public WebAppModifier(WebApp webapp) {
070: super (webapp);
071: web = webapp;
072: }
073:
074: /**
075: * Modify the current archive and return a modified archive.
076: *
077: * @return a modified archive.
078: *
079: * @throws GenBaseException
080: * When modification fails
081: */
082: public Archive modify() throws GenBaseException {
083:
084: getLogger().log(BasicLevel.INFO,
085: "Processing WebApp " + web.getName());
086:
087: // Update MANIFEST with Version Number
088: // used to say if WsGen has already been applied to this Module
089: Attributes main = this .web.getManifest().getMainAttributes();
090: main.put(new Attributes.Name(
091: WsGenModifierConstants.WSGEN_JONAS_VERSION_ATTR),
092: Version.getNumber());
093:
094: GeneratorFactory gf = GeneratorFactory.getInstance();
095: Document jwebapp = web.getJonasWebAppDoc();
096: Document webapp = web.getWebAppDoc();
097: Document webservices = web.getWebservicesDoc();
098: Document jonasWebservices = web.getJonasWebservicesDoc();
099:
100: List refs = web.getServiceRefDescs();
101:
102: for (Iterator i = refs.iterator(); i.hasNext();) {
103: ServiceRefDesc ref = (ServiceRefDesc) i.next();
104:
105: // create dd modifier
106: Element base = null;
107: if (jwebapp != null) {
108: base = jwebapp.getDocumentElement();
109: }
110: WsClientDDModifier ddm = new WsClientDDModifier(ref
111: .getServiceRefName(), jwebapp, base);
112:
113: // launch generation
114: Generator g = gf.newGenerator(ref, ddm, web);
115: g.generate();
116: g.compile();
117:
118: // add files in web archive
119: g.addFiles(web);
120:
121: // update the Document if it was created
122: // in the meantime
123: jwebapp = ddm.getDocument();
124:
125: }
126:
127: // create dd modifier
128: WsEndpointDDModifier ddm = new WsEndpointDDModifier(webapp);
129: WebServicesDDModifier wsddm = null;
130: if (webservices != null) {
131: wsddm = new WebServicesDDModifier(webservices);
132: }
133:
134: List sds = web.getServiceDescs();
135:
136: for (Iterator i = sds.iterator(); i.hasNext();) {
137: ServiceDesc sd = (ServiceDesc) i.next();
138:
139: // launch generation
140: Generator g = gf.newGenerator(sd, ddm, wsddm, web);
141: g.generate();
142: g.compile();
143:
144: // add files in web archive
145: g.addFiles(web);
146:
147: //Now generate the security for the web app
148: Document context = web.getContextDoc();
149: if (context == null) {
150: context = web.newContextDoc();
151: }
152: ContextDDModifier cddm = new ContextDDModifier(context);
153: Document webJetty = web.getWebJettyDoc();
154: if (webJetty == null) {
155: webJetty = web.newWebJettyDoc();
156: }
157: WebJettyDDModifier wjddm = new WebJettyDDModifier(webJetty);
158: SecurityGenerator sm = new SecurityGenerator(
159: jonasWebservices);
160: sm.generate(ddm, cddm, wjddm);
161:
162: }
163:
164: return save(gf.getConfiguration(), "webapps" + File.separator
165: + web.getName());
166: }
167: }
|