KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Locale JavaDoc;
27 import java.util.Vector JavaDoc;
28
29 import javax.servlet.ServletContext JavaDoc;
30
31 import org.apache.pluto.om.common.Description;
32 import org.apache.pluto.om.common.DescriptionSet;
33 import org.apache.pluto.om.common.DisplayName;
34 import org.apache.pluto.om.common.DisplayNameSet;
35 import org.apache.pluto.om.common.ObjectID;
36 import org.apache.pluto.om.common.ParameterSet;
37 import org.apache.pluto.om.common.SecurityRoleSet;
38 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
39 import org.apache.pluto.om.servlet.ServletDefinitionList;
40 import org.apache.pluto.om.servlet.WebApplicationDefinition;
41 import org.apache.pluto.portalImpl.om.common.Support;
42 import org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl;
43 import org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl;
44 import org.apache.pluto.portalImpl.services.log.Log;
45 import org.apache.pluto.util.StringUtils;
46
47 public class WebApplicationDefinitionImpl
48 implements WebApplicationDefinition, java.io.Serializable JavaDoc, Support {
49
50
51     // <not used variables - only for castor>
52
public String JavaDoc icon = null;
53     public String JavaDoc distributable = null;
54     public String JavaDoc sessionConfig = null;
55     public String JavaDoc mimeMapping = null;
56     public String JavaDoc welcomeFileList = null;
57     public String JavaDoc errorPage = null;
58     public String JavaDoc taglib = null;
59     public String JavaDoc resourceRef = null;
60     public String JavaDoc securityConstraint = null;
61     public String JavaDoc loginConfig = null;
62     public String JavaDoc securityRole = null;
63     public String JavaDoc envEntry = null;
64     public String JavaDoc ejbRef = null;
65     private Collection JavaDoc castorMimeMappings = new ArrayList JavaDoc(); // </not used variables - only for castor>
66

67
68     private String JavaDoc contextPath = null;
69     private DescriptionSet descriptions = new org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl();
70     private DisplayNameSet displayNames = new org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl();
71     private String JavaDoc id = "";
72     private ParameterSet initParams = new org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl();
73     private ObjectID objectId = null;
74     private Collection JavaDoc servletMappings = new ArrayList JavaDoc();
75     private ServletDefinitionList servlets = new ServletDefinitionListImpl();
76     private SecurityRoleSet securityRoles = new org.apache.pluto.portalImpl.om.common.impl.SecurityRoleSetImpl();
77
78     // modified by YCLI: START :: to handle multiple taglib tags and resource-ref tag
79
// private TagDefinition castorTagDefinition = new TagDefinition();
80
private TagDefinitionSet taglibs = new TagDefinitionSet();
81     private ResourceRefSet castorResourceRef = new ResourceRefSet();
82     // modified by YCLI: END
83

84     // WebApplicationDefinition implementation.
85

86     public ObjectID getId() {
87         if (objectId==null) {
88             objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(id);
89         }
90         return objectId;
91     }
92
93     /* (non-Javadoc)
94      * @see org.apache.pluto.om.servlet.WebApplicationDefinition#getDisplayName(Locale)
95      */

96     public DisplayName getDisplayName(Locale JavaDoc locale) {
97         return displayNames.get(locale);
98     }
99
100     public Description getDescription(Locale JavaDoc locale)
101     {
102         return descriptions.get(locale);
103     }
104
105     public ParameterSet getInitParameterSet()
106     {
107         return initParams;
108     }
109
110     public ServletDefinitionList getServletDefinitionList()
111     {
112         return servlets;
113     }
114
115     public ServletContext JavaDoc getServletContext(ServletContext JavaDoc servletContext)
116     {
117         if (Log.isDebugEnabled()) {
118             Log.debug("Looking up ServletContext for path "+contextPath);
119         }
120         return servletContext.getContext(contextPath);
121     }
122
123     public String JavaDoc getContextRoot() {
124
125         return contextPath;
126     }
127
128     // Support implementation.
129

130     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc
131     {
132         // not needed in this implementation
133
}
134
135     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc
136     {
137         Vector JavaDoc structure = (Vector JavaDoc)parameter;
138         PortletApplicationDefinition portletApplication = (PortletApplicationDefinition)structure.get(0);
139         String JavaDoc contextString = (String JavaDoc)structure.get(1);
140
141         ((Support)portletApplication).postLoad(this);
142
143         ((Support)servlets).postLoad(this);
144
145         ((Support)descriptions).postLoad(parameter);
146         ((Support)displayNames).postLoad(parameter);
147
148     }
149
150     public void postStore(Object JavaDoc parameter) throws Exception JavaDoc
151     {
152         ((Support)servlets).postStore(this);
153     }
154
155     public void preBuild(Object JavaDoc parameter) throws Exception JavaDoc
156     {
157         Vector JavaDoc structure = (Vector JavaDoc)parameter;
158         PortletApplicationDefinition portletApplication = (PortletApplicationDefinition)structure.get(0);
159         String JavaDoc contextString = (String JavaDoc)structure.get(1);
160
161         setContextRoot(contextString);
162
163         HashMap JavaDoc servletMap = new HashMap JavaDoc(1);
164         Vector JavaDoc structure2 = new Vector JavaDoc();
165         structure2.add(this);
166         structure2.add(servletMappings);
167         structure2.add(servletMap);
168
169         ((Support)servlets).preBuild(structure2);
170
171         Vector JavaDoc structure3 = new Vector JavaDoc();
172         structure3.add(contextString);
173         structure3.add(this);
174         structure3.add(servletMap);
175         ((Support)portletApplication).preBuild(structure3);
176     }
177
178     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc
179     {
180         Vector JavaDoc structure = (Vector JavaDoc)parameter;
181         PortletApplicationDefinition portletApplication = (PortletApplicationDefinition)structure.get(0);
182         String JavaDoc contextString = (String JavaDoc)structure.get(1);
183
184         ((Support)portletApplication).preStore(null);
185
186         ((Support)servlets).preStore(this);
187     }
188     
189     // additional methods.
190

191     public String JavaDoc getCastorId() {
192         if (id.length() > 0) {
193             return getId().toString();
194         } else {
195             return null;
196         }
197     }
198
199     public Collection JavaDoc getCastorInitParams()
200     {
201         return(org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams;
202     }
203
204     public Collection JavaDoc getCastorServlets()
205     {
206         return(ServletDefinitionListImpl)servlets;
207     }
208
209     public Collection JavaDoc getCastorDisplayNames()
210     {
211         return(DisplayNameSetImpl)displayNames;
212     }
213
214     public Collection JavaDoc getCastorDescriptions()
215     {
216         return(DescriptionSetImpl)descriptions;
217     }
218
219     public SecurityRoleSet getSecurityRoles()
220     {
221         return securityRoles;
222     }
223
224     public Collection JavaDoc getServletMappings()
225     {
226         return servletMappings;
227     }
228     public void setCastorId(String JavaDoc id) {
229         setId(id);
230     }
231     
232     protected void setContextRoot(String JavaDoc contextPath)
233     {
234         // Test for IBM WebSphere
235
if (contextPath != null && contextPath.endsWith(".war"))
236         {
237             contextPath = contextPath.substring(0, contextPath.length()-4);
238         }
239         this.contextPath = contextPath;
240     }
241
242     public void setDescriptions(DescriptionSet descriptions)
243     {
244         this.descriptions = descriptions;
245     }
246
247     public void setDisplayNames(DisplayNameSet displayNames)
248     {
249         this.displayNames = displayNames;
250     }
251
252     public void setCastorDescriptions(DescriptionSet castorDescriptions)
253     {
254         this.descriptions = castorDescriptions;
255     }
256
257     public void setCastorDisplayNames(DisplayNameSet castorDisplayNames)
258     {
259         this.displayNames = castorDisplayNames;
260     }
261
262     public void setId(String JavaDoc id)
263     {
264         this.id = id;
265         objectId = null;
266     }
267
268     // internal methods used for debugging purposes only
269

270     public String JavaDoc toString()
271     {
272         return toString(0);
273     }
274
275     public String JavaDoc toString(int indent)
276     {
277         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
278         StringUtils.newLine(buffer,indent);
279         buffer.append(getClass().toString()); buffer.append(":");
280         StringUtils.newLine(buffer,indent);
281         buffer.append("{");
282         StringUtils.newLine(buffer,indent);
283         buffer.append("id='"); buffer.append(id); buffer.append("'");
284
285         StringUtils.newLine(buffer,indent);
286         buffer.append(((DisplayNameSetImpl)displayNames).toString(indent));
287
288         StringUtils.newLine(buffer,indent);
289         buffer.append(((DescriptionSetImpl)descriptions).toString(indent));
290
291         StringUtils.newLine(buffer,indent);
292         buffer.append(((org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams).toString(indent));
293
294         StringUtils.newLine(buffer,indent);
295         buffer.append(((ServletDefinitionListImpl)servlets).toString(indent));
296
297         Iterator JavaDoc iterator = servletMappings.iterator();
298         if (iterator.hasNext()) {
299             StringUtils.newLine(buffer,indent);
300             buffer.append("ServletMappings:");
301         }
302         while (iterator.hasNext()) {
303             buffer.append(((ServletMappingImpl)iterator.next()).toString(indent+2));
304         }
305
306         StringUtils.newLine(buffer,indent);
307         buffer.append("contextPath='"); buffer.append(contextPath); buffer.append("'");
308         StringUtils.newLine(buffer,indent);
309         buffer.append("}");
310         return buffer.toString();
311     }
312
313     // modified by YCLI: START :: handling multiple taglib tags and resource-ref tag
314

315     /**
316      * @return Custom tag definitions configured in the webapp.
317      */

318     public TagDefinitionSet getTagDefinitionSet()
319     {
320         return taglibs;
321     }
322
323     public Collection JavaDoc getCastorTagDefinitions() {
324         return taglibs;
325     }
326
327     public void setCastorTagDefinitions(TagDefinitionSet taglibs)
328     {
329         this.taglibs = taglibs;
330     }
331
332     public ResourceRefSet getCastorResourceRefSet() {
333         return castorResourceRef;
334     }
335
336     public void setCastorResourceRefSet(ResourceRefSet resourceRefs) {
337         castorResourceRef = resourceRefs;
338     }
339     // modified by YCLI: END
340

341     /**
342      * @return Returns the castorMimeMappings.
343      */

344     public Collection JavaDoc getCastorMimeMappings()
345     {
346         return castorMimeMappings;
347     }
348     
349     /**
350      * @param castorMimeMappings The castorMimeMappings to set.
351      */

352     public void setCastorMimeMappings(Collection JavaDoc castorMimeMappings)
353     {
354         this.castorMimeMappings = castorMimeMappings;
355     }
356 }
357
Popular Tags