KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > om > portlet > impl > PortletDefinitionImpl


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.portlet.impl;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Locale JavaDoc;
26 import java.util.StringTokenizer 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.LanguageSet;
33 import org.apache.pluto.om.common.ObjectID;
34 import org.apache.pluto.om.common.ParameterSet;
35 import org.apache.pluto.om.common.PreferenceSet;
36 import org.apache.pluto.om.common.SecurityRoleRefSet;
37 import org.apache.pluto.om.portlet.ContentTypeSet;
38 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
39 import org.apache.pluto.om.portlet.PortletDefinition;
40 import org.apache.pluto.om.portlet.PortletDefinitionCtrl;
41 import org.apache.pluto.om.servlet.ServletDefinition;
42 import org.apache.pluto.portalImpl.om.common.Support;
43 import org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl;
44 import org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl;
45 import org.apache.pluto.portalImpl.om.common.impl.LanguageSetImpl;
46 import org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl;
47 import org.apache.pluto.util.StringUtils;
48
49 public class PortletDefinitionImpl
50 implements PortletDefinition, PortletDefinitionCtrl, java.io.Serializable JavaDoc,
51 org.apache.pluto.portalImpl.om.common.Support {
52
53
54     private PortletApplicationDefinition application = null;
55     private LanguageSet castorResources = null;
56
57     // contains String objects
58
private ArrayList JavaDoc castorSupportedLocales = new ArrayList JavaDoc();
59     private ClassLoader JavaDoc classLoader = null;
60     private String JavaDoc className = null;
61     private ContentTypeSet contentTypes = new ContentTypeSetImpl();
62     private DescriptionSet descriptions = new org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl();
63
64     private DisplayNameSet displayNames = new org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl();
65     private String JavaDoc expirationCache = null;
66     public String JavaDoc id = "";
67     private ParameterSet initParams = new org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl();
68     private SecurityRoleRefSet initSecurityRoleRefs = new org.apache.pluto.portalImpl.om.common.impl.SecurityRoleRefSetImpl();
69     private String JavaDoc name = null;
70
71     private ObjectID objectId = null;
72     private PreferenceSet preferences = new org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl();
73
74     // private PortletInfoImpl portletInfo = null;
75
private String JavaDoc resourceBundle = null;
76     private ServletDefinition servlet = null;
77
78     // contains Locale objects
79
private ArrayList JavaDoc supportedLocales = new ArrayList JavaDoc();
80
81     // PortletDefinition implementation.
82

83     public ObjectID getId()
84     {
85         if (objectId==null) {
86             objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(getGUID());
87         }
88
89         return objectId;
90     }
91
92     public String JavaDoc getClassName()
93     {
94         return className;
95     }
96
97     public String JavaDoc getName()
98     {
99         return name;
100     }
101
102     /* (non-Javadoc)
103      * @see org.apache.pluto.om.portlet.PortletDefinition#getDescription(Locale)
104      */

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

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

176     public void setDescriptions(DescriptionSet descriptions) {
177         this.descriptions = descriptions;
178     }
179
180     public void setDisplayNames(DisplayNameSet displayNames)
181     {
182         this.displayNames = displayNames;
183     }
184
185     public void setPortletClassLoader(ClassLoader JavaDoc loader)
186     {
187         this.classLoader = loader;
188     }
189     
190     public void store() throws java.io.IOException JavaDoc
191     {
192         // not supported
193
}
194
195     // org.apache.pluto.portalImpl.om.common.Support implementation.
196

197     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc
198     {
199         setServletDefinition((ServletDefinition)parameter);
200         ((Support)contentTypes).postBuild(this);
201         if (castorResources!=null) {
202             ((Support)castorResources).postBuild(this);
203         }
204     }
205
206     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc
207     {
208         ((Support)contentTypes).postLoad(this);
209
210         // create Locale objects for given locale entries
211
Iterator JavaDoc iterator = castorSupportedLocales.iterator();
212         while (iterator.hasNext()) {
213
214             String JavaDoc locale = (String JavaDoc)iterator.next();
215
216             // parse locale String
217
StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(locale,"_");
218             String JavaDoc[] localeDef = new String JavaDoc[3];
219             for (int i=0; i<3 ;i++) {
220                 if (tokenizer.hasMoreTokens()) {
221                     localeDef[i] = tokenizer.nextToken();
222                 } else {
223                     localeDef[i] = "";
224                 }
225             }
226             supportedLocales.add(new java.util.Locale JavaDoc(localeDef[0], localeDef[1], localeDef[2]));
227
228         }
229
230         if (castorResources==null) {
231             castorResources = new LanguageSetImpl();
232         }
233         if (resourceBundle!=null) {
234             ((LanguageSetImpl)castorResources).setResources(resourceBundle);
235         }
236         ((Support)castorResources).postLoad(this.supportedLocales);
237         ((Support)descriptions).postLoad(parameter);
238         ((Support)displayNames).postLoad(parameter);
239
240     }
241     public void postStore(Object JavaDoc parameter) throws Exception JavaDoc
242     {
243         ((Support)contentTypes).postStore(this);
244         if (castorResources!=null) {
245             ((Support)castorResources).postStore(this);
246         }
247     }
248     public void preBuild(Object JavaDoc parameter) throws Exception JavaDoc
249     {
250         setPortletApplicationDefinition((PortletApplicationDefinition)parameter);
251         ((Support)contentTypes).preBuild(this);
252         if (castorResources!=null) {
253             ((Support)castorResources).preBuild(this);
254         }
255     }
256     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc
257     {
258         ((Support)contentTypes).preStore(this);
259         if (castorResources!=null) {
260             ((Support)castorResources).preStore(this);
261         }
262     }
263
264     // additional methods.
265

266     public Collection JavaDoc getCastorContentTypes()
267     {
268         return(ContentTypeSetImpl)contentTypes;
269     }
270
271     public Collection JavaDoc getCastorDisplayNames()
272     {
273         return(DisplayNameSetImpl)displayNames;
274     }
275
276     public Collection JavaDoc getCastorDescriptions()
277     {
278         return(DescriptionSetImpl)descriptions;
279     }
280
281     public Collection JavaDoc getDescriptions()
282     {
283         return(DescriptionSetImpl)descriptions;
284     }
285
286     public Collection JavaDoc getCastorInitParams()
287     {
288         return(org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams;
289     }
290
291     public SecurityRoleRefSet getCastorInitSecurityRoleRefs()
292     {
293         return initSecurityRoleRefs;
294     }
295
296     public PreferenceSet getCastorPreferences()
297     {
298         return preferences;
299     }
300
301     public LanguageSet getCastorResources()
302     {
303         return castorResources;
304     }
305
306     // not yet fully supported
307
// public Collection getSecurityRoleRef()
308
// {
309
// return securityRoleRef;
310
// }
311

312     // public void setSecurityRoleRef(Collection securityRoleRef)
313
// {
314
// this.securityRoleRef = (ArrayList)securityRoleRef;
315
// }
316

317     // additional internal methods
318

319     public Collection JavaDoc getCastorSupportedLocales()
320     {
321         return castorSupportedLocales;
322     }
323
324
325     private String JavaDoc getGUID()
326     {
327         String JavaDoc portletID = "";
328         if (getName()!=null) portletID += getName();
329
330         portletID = application.getId().toString() + "."+portletID;
331         return portletID;
332     }
333
334     public ClassLoader JavaDoc getPortletClassLoader()
335     {
336         return classLoader;
337     }
338
339     public String JavaDoc getResourceBundle()
340     {
341         return this.resourceBundle;
342     }
343
344     public Collection JavaDoc getSupportedLocales()
345     {
346         return supportedLocales;
347     }
348
349     public void setCastorContentTypes(ContentTypeSet castorContentTypes)
350     {
351         this.contentTypes = castorContentTypes;
352     }
353
354     public void setCastorInitParams(ParameterSet castorInitParams)
355     {
356         this.initParams = castorInitParams;
357     }
358
359     public void setCastorInitSecurityRoleRefs(SecurityRoleRefSet castorInitSecurityRoleRefs)
360     {
361         this.initSecurityRoleRefs = castorInitSecurityRoleRefs;
362     }
363
364     public void setCastorDisplayNames(DisplayNameSet castorDisplayNames)
365     {
366         this.displayNames = castorDisplayNames;
367     }
368
369     public void setCastorDescriptions(DescriptionSet castorDescriptions)
370     {
371         this.descriptions = castorDescriptions;
372     }
373
374     public void setCastorPreferences(PreferenceSet castorPreferences)
375     {
376         this.preferences = castorPreferences;
377     }
378
379     public void setCastorResources(LanguageSet resources)
380     {
381         this.castorResources = resources;
382     }
383
384     public void setCastorSupportedLocales(Collection JavaDoc castorSupportedLocales)
385     {
386         this.castorSupportedLocales = (ArrayList JavaDoc)castorSupportedLocales;
387     }
388
389     public void setExpirationCache(String JavaDoc expirationCache)
390     {
391         this.expirationCache = expirationCache;
392     }
393
394     protected void setPortletApplicationDefinition(PortletApplicationDefinition application)
395     {
396         this.application = application;
397     }
398
399     public void setResourceBundle(String JavaDoc resourceBundle)
400     {
401         this.resourceBundle = resourceBundle;
402     }
403
404     protected void setServletDefinition(ServletDefinition servlet)
405     {
406         this.servlet = servlet;
407     }
408
409
410     // internal methods used for debugging purposes only
411

412     public String JavaDoc toString()
413     {
414         return toString(0);
415     }
416
417     public String JavaDoc toString(int indent)
418     {
419         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
420         StringUtils.newLine(buffer,indent);
421         buffer.append(getClass().toString()); buffer.append(":");
422         StringUtils.newLine(buffer,indent);
423         buffer.append("{");
424         StringUtils.newLine(buffer,indent);
425         buffer.append("objectID='"); buffer.append(getId()); buffer.append("'");
426         StringUtils.newLine(buffer,indent);
427         buffer.append("guid='"); buffer.append(getGUID()); buffer.append("'");
428         StringUtils.newLine(buffer,indent);
429         buffer.append("id='"); buffer.append(id); buffer.append("'");
430         StringUtils.newLine(buffer,indent);
431         buffer.append("name='"); buffer.append(name); buffer.append("'");
432
433         StringUtils.newLine(buffer,indent);
434         buffer.append(((org.apache.pluto.portalImpl.om.common.impl.LanguageSetImpl)castorResources).toString(indent));
435
436         StringUtils.newLine(buffer,indent);
437         buffer.append(((org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams).toString(indent));
438
439         StringUtils.newLine(buffer,indent);
440         buffer.append(((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)preferences).toString(indent));
441
442         StringUtils.newLine(buffer,indent);
443         buffer.append(((org.apache.pluto.portalImpl.om.common.impl.SecurityRoleRefSetImpl)initSecurityRoleRefs).toString(indent));
444
445         StringUtils.newLine(buffer,indent);
446         buffer.append(((ContentTypeSetImpl)contentTypes).toString(indent));
447
448         StringUtils.newLine(buffer,indent);
449         buffer.append(((DescriptionSetImpl)descriptions).toString(indent));
450
451         StringUtils.newLine(buffer,indent);
452         buffer.append(((DisplayNameSetImpl)displayNames).toString(indent));
453
454
455         if (servlet!=null) {
456             StringUtils.newLine(buffer,indent);
457             buffer.append("servlet:");
458             buffer.append(((org.apache.pluto.portalImpl.om.servlet.impl.ServletDefinitionImpl)servlet).toString(indent+2));
459         }
460         StringUtils.newLine(buffer,indent);
461         buffer.append("}");
462         return buffer.toString();
463     }
464
465
466 }
467
Popular Tags