001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 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 1any 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: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: WebApp.java 5201 2004-07-29 12:19:56Z benoitf $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas_web.deployment.xml;
026:
027: import org.objectweb.jonas_lib.deployment.xml.AbsEnvironmentElement;
028: import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
029: import org.objectweb.jonas_lib.deployment.xml.JndiEnvRefsGroupXml;
030: import org.objectweb.jonas_lib.deployment.xml.SecurityRole;
031: import org.objectweb.jonas_lib.deployment.xml.TopLevelElement;
032:
033: /**
034: * This class defines the implementation of the element web-app.
035: * @author Florent Benoit
036: */
037: public class WebApp extends AbsEnvironmentElement implements
038: TopLevelElement, JndiEnvRefsGroupXml {
039:
040: /**
041: * List of servlet
042: */
043: private JLinkedList servletList = null;
044:
045: /**
046: * List of servlet-mapping
047: */
048: private JLinkedList servletMappingList = null;
049:
050: /**
051: * security-constraint
052: */
053: private JLinkedList securityConstraintList = null;
054:
055: /**
056: * security-role
057: */
058: private JLinkedList securityRoleList = null;
059:
060: /**
061: * Number of jsp-config
062: */
063: private int jspConfigNumber = 0;
064:
065: /**
066: * Number of login-config
067: */
068: private int loginConfigNumber = 0;
069:
070: /**
071: * Number of jsp-config
072: */
073: private int sessionConfigNumber = 0;
074:
075: /**
076: * Constructor : build a new WebApp object
077: */
078: public WebApp() {
079: super ();
080: servletList = new JLinkedList("servlet");
081: servletMappingList = new JLinkedList("servlet-mapping");
082: securityConstraintList = new JLinkedList("security-constraint");
083: securityRoleList = new JLinkedList("security-role");
084: }
085:
086: /**
087: * Add a new servlet element to this object
088: * @param servlet the servlet object
089: */
090: public void addServlet(Servlet servlet) {
091: servletList.add(servlet);
092: }
093:
094: /**
095: * Add a new servlet-mapping element to this object
096: * @param servletMapping the servlet-mapping object
097: */
098: public void addServletMapping(ServletMapping servletMapping) {
099: servletMappingList.add(servletMapping);
100: }
101:
102: /**
103: * Set the security-role
104: * @param securityRoleList securityRole
105: */
106: public void setSecurityRoleList(JLinkedList securityRoleList) {
107: this .securityRoleList = securityRoleList;
108: }
109:
110: /**
111: * Add a new security role element to this object
112: * @param securityRole security role object
113: */
114: public void addSecurityRole(SecurityRole securityRole) {
115: securityRoleList.add(securityRole);
116: }
117:
118: /**
119: * Set the security-constraint
120: * @param securityConstraintList securityConstraint
121: */
122: public void setSecurityConstraintList(
123: 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(
132: SecurityConstraint securityConstraint) {
133: securityConstraintList.add(securityConstraint);
134: }
135:
136: // Getters
137:
138: /**
139: * Gets the security-constraint
140: * @return the security-constraint
141: */
142: public JLinkedList getSecurityConstraintList() {
143: return securityConstraintList;
144: }
145:
146: /**
147: * Gets the security-role
148: * @return the security-role
149: */
150: public JLinkedList getSecurityRoleList() {
151: return securityRoleList;
152: }
153:
154: /**
155: * @return the list of all servlet elements
156: */
157: public JLinkedList getServletList() {
158: return servletList;
159: }
160:
161: /**
162: * @return the list of all servlet-mapping elements
163: */
164: public JLinkedList getServletMappingList() {
165: return servletMappingList;
166: }
167:
168: /**
169: * Count a new jsp config
170: */
171: public void newJspConfig() {
172: jspConfigNumber++;
173: }
174:
175: /**
176: * Count a new login-config
177: */
178: public void newLoginConfig() {
179: loginConfigNumber++;
180: }
181:
182: /**
183: * Count a new jsp config
184: */
185: public void newSessionConfig() {
186: sessionConfigNumber++;
187: }
188:
189: /**
190: * Represents this element by it's XML description.
191: * @param indent use this indent for prexifing XML representation.
192: * @return the XML description of this object.
193: */
194: public String toXML(int indent) {
195: StringBuffer sb = new StringBuffer();
196: sb.append(indent(indent));
197: sb.append("<web-app>\n");
198:
199: indent += 2;
200:
201: // display-name
202: sb.append(xmlElement(getDisplayName(), "display-name", indent));
203:
204: // servlet
205: sb.append(servletList.toXML(indent));
206:
207: // servlet-mapping
208: sb.append(servletMappingList.toXML(indent));
209:
210: // security-constraint
211: sb.append(securityConstraintList.toXML(indent));
212:
213: // security-role
214: sb.append(securityRoleList.toXML(indent));
215:
216: // resource-env-ref
217: sb.append(getResourceEnvRefList().toXML(indent));
218:
219: // resource-ref
220: sb.append(getResourceRefList().toXML(indent));
221:
222: // env-entry
223: sb.append(getEnvEntryList().toXML(indent));
224:
225: // ejb-ref
226: sb.append(getEjbRefList().toXML(indent));
227:
228: // ejb-local-ref
229: sb.append(getEjbLocalRefList().toXML(indent));
230:
231: // service-ref
232: sb.append(getServiceRefList().toXML(indent));
233:
234: // message-destination-ref
235: sb.append(getMessageDestinationRefList().toXML(indent));
236: indent -= 2;
237: sb.append(indent(indent));
238: sb.append("</web-app>");
239:
240: return sb.toString();
241: }
242:
243: /**
244: * @return the jspConfigNumber.
245: */
246: public int getJspConfigNumber() {
247: return jspConfigNumber;
248: }
249:
250: /**
251: * @return the loginConfigNumber.
252: */
253: public int getLoginConfigNumber() {
254: return loginConfigNumber;
255: }
256:
257: /**
258: * @return the sessionConfigNumber.
259: */
260: public int getSessionConfigNumber() {
261: return sessionConfigNumber;
262: }
263: }
|