KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > om > servlet > impl > ServletDefinitionImpl


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

16 /*
17
18  */

19
20 package org.apache.pluto.portalImpl.om.servlet.impl;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Locale JavaDoc;
24
25 import javax.servlet.RequestDispatcher JavaDoc;
26 import javax.servlet.ServletContext JavaDoc;
27
28 import org.apache.pluto.om.common.Description;
29 import org.apache.pluto.om.common.DescriptionSet;
30 import org.apache.pluto.om.common.DisplayName;
31 import org.apache.pluto.om.common.DisplayNameSet;
32 import org.apache.pluto.om.common.ObjectID;
33 import org.apache.pluto.om.common.ParameterSet;
34 import org.apache.pluto.om.common.SecurityRoleRefSet;
35 import org.apache.pluto.om.servlet.ServletDefinition;
36 import org.apache.pluto.om.servlet.ServletDefinitionCtrl;
37 import org.apache.pluto.om.servlet.WebApplicationDefinition;
38 import org.apache.pluto.portalImpl.om.common.Support;
39 import org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl;
40 import org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl;
41 import org.apache.pluto.portalImpl.services.log.Log;
42 import org.apache.pluto.util.StringUtils;
43
44 public class ServletDefinitionImpl
45 implements ServletDefinition, ServletDefinitionCtrl, java.io.Serializable JavaDoc, Support {
46
47     private DescriptionSet descriptions = new org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl();
48     private DisplayNameSet displayNames = new org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl();
49
50     // not used variables - only for castor
51
public String JavaDoc icon = null;
52     private String JavaDoc id = "";
53     private ParameterSet initParams = new org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl();
54     private SecurityRoleRefSet initSecurityRoleRefs = new org.apache.pluto.portalImpl.om.common.impl.SecurityRoleRefSetImpl();
55     public String JavaDoc jspFile = null;
56     public String JavaDoc loadOnStartup = null;
57     private ObjectID objectId = null;
58     public String JavaDoc securityRoleRef = null;
59     private String JavaDoc servletClass = null;
60     private ServletMappingImpl servletMapping = null;
61     private String JavaDoc servletName = null;
62     private long available = 0;
63
64     private WebApplicationDefinition webApplication = null;
65
66     // ServletDefinition implementation.
67

68     public ObjectID getId()
69     {
70         if (objectId==null) {
71             objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(id);
72         }
73         return objectId;
74     }
75
76     public String JavaDoc getServletName()
77     {
78         return servletName;
79     }
80
81     public DisplayName getDisplayName(Locale JavaDoc locale)
82     {
83         return displayNames.get(locale);
84     }
85
86     /* (non-Javadoc)
87      * @see org.apache.pluto.om.servlet.ServletDefinition#getDescription(Locale)
88      */

89     public Description getDescription(Locale JavaDoc locale) {
90         return descriptions.get(locale);
91     }
92
93     public String JavaDoc getServletClass()
94     {
95         return servletClass;
96     }
97
98     public ParameterSet getInitParameterSet()
99     {
100         return initParams;
101     }
102
103     public WebApplicationDefinition getWebApplicationDefinition()
104     {
105         return webApplication;
106     }
107
108     public RequestDispatcher JavaDoc getRequestDispatcher(ServletContext JavaDoc servletContext)
109     {
110         ServletContext JavaDoc newContext = webApplication.getServletContext(servletContext);
111         if (newContext==null) {
112             Log.error("ServletContext '"+((WebApplicationDefinitionImpl)webApplication).getContextRoot()+"' not found!");
113             return null;
114         }
115         if (Log.isDebugEnabled()) {
116             Log.debug("Looking up RequestDispatcher for servlet mapping "+servletMapping.getUrlPattern());
117         }
118         return newContext.getRequestDispatcher(servletMapping.getUrlPattern());
119     }
120
121     public long getAvailable() {
122         return available;
123     }
124
125     public boolean isUnavailable() {
126         if (available == 0) {
127             return false;
128         } else if (available <= System.currentTimeMillis()) {
129             available = 0;
130             return false;
131         } else {
132             return true;
133         }
134     }
135
136     // Support implementation.
137

138     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc
139     {
140         setServletMapping((ServletMappingImpl)parameter);
141     }
142
143
144     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc
145     {
146         ((Support)descriptions).postLoad(parameter);
147         ((Support)displayNames).postLoad(parameter);
148     }
149     public void postStore(Object JavaDoc parameter) throws Exception JavaDoc
150     {
151     }
152     public void preBuild(Object JavaDoc parameter) throws Exception JavaDoc
153     {
154         setWebApplicationDefinition((WebApplicationDefinition)parameter);
155     }
156     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc
157     {
158     }
159
160     // additional methods.
161

162     public String JavaDoc getCastorId() {
163         if (id.length() > 0)
164             return getId().toString();
165         else
166             return null;
167     }
168
169     public Collection JavaDoc getCastorInitParams()
170     {
171         return(org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams;
172     }
173
174     public SecurityRoleRefSet getCastorInitSecurityRoleRefs()
175     {
176         return initSecurityRoleRefs;
177     }
178
179     public Collection JavaDoc getCastorDisplayNames()
180     {
181         return(DisplayNameSetImpl)displayNames;
182     }
183
184     public Collection JavaDoc getCastorDescriptions()
185     {
186         return(DescriptionSetImpl)descriptions;
187     }
188
189     public Collection JavaDoc getDescriptions()
190     {
191         return(DescriptionSetImpl)descriptions;
192     }
193
194
195
196     public SecurityRoleRefSet getInitSecurityRoleRefSet()
197     {
198         return initSecurityRoleRefs;
199     }
200
201
202
203     public String JavaDoc getJspFile()
204     {
205         return jspFile;
206     }
207
208
209     public void setCastorId(String JavaDoc id) {
210         setId(id);
211     }
212
213     public void setCastorInitSecurityRoleRefs(SecurityRoleRefSet castorInitSecurityRoleRefs)
214     {
215         this.initSecurityRoleRefs = castorInitSecurityRoleRefs;
216     }
217
218     public void setCastorDisplayNames(DisplayNameSet castorDisplayNames)
219     {
220         this.displayNames = castorDisplayNames;
221     }
222
223     public void setCastorDescriptions(DescriptionSet castorDescriptions)
224     {
225         this.descriptions = castorDescriptions;
226     }
227
228     public void setDisplayNames(DisplayNameSet displayNames)
229     {
230         this.displayNames = displayNames;
231     }
232
233     public void setDescriptions(DescriptionSet descriptions) {
234         this.descriptions = descriptions;
235     }
236
237     public void setId(String JavaDoc id)
238     {
239         this.id = id;
240         objectId = null;
241     }
242
243     public void setServletClass(String JavaDoc servletClass)
244     {
245         this.servletClass = servletClass;
246     }
247
248     public void setAvailable(long available) {
249         if (available > System.currentTimeMillis()) {
250             this.available = available;
251         } else {
252             this.available = 0;
253         }
254     }
255
256     public void setJspFile(String JavaDoc jspFile)
257     {
258         this.jspFile = jspFile;
259     }
260
261     protected void setServletMapping(ServletMappingImpl servletMapping)
262     {
263         this.servletMapping = servletMapping;
264     }
265
266     public void setServletName(String JavaDoc servletName)
267     {
268         this.servletName = servletName;
269     }
270
271     protected void setWebApplicationDefinition(WebApplicationDefinition webApplication)
272     {
273         this.webApplication = webApplication;
274     }
275
276     // internal methods used for debugging purposes only
277

278     public String JavaDoc toString()
279     {
280         return toString(0);
281     }
282
283     public String JavaDoc toString(int indent)
284     {
285         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
286         StringUtils.newLine(buffer,indent);
287         buffer.append(getClass().toString()); buffer.append(":");
288         StringUtils.newLine(buffer,indent);
289         buffer.append("{");
290         StringUtils.newLine(buffer,indent);
291         buffer.append("id='"); buffer.append(id); buffer.append("'");
292         StringUtils.newLine(buffer,indent);
293         buffer.append("servletName='"); buffer.append(servletName); buffer.append("'");
294         StringUtils.newLine(buffer,indent);
295         buffer.append(((DescriptionSetImpl)descriptions).toString(indent));
296
297         StringUtils.newLine(buffer,indent);
298         buffer.append(((DisplayNameSetImpl)displayNames).toString(indent));
299
300         if (servletClass!=null) {
301             buffer.append("servletClass='"); buffer.append(servletClass); buffer.append("'");
302         } else if (jspFile!=null) {
303             buffer.append("jspFile='"); buffer.append(jspFile); buffer.append("'");
304         }
305         StringUtils.newLine(buffer,indent);
306         buffer.append(((org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams).toString(indent));
307
308         StringUtils.newLine(buffer,indent);
309         buffer.append(((org.apache.pluto.portalImpl.om.common.impl.SecurityRoleRefSetImpl)initSecurityRoleRefs).toString(indent));
310
311         if (servletMapping!=null) {
312             StringUtils.newLine(buffer,indent);
313             buffer.append("Linked ServletMapping:");
314             buffer.append(servletMapping.toString(indent+2));
315         }
316         StringUtils.newLine(buffer,indent);
317         buffer.append("}");
318         return buffer.toString();
319     }
320
321 }
322
Popular Tags