KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > pluto > om > ServletDefinitionImpl


1 /*
2  * Copyright 2004,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 package org.apache.cocoon.portal.pluto.om;
17
18 import java.util.Collection JavaDoc;
19 import java.util.Locale JavaDoc;
20
21 import javax.servlet.RequestDispatcher JavaDoc;
22 import javax.servlet.ServletContext JavaDoc;
23
24 import org.apache.pluto.om.common.Description;
25 import org.apache.pluto.om.common.DescriptionSet;
26 import org.apache.pluto.om.common.DisplayName;
27 import org.apache.pluto.om.common.DisplayNameSet;
28 import org.apache.pluto.om.common.ObjectID;
29 import org.apache.pluto.om.common.ParameterSet;
30 import org.apache.pluto.om.common.SecurityRoleRefSet;
31 import org.apache.pluto.om.servlet.ServletDefinition;
32 import org.apache.pluto.om.servlet.ServletDefinitionCtrl;
33 import org.apache.pluto.om.servlet.WebApplicationDefinition;
34 import org.apache.cocoon.portal.pluto.om.common.ParameterSetImpl;
35 import org.apache.cocoon.portal.pluto.om.common.SecurityRoleRefSetImpl;
36 import org.apache.cocoon.portal.pluto.om.common.Support;
37 import org.apache.cocoon.portal.pluto.om.common.DescriptionSetImpl;
38 import org.apache.cocoon.portal.pluto.om.common.DisplayNameSetImpl;
39
40 /**
41  *
42  *
43  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
44  *
45  * @version CVS $Id: ServletDefinitionImpl.java 123407 2004-12-27 13:51:59Z cziegeler $
46  */

47 public class ServletDefinitionImpl
48 implements ServletDefinition, ServletDefinitionCtrl, java.io.Serializable JavaDoc, Support {
49
50     private DescriptionSet descriptions = new DescriptionSetImpl();
51     private DisplayNameSet displayNames = new DisplayNameSetImpl();
52
53     // not used variables - only for castor
54
public String JavaDoc icon;
55     private String JavaDoc id = "";
56     private ParameterSet initParams = new ParameterSetImpl();
57     private SecurityRoleRefSet initSecurityRoleRefs = new SecurityRoleRefSetImpl();
58     public String JavaDoc jspFile;
59     public String JavaDoc loadOnStartup;
60     private ObjectID objectId;
61     public String JavaDoc securityRoleRef;
62     private String JavaDoc servletClass;
63     private ServletMapping servletMapping;
64     private String JavaDoc servletName;
65     private long available = 0;
66
67     private WebApplicationDefinition webApplication;
68
69     // ServletDefinition implementation.
70

71     public ObjectID getId() {
72         if (objectId==null) {
73             objectId = org.apache.cocoon.portal.pluto.om.common.ObjectIDImpl.createFromString(id);
74         }
75         return objectId;
76     }
77
78     public String JavaDoc getServletName() {
79         return servletName;
80     }
81
82     public DisplayName getDisplayName(Locale JavaDoc locale) {
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         return servletClass;
95     }
96
97     public ParameterSet getInitParameterSet() {
98         return initParams;
99     }
100
101     public WebApplicationDefinition getWebApplicationDefinition() {
102         return webApplication;
103     }
104
105     public RequestDispatcher JavaDoc getRequestDispatcher(ServletContext JavaDoc servletContext) {
106         ServletContext JavaDoc newContext = webApplication.getServletContext(servletContext);
107         if (newContext==null) {
108             return null;
109         }
110         return newContext.getRequestDispatcher(servletMapping.getUrlPattern());
111     }
112
113     public long getAvailable() {
114         return available;
115     }
116
117     public boolean isUnavailable() {
118         if (available == 0) {
119             return false;
120         } else if (available <= System.currentTimeMillis()) {
121             available = 0;
122             return false;
123         } else {
124             return true;
125         }
126     }
127
128     // Support implementation.
129

130     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc {
131         setServletMapping((ServletMapping)parameter);
132     }
133
134
135     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc {
136         ((Support)descriptions).postLoad(parameter);
137         ((Support)displayNames).postLoad(parameter);
138     }
139     
140     public void postStore(Object JavaDoc parameter) throws Exception JavaDoc {
141         // nothing to do
142
}
143     
144     public void preBuild(Object JavaDoc parameter) throws Exception JavaDoc {
145         setWebApplicationDefinition((WebApplicationDefinition)parameter);
146     }
147     
148     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc {
149         // nothing to do
150
}
151
152     // additional methods.
153

154     public String JavaDoc getCastorId() {
155         if (id.length() > 0) {
156             return getId().toString();
157         }
158             return null;
159     }
160
161     public Collection JavaDoc getCastorInitParams() {
162         return(ParameterSetImpl)initParams;
163     }
164
165     public SecurityRoleRefSet getCastorInitSecurityRoleRefs() {
166         return initSecurityRoleRefs;
167     }
168
169     public Collection JavaDoc getCastorDisplayNames() {
170         return(DisplayNameSetImpl)displayNames;
171     }
172
173     public Collection JavaDoc getCastorDescriptions() {
174         return(DescriptionSetImpl)descriptions;
175     }
176
177     public Collection JavaDoc getDescriptions() {
178         return(DescriptionSetImpl)descriptions;
179     }
180
181     public SecurityRoleRefSet getInitSecurityRoleRefSet() {
182         return initSecurityRoleRefs;
183     }
184
185     public String JavaDoc getJspFile() {
186         return jspFile;
187     }
188
189     public void setCastorId(String JavaDoc id) {
190         setId(id);
191     }
192
193     public void setCastorInitSecurityRoleRefs(SecurityRoleRefSet castorInitSecurityRoleRefs) {
194         this.initSecurityRoleRefs = castorInitSecurityRoleRefs;
195     }
196
197     public void setCastorDisplayNames(DisplayNameSet castorDisplayNames) {
198         this.displayNames = castorDisplayNames;
199     }
200
201     public void setCastorDescriptions(DescriptionSet castorDescriptions) {
202         this.descriptions = castorDescriptions;
203     }
204
205     public void setDisplayNames(DisplayNameSet displayNames) {
206         this.displayNames = displayNames;
207     }
208
209     public void setDescriptions(DescriptionSet descriptions) {
210         this.descriptions = descriptions;
211     }
212
213     public void setId(String JavaDoc id) {
214         this.id = id;
215         this.objectId = null;
216     }
217
218     public void setServletClass(String JavaDoc servletClass) {
219         this.servletClass = servletClass;
220     }
221
222     public void setAvailable(long available) {
223         if (available > System.currentTimeMillis()) {
224             this.available = available;
225         } else {
226             this.available = 0;
227         }
228     }
229
230     public void setJspFile(String JavaDoc jspFile) {
231         this.jspFile = jspFile;
232     }
233
234     protected void setServletMapping(ServletMapping servletMapping) {
235         this.servletMapping = servletMapping;
236     }
237
238     public void setServletName(String JavaDoc servletName) {
239         this.servletName = servletName;
240     }
241
242     protected void setWebApplicationDefinition(WebApplicationDefinition webApplication) {
243         this.webApplication = webApplication;
244     }
245
246 }
247
Popular Tags