KickJava   Java API By Example, From Geeks To Geeks.

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


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: WebAppModifier.java,v 1.9 2005/01/21 13:35:50 pelletib Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ws.wsgen.modifier;
27
28 import java.io.File JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31
32 import org.w3c.dom.Document JavaDoc;
33 import org.w3c.dom.Element JavaDoc;
34
35 import org.objectweb.jonas_lib.genbase.GenBaseException;
36 import org.objectweb.jonas_lib.genbase.archive.Archive;
37 import org.objectweb.jonas_lib.genbase.archive.WebApp;
38 import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier;
39
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.WebServicesDDModifier;
43 import org.objectweb.jonas_ws.wsgen.ddmodifier.WsClientDDModifier;
44 import org.objectweb.jonas_ws.wsgen.ddmodifier.WsEndpointDDModifier;
45 import org.objectweb.jonas_ws.wsgen.generator.Generator;
46 import org.objectweb.jonas_ws.wsgen.generator.GeneratorFactory;
47
48 import org.objectweb.util.monolog.api.BasicLevel;
49
50 /**
51  * Modify a given WebApp.
52  *
53  * @author Guillaume Sauthier
54  */

55 public class WebAppModifier extends ArchiveModifier {
56
57     /** webapp */
58     private WebApp web;
59
60     /**
61      * Creates a new WebAppModifier
62      *
63      * @param webapp
64      * the WebApp J2EE archive
65      */

66     public WebAppModifier(WebApp webapp) {
67         super(webapp);
68         web = webapp;
69     }
70
71     /**
72      * Modify the current archive and return a modified archive.
73      *
74      * @return a modified archive.
75      *
76      * @throws GenBaseException
77      * When modification fails
78      */

79     public Archive modify() throws GenBaseException {
80
81         getLogger().log(BasicLevel.INFO, "Processing WebApp " + web.getName());
82
83         GeneratorFactory gf = GeneratorFactory.getInstance();
84         Document JavaDoc jwebapp = web.getJonasWebAppDoc();
85         Document JavaDoc webapp = web.getWebAppDoc();
86         Document JavaDoc webservices = web.getWebservicesDoc();
87
88         List JavaDoc refs = web.getServiceRefDescs();
89
90         for (Iterator JavaDoc i = refs.iterator(); i.hasNext();) {
91             ServiceRefDesc ref = (ServiceRefDesc) i.next();
92
93             // create dd modifier
94
Element JavaDoc base = null;
95             if (jwebapp != null) {
96                 base = jwebapp.getDocumentElement();
97             }
98             WsClientDDModifier ddm = new WsClientDDModifier(ref.getServiceRefName(), jwebapp, base);
99
100             // launch generation
101
Generator g = gf.newGenerator(ref, ddm, web);
102             g.generate();
103             g.compile();
104
105             // add files in web archive
106
g.addFiles(web);
107         }
108
109         // create dd modifier
110
WsEndpointDDModifier ddm = new WsEndpointDDModifier(webapp);
111         WebServicesDDModifier wsddm = null;
112         if (webservices != null) {
113             wsddm = new WebServicesDDModifier(webservices);
114         }
115
116         List JavaDoc sds = web.getServiceDescs();
117
118         for (Iterator JavaDoc i = sds.iterator(); i.hasNext();) {
119             ServiceDesc sd = (ServiceDesc) i.next();
120
121             // launch generation
122
Generator g = gf.newGenerator(sd, ddm, wsddm, web);
123             g.generate();
124             g.compile();
125
126             // add files in web archive
127
g.addFiles(web);
128
129         }
130
131         return save(gf.getConfiguration(), "webapps" + File.separator
132                 + web.getName());
133     }
134 }
Popular Tags