KickJava   Java API By Example, From Geeks To Geeks.

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


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: Servlet.java,v 1.3 2004/05/25 14:26:34 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_web.deployment.xml;
28
29 import org.objectweb.jonas_lib.deployment.xml.AbsElement;
30 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
31 import org.objectweb.jonas_lib.deployment.xml.RunAs;
32 import org.objectweb.jonas_lib.deployment.xml.SecurityRoleRef;
33
34 /**
35  * This class defines the implementation of the element servlet
36  * <b> Don't take into account nested element :
37  * icon, display-name, description, init-param, load-on-startup, run-as and security-role-ref
38  * </b> Which are optional (web container implentation will parse it)
39  * @author Florent Benoit
40  */

41 public class Servlet extends AbsElement {
42
43     /**
44      * Name of the servlet
45      */

46     private String JavaDoc servletName = null;
47
48     /**
49      * Servlet-class
50      */

51     private String JavaDoc servletClass = null;
52
53     /**
54      * Jsp-file
55      */

56     private String JavaDoc jspFile = null;
57
58     /**
59      * security-role-ref
60      */

61     private JLinkedList securityRoleRefList = null;
62
63     /**
64      * run-as
65      */

66     private RunAs runAs = null;
67
68
69     /**
70      * Constructor
71      */

72     public Servlet() {
73         super();
74         securityRoleRefList = new JLinkedList("security-role-ref");
75     }
76
77     // Setters
78

79
80     /**
81      * Sets the name of the servlet
82      * @param servletName name of the servlet
83      */

84     public void setServletName(String JavaDoc servletName) {
85         this.servletName = servletName;
86     }
87
88
89     /**
90      * Sets the class of the servlet
91      * @param servletClass class of the servlet
92      */

93     public void setServletClass(String JavaDoc servletClass) {
94         this.servletClass = servletClass;
95     }
96
97     /**
98      * Sets the jsp-file of the servlet
99      * @param jspFile jsp-file of the servlet
100      */

101     public void setJspFile(String JavaDoc jspFile) {
102         this.jspFile = jspFile;
103     }
104
105     /**
106      * Add a new security-role-ref element to this object
107      * @param securityRoleRef security-role-ref
108      */

109     public void addSecurityRoleRef(SecurityRoleRef securityRoleRef) {
110         securityRoleRefList.add(securityRoleRef);
111     }
112
113     /**
114      * Set the security-role-ref
115      * @param securityRoleRefList securityRoleRef
116      */

117     public void setSecurityRoleRefList(JLinkedList securityRoleRefList) {
118         this.securityRoleRefList = securityRoleRefList;
119     }
120
121     /**
122      * Set the run-as
123      * @param runAs runAs
124      */

125     public void setRunAs(RunAs runAs) {
126         this.runAs = runAs;
127     }
128
129     // Getters
130

131     /**
132      * @return the name of the servlet
133      */

134     public String JavaDoc getServletName() {
135         return servletName;
136     }
137
138     /**
139      * @return the class of the servlet
140      */

141     public String JavaDoc getServletClass() {
142         return servletClass;
143     }
144
145     /**
146      * @return the jsp-file of the servlet
147      */

148     public String JavaDoc getJspFile() {
149         return jspFile;
150     }
151
152     /**
153      * Gets the security-role-ref
154      * @return the security-role-ref
155      */

156     public JLinkedList getSecurityRoleRefList() {
157         return securityRoleRefList;
158     }
159
160
161     /**
162      * Gets the run-as
163      * @return the run-as
164      */

165     public RunAs getRunAs() {
166         return runAs;
167     }
168
169     /**
170      * Represents this element by it's XML description.
171      * @param indent use this indent for prexifing XML representation.
172      * @return the XML description of this object.
173      */

174     public String JavaDoc toXML(int indent) {
175         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
176         sb.append(indent(indent));
177         sb.append("<servlet>\n");
178
179         indent += 2;
180
181         // servlet-name
182
sb.append(xmlElement(servletName, "servlet-name", indent));
183
184         // servlet-class or jsp-file
185
sb.append(xmlElement(servletClass, "servlet-class", indent));
186         sb.append(xmlElement(jspFile, "jsp-file", indent));
187
188         // run-as
189
if (runAs != null) {
190             sb.append(runAs.toXML(indent));
191         }
192
193         // security-role-ref
194
if (securityRoleRefList != null) {
195             sb.append(securityRoleRefList.toXML(indent));
196         }
197
198         indent -= 2;
199         sb.append(indent(indent));
200         sb.append("</servlet>\n");
201
202         return sb.toString();
203     }
204 }
205
Popular Tags