KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 import org.apache.pluto.om.servlet.ServletDefinition;
24 import org.apache.pluto.om.servlet.ServletDefinitionList;
25 import org.apache.pluto.om.servlet.ServletDefinitionListCtrl;
26 import org.apache.pluto.om.servlet.WebApplicationDefinition;
27 import org.apache.cocoon.ProcessingException;
28 import org.apache.cocoon.portal.pluto.om.common.AbstractSupportSet;
29 import org.apache.cocoon.portal.pluto.om.common.Support;
30
31 /**
32  *
33  *
34  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
35  *
36  * @version CVS $Id: ServletDefinitionListImpl.java 123407 2004-12-27 13:51:59Z cziegeler $
37  */

38 public class ServletDefinitionListImpl extends AbstractSupportSet
39 implements ServletDefinitionList, ServletDefinitionListCtrl, java.io.Serializable JavaDoc, Support {
40
41     // ServletDefinitionList implementation.
42

43     public ServletDefinition get(String JavaDoc name) {
44         Iterator JavaDoc iterator = this.iterator();
45         while (iterator.hasNext()) {
46             ServletDefinition servletDefinition = (ServletDefinition)iterator.next();
47             if (servletDefinition.getServletName().equals(name)) {
48                 return servletDefinition;
49             }
50         }
51         return null;
52     }
53
54     // ServletDefinitionListCtrl implementation.
55

56     public ServletDefinition add(String JavaDoc name, String JavaDoc className) {
57         ServletDefinitionImpl servletDefinition = new ServletDefinitionImpl();
58         servletDefinition.setServletName(name);
59         servletDefinition.setServletClass(className);
60
61         super.add(servletDefinition);
62
63         return servletDefinition;
64     }
65
66     public ServletDefinition remove(String JavaDoc name) {
67         Iterator JavaDoc iterator = this.iterator();
68         while (iterator.hasNext()) {
69             ServletDefinition servletDefinition = (ServletDefinition)iterator.next();
70             if (servletDefinition.getServletName().equals(name)) {
71                 super.remove(servletDefinition);
72                 return servletDefinition;
73             }
74         }
75         return null;
76     }
77
78     public void remove(ServletDefinition servletDefinition) {
79         super.remove(servletDefinition);
80     }
81
82     // Support implementation.
83

84     public void preBuild(Object JavaDoc parameter) throws Exception JavaDoc {
85         Vector JavaDoc structure = (Vector JavaDoc)parameter;
86         WebApplicationDefinition webApplicationDefinition = (WebApplicationDefinition)structure.get(0);
87         Collection JavaDoc servletMappings = (Collection JavaDoc)structure.get(1);
88         HashMap JavaDoc servletMap = (HashMap JavaDoc)structure.get(2);
89
90         // build internal hashtable to cross link mappings with servlets
91
HashMap JavaDoc mappings = new HashMap JavaDoc(servletMappings.size());
92         Iterator JavaDoc iterator = servletMappings.iterator();
93         while (iterator.hasNext()) {
94             ServletMapping servletMapping = (ServletMapping)iterator.next();
95             mappings.put(servletMapping.getServletName(),servletMapping);
96         }
97         // update servlets
98
iterator = this.iterator();
99         while (iterator.hasNext()) {
100             ServletDefinition servlet = (ServletDefinition)iterator.next();
101             ((Support)servlet).preBuild(webApplicationDefinition);
102
103             if (servlet.getInitParameterSet() != null) {
104                 if (servlet.getInitParameterSet().get("portlet-guid") != null) {
105                     String JavaDoc guid = servlet.getInitParameterSet().get("portlet-guid").getValue();
106                     servletMap.put(guid, servlet);
107
108                     ServletMapping servletMapping = (ServletMapping)mappings.get(servlet.getServletName());
109                     if (mappings==null) {
110                         throw new ProcessingException("No corresponding servlet mapping found for servlet name '"+servlet.getServletName()+"'");
111                     }
112                     ((Support)servlet).postBuild(servletMapping);
113
114                 }
115             }
116         }
117
118     }
119
120     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc {
121         // nothing to do
122
}
123
124     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc {
125         Iterator JavaDoc iterator = this.iterator();
126         while (iterator.hasNext()) {
127             ((ServletDefinitionImpl)iterator.next()).postLoad(parameter);
128         }
129
130     }
131
132     public void postStore(Object JavaDoc parameter) throws Exception JavaDoc {
133         // nothing to do
134
}
135
136     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc {
137         // nothing to do
138
}
139     
140 }
141
Popular Tags