KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Locale JavaDoc;
22 import java.util.StringTokenizer JavaDoc;
23
24 import org.apache.cocoon.portal.pluto.om.common.ContentTypeSetImpl;
25 import org.apache.cocoon.portal.pluto.om.common.DescriptionSetImpl;
26 import org.apache.cocoon.portal.pluto.om.common.DisplayNameSetImpl;
27 import org.apache.cocoon.portal.pluto.om.common.LanguageSetImpl;
28 import org.apache.cocoon.portal.pluto.om.common.ParameterSetImpl;
29 import org.apache.cocoon.portal.pluto.om.common.PreferenceSetImpl;
30 import org.apache.cocoon.portal.pluto.om.common.SecurityRoleRefSetImpl;
31 import org.apache.cocoon.portal.pluto.om.common.Support;
32 import org.apache.pluto.invoker.PortletInvoker;
33 import org.apache.pluto.om.common.Description;
34 import org.apache.pluto.om.common.DescriptionSet;
35 import org.apache.pluto.om.common.DisplayName;
36 import org.apache.pluto.om.common.DisplayNameSet;
37 import org.apache.pluto.om.common.LanguageSet;
38 import org.apache.pluto.om.common.ObjectID;
39 import org.apache.pluto.om.common.ParameterSet;
40 import org.apache.pluto.om.common.PreferenceSet;
41 import org.apache.pluto.om.common.SecurityRoleRefSet;
42 import org.apache.pluto.om.portlet.ContentTypeSet;
43 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
44 import org.apache.pluto.om.portlet.PortletDefinition;
45 import org.apache.pluto.om.portlet.PortletDefinitionCtrl;
46 import org.apache.pluto.om.servlet.ServletDefinition;
47
48 /**
49  *
50  *
51  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
52  *
53  * @version CVS $Id: PortletDefinitionImpl.java 123407 2004-12-27 13:51:59Z cziegeler $
54  */

55 public class PortletDefinitionImpl
56 implements PortletDefinition, PortletDefinitionCtrl, java.io.Serializable JavaDoc, Support {
57
58
59     private PortletApplicationDefinition application = null;
60     private LanguageSet castorResources = null;
61
62     // contains String objects
63
private ArrayList JavaDoc castorSupportedLocales = new ArrayList JavaDoc();
64     private ClassLoader JavaDoc classLoader;
65     private String JavaDoc className;
66     private ContentTypeSet contentTypes = new ContentTypeSetImpl();
67     private DescriptionSet descriptions = new DescriptionSetImpl();
68
69     private DisplayNameSet displayNames = new DisplayNameSetImpl();
70     private String JavaDoc expirationCache;
71     public String JavaDoc id = "";
72     private ParameterSet initParams = new ParameterSetImpl();
73     private SecurityRoleRefSet initSecurityRoleRefs = new SecurityRoleRefSetImpl();
74     private String JavaDoc name;
75
76     private ObjectID objectId;
77     private PreferenceSet preferences = new PreferenceSetImpl();
78
79     // private PortletInfoImpl portletInfo = null;
80
private String JavaDoc resourceBundle;
81     private ServletDefinition servlet;
82
83     // contains Locale objects
84
private ArrayList JavaDoc supportedLocales = new ArrayList JavaDoc();
85
86     /** is this a local portlet? */
87     protected boolean localPortlet = false;
88     
89     /** The local portlet invoker */
90     protected PortletInvoker localPortletInvoker;
91     
92     // PortletDefinition implementation.
93

94     public ObjectID getId() {
95         if (objectId==null) {
96             objectId = org.apache.cocoon.portal.pluto.om.common.ObjectIDImpl.createFromString(getGUID());
97         }
98
99         return objectId;
100     }
101
102     public String JavaDoc getClassName() {
103         return className;
104     }
105
106     public String JavaDoc getName() {
107         return name;
108     }
109
110     /* (non-Javadoc)
111      * @see org.apache.pluto.om.portlet.PortletDefinition#getDescription(Locale)
112      */

113     public Description getDescription(Locale JavaDoc locale) {
114         return descriptions.get(locale);
115     }
116
117     public LanguageSet getLanguageSet() {
118         ((LanguageSetImpl)castorResources).setClassLoader(this.getPortletClassLoader());
119         return castorResources;
120     }
121
122     public ParameterSet getInitParameterSet() {
123         return initParams;
124     }
125
126     public SecurityRoleRefSet getInitSecurityRoleRefSet() {
127         return initSecurityRoleRefs;
128     }
129
130     public PreferenceSet getPreferenceSet() {
131         ((PreferenceSetImpl)preferences).setClassLoader(this.getPortletClassLoader());
132         return preferences;
133     }
134
135     public ContentTypeSet getContentTypeSet() {
136         return contentTypes;
137     }
138
139     public PortletApplicationDefinition getPortletApplicationDefinition() {
140         return application;
141     }
142
143     public ServletDefinition getServletDefinition() {
144         return servlet;
145     }
146
147     public DisplayName getDisplayName(Locale JavaDoc locale) {
148         return displayNames.get(locale);
149     }
150
151     public String JavaDoc getExpirationCache() {
152         return expirationCache;
153     }
154
155     // PortletDefinitionCtrl implementation.
156

157     public void setId(String JavaDoc id) {
158         // todo excep
159
}
160
161     public void setClassName(String JavaDoc className) {
162         this.className = className;
163     }
164
165     public void setName(String JavaDoc name) {
166         this.name = name;
167     }
168
169     /* (non-Javadoc)
170      * @see org.apache.pluto.om.portlet.PortletDefinitionCtrl#setDescriptions(DescriptionSet)
171      */

172     public void setDescriptions(DescriptionSet descriptions) {
173         this.descriptions = descriptions;
174     }
175
176     public void setDisplayNames(DisplayNameSet displayNames) {
177         this.displayNames = displayNames;
178     }
179
180     public void setPortletClassLoader(ClassLoader JavaDoc loader) {
181         this.classLoader = loader;
182     }
183     
184     public void store() throws java.io.IOException JavaDoc {
185         // not supported
186
}
187
188
189     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc {
190         setServletDefinition((ServletDefinition)parameter);
191         ((Support)contentTypes).postBuild(this);
192         if (castorResources!=null) {
193             ((Support)castorResources).postBuild(this);
194         }
195     }
196
197     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc {
198         ((Support)contentTypes).postLoad(this);
199
200         // create Locale objects for given locale entries
201
Iterator JavaDoc iterator = castorSupportedLocales.iterator();
202         while (iterator.hasNext()) {
203
204             String JavaDoc locale = (String JavaDoc)iterator.next();
205
206             // parse locale String
207
StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(locale,"_");
208             String JavaDoc[] localeDef = new String JavaDoc[3];
209             for (int i=0; i<3 ;i++) {
210                 if (tokenizer.hasMoreTokens()) {
211                     localeDef[i] = tokenizer.nextToken();
212                 } else {
213                     localeDef[i] = "";
214                 }
215             }
216             supportedLocales.add(new java.util.Locale JavaDoc(localeDef[0], localeDef[1], localeDef[2]));
217
218         }
219
220         if (castorResources==null) {
221             castorResources = new LanguageSetImpl();
222         }
223         if (resourceBundle!=null) {
224             ((LanguageSetImpl)castorResources).setResources(resourceBundle);
225         }
226         ((Support)castorResources).postLoad(this.supportedLocales);
227         ((Support)descriptions).postLoad(parameter);
228         ((Support)displayNames).postLoad(parameter);
229
230     }
231     public void postStore(Object JavaDoc parameter) throws Exception JavaDoc {
232         ((Support)contentTypes).postStore(this);
233         if (castorResources!=null) {
234             ((Support)castorResources).postStore(this);
235         }
236     }
237     public void preBuild(Object JavaDoc parameter) throws Exception JavaDoc {
238         setPortletApplicationDefinition((PortletApplicationDefinition)parameter);
239         ((Support)contentTypes).preBuild(this);
240         if (castorResources!=null) {
241             ((Support)castorResources).preBuild(this);
242         }
243     }
244     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc {
245         ((Support)contentTypes).preStore(this);
246         if (castorResources!=null) {
247             ((Support)castorResources).preStore(this);
248         }
249     }
250
251     // additional methods.
252

253     public Collection JavaDoc getCastorContentTypes() {
254         return(ContentTypeSetImpl)contentTypes;
255     }
256
257     public Collection JavaDoc getCastorDisplayNames() {
258         return(DisplayNameSetImpl)displayNames;
259     }
260
261     public Collection JavaDoc getCastorDescriptions() {
262         return(DescriptionSetImpl)descriptions;
263     }
264
265     public Collection JavaDoc getDescriptions() {
266         return(DescriptionSetImpl)descriptions;
267     }
268
269     public Collection JavaDoc getCastorInitParams() {
270         return(ParameterSetImpl)initParams;
271     }
272
273     public SecurityRoleRefSet getCastorInitSecurityRoleRefs() {
274         return initSecurityRoleRefs;
275     }
276
277     public PreferenceSet getCastorPreferences() {
278         return preferences;
279     }
280
281     public LanguageSet getCastorResources() {
282         return castorResources;
283     }
284
285     // not yet fully supported
286
// public Collection getSecurityRoleRef()
287
// {
288
// return securityRoleRef;
289
// }
290

291     // public void setSecurityRoleRef(Collection securityRoleRef)
292
// {
293
// this.securityRoleRef = (ArrayList)securityRoleRef;
294
// }
295

296     // additional internal methods
297

298     public Collection JavaDoc getCastorSupportedLocales() {
299         return castorSupportedLocales;
300     }
301
302
303     private String JavaDoc getGUID() {
304         String JavaDoc portletID = "";
305         if (getName()!=null) portletID += getName();
306
307         portletID = application.getId().toString() + "."+portletID;
308         return portletID;
309     }
310
311     public ClassLoader JavaDoc getPortletClassLoader() {
312         return classLoader;
313     }
314
315     public String JavaDoc getResourceBundle() {
316         return this.resourceBundle;
317     }
318
319     public Collection JavaDoc getSupportedLocales() {
320         return supportedLocales;
321     }
322
323     public void setCastorContentTypes(ContentTypeSet castorContentTypes) {
324         this.contentTypes = castorContentTypes;
325     }
326
327     public void setCastorInitParams(ParameterSet castorInitParams) {
328         this.initParams = castorInitParams;
329     }
330
331     public void setCastorInitSecurityRoleRefs(SecurityRoleRefSet castorInitSecurityRoleRefs) {
332         this.initSecurityRoleRefs = castorInitSecurityRoleRefs;
333     }
334
335     public void setCastorDisplayNames(DisplayNameSet castorDisplayNames) {
336         this.displayNames = castorDisplayNames;
337     }
338
339     public void setCastorDescriptions(DescriptionSet castorDescriptions) {
340         this.descriptions = castorDescriptions;
341     }
342
343     public void setCastorPreferences(PreferenceSet castorPreferences) {
344         this.preferences = castorPreferences;
345     }
346
347     public void setCastorResources(LanguageSet resources) {
348         this.castorResources = resources;
349     }
350
351     public void setCastorSupportedLocales(Collection JavaDoc castorSupportedLocales) {
352         this.castorSupportedLocales = (ArrayList JavaDoc)castorSupportedLocales;
353     }
354
355     public void setExpirationCache(String JavaDoc expirationCache) {
356         this.expirationCache = expirationCache;
357     }
358
359     protected void setPortletApplicationDefinition(PortletApplicationDefinition application) {
360         this.application = application;
361     }
362
363     public void setResourceBundle(String JavaDoc resourceBundle) {
364         this.resourceBundle = resourceBundle;
365     }
366
367     protected void setServletDefinition(ServletDefinition servlet) {
368         this.servlet = servlet;
369     }
370
371     /**
372      * @return Returns the localPortlet.
373      */

374     public boolean isLocalPortlet() {
375         return this.localPortlet;
376     }
377
378     /**
379      * @param localPortlet The localPortlet to set.
380      */

381     public void setLocalPortlet(boolean localPortlet) {
382         this.localPortlet = localPortlet;
383     }
384
385     /**
386      * @return Returns the localPortletInvoker.
387      */

388     public PortletInvoker getLocalPortletInvoker() {
389         return this.localPortletInvoker;
390     }
391
392     /**
393      * Set a local portlet invoker for caching
394      * @param localPortletInvoker The localPortletInvoker to set.
395      */

396     public void setLocalPortletInvoker(PortletInvoker localPortletInvoker) {
397         this.localPortletInvoker = localPortletInvoker;
398     }
399 }
400
Popular Tags