KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_web > deployment > xml > WebApp


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 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 1any 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  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: WebApp.java,v 1.6 2004/07/29 12:19:56 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_web.deployment.xml;
28
29 import org.objectweb.jonas_lib.deployment.xml.AbsEnvironmentElement;
30 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
31 import org.objectweb.jonas_lib.deployment.xml.JndiEnvRefsGroupXml;
32 import org.objectweb.jonas_lib.deployment.xml.SecurityRole;
33 import org.objectweb.jonas_lib.deployment.xml.TopLevelElement;
34
35 /**
36  * This class defines the implementation of the element web-app.
37  * @author Florent Benoit
38  */

39 public class WebApp extends AbsEnvironmentElement implements TopLevelElement, JndiEnvRefsGroupXml {
40
41     /**
42      * List of servlet
43      */

44     private JLinkedList servletList = null;
45
46     /**
47      * List of servlet-mapping
48      */

49     private JLinkedList servletMappingList = null;
50
51     /**
52      * security-constraint
53      */

54     private JLinkedList securityConstraintList = null;
55
56     /**
57      * security-role
58      */

59     private JLinkedList securityRoleList = null;
60
61     /**
62      * Number of jsp-config
63      */

64     private int jspConfigNumber = 0;
65
66     /**
67      * Number of login-config
68      */

69     private int loginConfigNumber = 0;
70
71     /**
72      * Number of jsp-config
73      */

74     private int sessionConfigNumber = 0;
75
76     /**
77      * Constructor : build a new WebApp object
78      */

79     public WebApp() {
80         super();
81         servletList = new JLinkedList("servlet");
82         servletMappingList = new JLinkedList("servlet-mapping");
83         securityConstraintList = new JLinkedList("security-constraint");
84         securityRoleList = new JLinkedList("security-role");
85     }
86
87     /**
88      * Add a new servlet element to this object
89      * @param servlet the servlet object
90      */

91     public void addServlet(Servlet servlet) {
92         servletList.add(servlet);
93     }
94
95     /**
96      * Add a new servlet-mapping element to this object
97      * @param servletMapping the servlet-mapping object
98      */

99     public void addServletMapping(ServletMapping servletMapping) {
100         servletMappingList.add(servletMapping);
101     }
102
103     /**
104      * Set the security-role
105      * @param securityRoleList securityRole
106      */

107     public void setSecurityRoleList(JLinkedList securityRoleList) {
108         this.securityRoleList = securityRoleList;
109     }
110
111     /**
112      * Add a new security role element to this object
113      * @param securityRole security role object
114      */

115     public void addSecurityRole(SecurityRole securityRole) {
116         securityRoleList.add(securityRole);
117     }
118
119     /**
120      * Set the security-constraint
121      * @param securityConstraintList securityConstraint
122      */

123     public void setSecurityConstraintList(JLinkedList securityConstraintList) {
124         this.securityConstraintList = securityConstraintList;
125     }
126
127     /**
128      * Add a new security constraint element to this object
129      * @param securityConstraint security constraint object
130      */

131     public void addSecurityConstraint(SecurityConstraint securityConstraint) {
132         securityConstraintList.add(securityConstraint);
133     }
134
135     // Getters
136

137     /**
138      * Gets the security-constraint
139      * @return the security-constraint
140      */

141     public JLinkedList getSecurityConstraintList() {
142         return securityConstraintList;
143     }
144
145     /**
146      * Gets the security-role
147      * @return the security-role
148      */

149     public JLinkedList getSecurityRoleList() {
150         return securityRoleList;
151     }
152
153     /**
154      * @return the list of all servlet elements
155      */

156     public JLinkedList getServletList() {
157         return servletList;
158     }
159
160     /**
161      * @return the list of all servlet-mapping elements
162      */

163     public JLinkedList getServletMappingList() {
164         return servletMappingList;
165     }
166
167     /**
168      * Count a new jsp config
169      */

170     public void newJspConfig() {
171         jspConfigNumber++;
172     }
173
174     /**
175      * Count a new login-config
176      */

177     public void newLoginConfig() {
178         loginConfigNumber++;
179     }
180
181     /**
182      * Count a new jsp config
183      */

184     public void newSessionConfig() {
185         sessionConfigNumber++;
186     }
187
188     /**
189      * Represents this element by it's XML description.
190      * @param indent use this indent for prexifing XML representation.
191      * @return the XML description of this object.
192      */

193     public String JavaDoc toXML(int indent) {
194         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
195         sb.append(indent(indent));
196         sb.append("<web-app>\n");
197
198         indent += 2;
199
200         // display-name
201
sb.append(xmlElement(getDisplayName(), "display-name", indent));
202
203         // servlet
204
sb.append(servletList.toXML(indent));
205
206         // servlet-mapping
207
sb.append(servletMappingList.toXML(indent));
208
209         // security-constraint
210
sb.append(securityConstraintList.toXML(indent));
211
212         // security-role
213
sb.append(securityRoleList.toXML(indent));
214
215         // resource-env-ref
216
sb.append(getResourceEnvRefList().toXML(indent));
217
218         // resource-ref
219
sb.append(getResourceRefList().toXML(indent));
220
221         // env-entry
222
sb.append(getEnvEntryList().toXML(indent));
223
224         // ejb-ref
225
sb.append(getEjbRefList().toXML(indent));
226
227         // ejb-local-ref
228
sb.append(getEjbLocalRefList().toXML(indent));
229
230         // service-ref
231
sb.append(getServiceRefList().toXML(indent));
232
233         // message-destination-ref
234
sb.append(getMessageDestinationRefList().toXML(indent));
235         indent -= 2;
236         sb.append(indent(indent));
237         sb.append("</web-app>");
238
239         return sb.toString();
240     }
241
242     /**
243      * @return the jspConfigNumber.
244      */

245     public int getJspConfigNumber() {
246         return jspConfigNumber;
247     }
248
249     /**
250      * @return the loginConfigNumber.
251      */

252     public int getLoginConfigNumber() {
253         return loginConfigNumber;
254     }
255
256     /**
257      * @return the sessionConfigNumber.
258      */

259     public int getSessionConfigNumber() {
260         return sessionConfigNumber;
261     }
262 }
Popular Tags