1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.tomcat.util.descriptor.web;
18
19 import java.io.Serializable;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.Map;
23 import java.util.Set;
24
25 import org.apache.tomcat.util.res.StringManager;
26
27
28 /**
29  * Representation of a servlet definition for a web application, as represented
30  * in a <code>&lt;servlet&gt;</code> element in the deployment descriptor.
31  */

32
33 public class ServletDef implements Serializable {
34
35     private static final long serialVersionUID = 1L;
36
37     private static final StringManager sm =
38         StringManager.getManager(Constants.PACKAGE_NAME);
39
40     // ------------------------------------------------------------- Properties
41
42
43     /**
44      * The description of this servlet.
45      */

46     private String description = null;
47
48     public String getDescription() {
49         return this.description;
50     }
51
52     public void setDescription(String description) {
53         this.description = description;
54     }
55
56
57     /**
58      * The display name of this servlet.
59      */

60     private String displayName = null;
61
62     public String getDisplayName() {
63         return this.displayName;
64     }
65
66     public void setDisplayName(String displayName) {
67         this.displayName = displayName;
68     }
69
70
71     /**
72      * The small icon associated with this servlet.
73      */

74     private String smallIcon = null;
75
76     public String getSmallIcon() {
77         return this.smallIcon;
78     }
79
80     public void setSmallIcon(String smallIcon) {
81         this.smallIcon = smallIcon;
82     }
83
84     /**
85      * The large icon associated with this servlet.
86      */

87     private String largeIcon = null;
88
89     public String getLargeIcon() {
90         return this.largeIcon;
91     }
92
93     public void setLargeIcon(String largeIcon) {
94         this.largeIcon = largeIcon;
95     }
96
97
98     /**
99      * The name of this servlet, which must be unique among the servlets
100      * defined for a particular web application.
101      */

102     private String servletName = null;
103
104     public String getServletName() {
105         return this.servletName;
106     }
107
108     public void setServletName(String servletName) {
109         if (servletName == null || servletName.equals("")) {
110             throw new IllegalArgumentException(
111                     sm.getString("servletDef.invalidServletName", servletName));
112         }
113         this.servletName = servletName;
114     }
115
116
117     /**
118      * The fully qualified name of the Java class that implements this servlet.
119      */

120     private String servletClass = null;
121
122     public String getServletClass() {
123         return this.servletClass;
124     }
125
126     public void setServletClass(String servletClass) {
127         this.servletClass = servletClass;
128     }
129
130
131     /**
132      * The name of the JSP file to which this servlet definition applies
133      */

134     private String jspFile = null;
135
136     public String getJspFile() {
137         return this.jspFile;
138     }
139
140     public void setJspFile(String jspFile) {
141         this.jspFile = jspFile;
142     }
143
144
145     /**
146      * The set of initialization parameters for this servlet, keyed by
147      * parameter name.
148      */

149     private final Map<String, String> parameters = new HashMap<>();
150
151     public Map<String, String> getParameterMap() {
152         return this.parameters;
153     }
154
155     /**
156      * Add an initialization parameter to the set of parameters associated
157      * with this servlet.
158      *
159      * @param name The initialisation parameter name
160      * @param value The initialisation parameter value
161      */

162     public void addInitParameter(String name, String value) {
163
164         if (parameters.containsKey(name)) {
165             // The spec does not define this but the TCK expects the first
166             // definition to take precedence
167             return;
168         }
169         parameters.put(name, value);
170
171     }
172
173     /**
174      * The load-on-startup order for this servlet
175      */

176     private Integer loadOnStartup = null;
177
178     public Integer getLoadOnStartup() {
179         return this.loadOnStartup;
180     }
181
182     public void setLoadOnStartup(String loadOnStartup) {
183         this.loadOnStartup = Integer.valueOf(loadOnStartup);
184     }
185
186
187     /**
188      * The run-as configuration for this servlet
189      */

190     private String runAs = null;
191
192     public String getRunAs() {
193         return this.runAs;
194     }
195
196     public void setRunAs(String runAs) {
197         this.runAs = runAs;
198     }
199
200
201     /**
202      * The set of security role references for this servlet
203      */

204     private final Set<SecurityRoleRef> securityRoleRefs = new HashSet<>();
205
206     public Set<SecurityRoleRef> getSecurityRoleRefs() {
207         return this.securityRoleRefs;
208     }
209
210     /**
211      * Add a security-role-ref to the set of security-role-refs associated
212      * with this servlet.
213      * @param securityRoleRef The security role
214      */

215     public void addSecurityRoleRef(SecurityRoleRef securityRoleRef) {
216         securityRoleRefs.add(securityRoleRef);
217     }
218
219     /**
220      * The multipart configuration, if any, for this servlet
221      */

222     private MultipartDef multipartDef = null;
223
224     public MultipartDef getMultipartDef() {
225         return this.multipartDef;
226     }
227
228     public void setMultipartDef(MultipartDef multipartDef) {
229         this.multipartDef = multipartDef;
230     }
231
232
233     /**
234      * Does this servlet support async.
235      */

236     private Boolean asyncSupported = null;
237
238     public Boolean getAsyncSupported() {
239         return this.asyncSupported;
240     }
241
242     public void setAsyncSupported(String asyncSupported) {
243         this.asyncSupported = Boolean.valueOf(asyncSupported);
244     }
245
246
247     /**
248      * Is this servlet enabled.
249      */

250     private Boolean enabled = null;
251
252     public Boolean getEnabled() {
253         return this.enabled;
254     }
255
256     public void setEnabled(String enabled) {
257         this.enabled = Boolean.valueOf(enabled);
258     }
259
260
261     /**
262      * Can this ServletDef be overridden by an SCI?
263      */

264     private boolean overridable = false;
265
266     public boolean isOverridable() {
267         return overridable;
268     }
269
270     public void setOverridable(boolean overridable) {
271         this.overridable = overridable;
272     }
273
274 }
275