View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.om.portlet.impl;
18  
19  import java.io.IOException;
20  import java.io.Serializable;
21  import java.util.ArrayList;
22  import java.util.Arrays;
23  import java.util.Collection;
24  import java.util.Iterator;
25  import java.util.List;
26  import java.util.Locale;
27  import java.util.StringTokenizer;
28  import java.util.prefs.BackingStoreException;
29  import java.util.prefs.Preferences;
30  
31  import javax.portlet.PreferencesValidator;
32  
33  import org.apache.jetspeed.components.portletregistry.PortletRegistry;
34  import org.apache.jetspeed.components.portletregistry.RegistryException;
35  import org.apache.jetspeed.factory.PortletFactory;
36  import org.apache.jetspeed.om.common.GenericMetadata;
37  import org.apache.jetspeed.om.common.MutableDescription;
38  import org.apache.jetspeed.om.common.MutableDisplayName;
39  import org.apache.jetspeed.om.common.ParameterComposite;
40  import org.apache.jetspeed.om.common.Support;
41  import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
42  import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
43  import org.apache.jetspeed.om.common.preference.PreferenceComposite;
44  import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
45  import org.apache.jetspeed.om.common.preference.PreferencesValidatorFactory;
46  import org.apache.jetspeed.om.impl.DescriptionImpl;
47  import org.apache.jetspeed.om.impl.DescriptionSetImpl;
48  import org.apache.jetspeed.om.impl.DisplayNameSetImpl;
49  import org.apache.jetspeed.om.impl.LanguageImpl;
50  import org.apache.jetspeed.om.impl.LanguageSetImpl;
51  import org.apache.jetspeed.om.impl.ParameterSetImpl;
52  import org.apache.jetspeed.om.impl.PortletDescriptionImpl;
53  import org.apache.jetspeed.om.impl.PortletDisplayNameImpl;
54  import org.apache.jetspeed.om.impl.PortletParameterSetImpl;
55  import org.apache.jetspeed.om.impl.SecurityRoleRefImpl;
56  import org.apache.jetspeed.om.impl.SecurityRoleRefSetImpl;
57  import org.apache.jetspeed.om.preference.impl.PrefsPreference;
58  import org.apache.jetspeed.om.preference.impl.PrefsPreferenceSetImpl;
59  import org.apache.jetspeed.util.HashCodeBuilder;
60  import org.apache.jetspeed.util.JetspeedLongObjectID;
61  import org.apache.pluto.om.common.Description;
62  import org.apache.pluto.om.common.DescriptionSet;
63  import org.apache.pluto.om.common.DisplayName;
64  import org.apache.pluto.om.common.DisplayNameSet;
65  import org.apache.pluto.om.common.Language;
66  import org.apache.pluto.om.common.LanguageSet;
67  import org.apache.pluto.om.common.ObjectID;
68  import org.apache.pluto.om.common.Parameter;
69  import org.apache.pluto.om.common.ParameterSet;
70  import org.apache.pluto.om.common.Preference;
71  import org.apache.pluto.om.common.PreferenceSet;
72  import org.apache.pluto.om.common.SecurityRoleRef;
73  import org.apache.pluto.om.common.SecurityRoleRefSet;
74  import org.apache.pluto.om.portlet.ContentType;
75  import org.apache.pluto.om.portlet.ContentTypeSet;
76  import org.apache.pluto.om.portlet.PortletApplicationDefinition;
77  import org.apache.pluto.om.servlet.ServletDefinition;
78  
79  /***
80   * 
81   * PortletDefinitionImpl
82   * 
83   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
84   * @version $Id: PortletDefinitionImpl.java 517124 2007-03-12 08:10:25Z ate $
85   *  
86   */
87  public class PortletDefinitionImpl implements PortletDefinitionComposite, PreferencesValidatorFactory, Serializable, Support
88  {
89      /***
90       * This is a static instance of the PortletREgistry that can be used by
91       * all instances of the PortletDefinitionImpl to support the 
92       * PortletDefintionCtrl.store() method.
93       * 
94       */
95      protected static PortletRegistry registry;
96      protected static PortletFactory  portletFactory;
97      
98      private Long id;
99      private JetspeedLongObjectID oid;
100     private String className;
101     private String name;
102     private String portletIdentifier;
103     private Collection languageSet = null;
104     private LanguageSetImpl langListWrapper = new LanguageSetImpl();
105     private Collection parameterSet;
106     private ParameterSetImpl paramListWrapper = new PortletParameterSetImpl();
107     private Collection securityRoleRefSet;
108     private SecurityRoleRefSetImpl secListWrapper = new SecurityRoleRefSetImpl();
109     /*** User attribute set. * */
110     //private Collection userAttributeSet;
111     /*** User attribute ref set. * */
112     //private Collection userAttributeRefSet;
113     private String preferenceValidatorClassname;
114     private Collection displayNames;
115     private DisplayNameSetImpl DNListWrapper = new DisplayNameSetImpl();
116     private Collection descriptions;
117     private DescriptionSetImpl descListWrapper = new DescriptionSetImpl(DescriptionImpl.TYPE_PORTLET);
118     private String resourceBundle;
119     private ArrayList supportedLocales;
120 
121     private Collection contentTypes;
122     private ContentTypeSetImpl ctListWrapper = new ContentTypeSetImpl();
123     protected List portletEntities;
124 
125     /*** PortletApplicationDefinition this PortletDefinition belongs to */
126     private MutablePortletApplication app;
127 
128     protected long appId;
129     private String expirationCache;
130 
131     /*** Metadata property */
132     private Collection metadataFields = null;
133     private PrefsPreferenceSetImpl preferenceSet;
134 
135     private String jetspeedSecurityConstraint = null;
136     
137     public PortletDefinitionImpl()
138     {
139         super();
140         try
141         {
142             parameterSet = new ArrayList();
143             securityRoleRefSet = new ArrayList();
144             //userAttributeSet = new ArrayList();
145             //userAttributeRefSet = new ArrayList();
146             contentTypes = new ArrayList();
147             supportedLocales= new ArrayList();
148         }
149         catch (RuntimeException e)
150         {
151 //            System.out.println("Failed to fully construct Portlet Definition");
152             e.printStackTrace();
153         }
154     }
155 
156     /***
157      * @see org.apache.pluto.om.portlet.PortletDefinition#getId()
158      */
159     public ObjectID getId()
160     {
161         if ( oid == null && id != null )
162         {
163             oid = new JetspeedLongObjectID(id);
164         }
165         return oid;
166     }
167 
168     /***
169      * @see org.apache.pluto.om.portlet.PortletDefinition#getClassName()
170      */
171     public String getClassName()
172     {
173         return className;
174     }
175 
176     /***
177      * @see org.apache.pluto.om.portlet.PortletDefinition#getName()
178      */
179     public String getName()
180     {
181         return name;
182     }
183 
184     /***
185      * @see org.apache.pluto.om.portlet.PortletDefinition#getLanguageSet()
186      */
187     public LanguageSet getLanguageSet()
188     {
189         if ( languageSet != null )
190         {
191             langListWrapper.setInnerCollection(languageSet);
192         }
193         langListWrapper.setClassLoader(getPortletClassLoader());
194         
195         return langListWrapper;
196     }
197 
198     /***
199      * @see org.apache.pluto.om.portlet.PortletDefinition#getInitParameterSet()
200      */
201     public ParameterSet getInitParameterSet()
202     {
203         paramListWrapper.setInnerCollection(parameterSet);
204         return paramListWrapper;
205     }
206 
207     /***
208      * @see org.apache.pluto.om.portlet.PortletDefinition#getInitSecurityRoleRefSet()
209      */
210     public SecurityRoleRefSet getInitSecurityRoleRefSet()
211     {
212         secListWrapper.setInnerCollection(securityRoleRefSet);
213         return secListWrapper;
214     }
215 
216     /***
217      * @see org.apache.pluto.om.portlet.PortletDefinition#getPreferenceSet()
218      */
219     public PreferenceSet getPreferenceSet()
220     {
221         try
222         {
223             if (preferenceSet == null)
224             {
225                
226                 if(app == null)
227                 {
228                     throw new IllegalStateException("Portlet Application must be defined before preferences can be accessed");
229                 }
230                 
231                 Preferences prefNode = PrefsPreference.createPrefenceNode(this);
232                 preferenceSet = new PrefsPreferenceSetImpl(prefNode, this);
233             }
234         }
235         catch (BackingStoreException e)
236         {
237             String msg = "Preference backing store failed: " + e.toString();
238             IllegalStateException ise = new IllegalStateException(msg);
239             ise.initCause(e);
240             throw ise;
241         }
242 
243         return preferenceSet;
244     }
245 
246     /***
247      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setPreferenceSet(org.apache.pluto.om.common.PreferenceSet)
248      */
249     public void setPreferenceSet( PreferenceSet preferences )
250     {
251         this.preferenceSet = (PrefsPreferenceSetImpl) preferences;
252     }
253 
254     /***
255      * @see org.apache.pluto.om.portlet.PortletDefinition#getContentTypeSet()
256      */
257     public ContentTypeSet getContentTypeSet()
258     {
259         ctListWrapper.setInnerCollection(contentTypes);
260         return ctListWrapper;
261     }
262 
263     /***
264      * @see org.apache.pluto.om.portlet.PortletDefinition#getPortletApplicationDefinition()
265      */
266     public PortletApplicationDefinition getPortletApplicationDefinition()
267     {
268         return app;
269     }
270 
271     /***
272      * @see org.apache.pluto.om.portlet.PortletDefinition#getServletDefinition()
273      */
274     public ServletDefinition getServletDefinition()
275     {
276         // TODO Auto-generated method stub
277         return null;
278     }
279 
280     /***
281      * @see org.apache.pluto.om.portlet.PortletDefinition#getExpirationCache()
282      */
283     public String getExpirationCache()
284     {
285         return expirationCache;
286     }
287 
288     /***
289      * @see org.apache.pluto.om.portlet.PortletDefinition#getPortletClassLoader()
290      */
291     public ClassLoader getPortletClassLoader()
292     {
293         if ( portletFactory != null )
294         {
295             return portletFactory.getPortletApplicationClassLoader(app);
296         }
297         return null;
298     }
299 
300     /***
301      * @see org.apache.pluto.om.portlet.PortletDefinitionCtrl#setId(java.lang.String)
302      */
303     public void setId( String oid )
304     {
305         throw new UnsupportedOperationException();
306     }
307 
308     /***
309      * @see org.apache.pluto.om.portlet.PortletDefinitionCtrl#setClassName(java.lang.String)
310      */
311     public void setClassName( String className )
312     {
313         this.className = className;
314     }
315 
316     /***
317      * @see org.apache.pluto.om.portlet.PortletDefinitionCtrl#setName(java.lang.String)
318      */
319     public void setName( String name )
320     {
321         this.name = name;
322     }
323 
324     /***
325      * @see org.apache.pluto.om.portlet.PortletDefinitionCtrl#setPortletClassLoader(java.lang.ClassLoader)
326      */
327     public void setPortletClassLoader( ClassLoader loader )
328     {
329       // no-op: ClassLoader is only stored in the PortletFactory
330       ;
331     }
332 
333     /***
334      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addLanguage(org.apache.pluto.om.common.Language)
335      */
336     public void addLanguage( Language lang )
337     {
338         if (languageSet == null)
339         {
340             languageSet = new ArrayList();
341         }
342         langListWrapper.setInnerCollection(languageSet);
343         langListWrapper.add(lang);
344     }
345     
346     /***
347      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addLanguage(java.lang.String, java.lang.String, java.lang.String, java.util.Locale)
348      */
349     public void addLanguage(String title, String shortTitle, String keywords, Locale locale)
350     {
351         LanguageImpl lang = new LanguageImpl();
352         lang.setTitle(title);
353         lang.setShortTitle(shortTitle);
354         lang.setKeywords(keywords);
355         lang.setLocale(locale);
356         
357         addLanguage(lang);
358     }
359 
360     /***
361      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setContentTypeSet(org.apache.pluto.om.portlet.ContentTypeSet)
362      */
363     public void setContentTypeSet( ContentTypeSet contentTypes )
364     {
365         this.contentTypes = ((ContentTypeSetImpl) contentTypes).getInnerCollection();
366     }
367 
368     /***
369      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setInitParameterSet(org.apache.pluto.om.common.ParameterSet)
370      */
371     public void setInitParameterSet( ParameterSet parameters )
372     {
373         this.parameterSet = ((ParameterSetImpl) parameters).getInnerCollection();
374     }
375 
376     /***
377      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setInitSecurityRoleRefSet(org.apache.pluto.om.common.SecurityRoleRefSet)
378      */
379     public void setInitSecurityRoleRefSet( SecurityRoleRefSet securityRefs )
380     {
381         this.securityRoleRefSet = ((SecurityRoleRefSetImpl) securityRefs).getInnerCollection();
382     }
383 
384     /***
385      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setLanguageSet(org.apache.pluto.om.common.LanguageSet)
386      */
387     public void setLanguageSet( LanguageSet languages )
388     {
389         this.languageSet = ((LanguageSetImpl) languages).getInnerCollection();
390     }
391 
392     /***
393      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addUserAttribute(org.apache.jetspeed.om.common.UserAttribute)
394      */
395     /*
396      * public void addUserAttribute(UserAttribute userAttribute) {
397      * this.userAttributeSet.add(userAttribute); }
398      *  
399      *//**
400         * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setUserAttributeSet(java.util.Collection)
401         */
402     /*
403      * public void setUserAttributeSet(Collection userAttributeSet) {
404      * this.userAttributeSet = userAttributeSet; }
405      *  
406      *//**
407         * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#getUserAttributeSet()
408         */
409     /*
410      * public Collection getUserAttributeSet() { return this.userAttributeSet; }
411      *  
412      *//**
413         * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addUserAttributeRef(org.apache.jetspeed.om.common.UserAttributeRef)
414         */
415     /*
416      * public void addUserAttributeRef(UserAttributeRef userAttributeRef) {
417      * System.out.println("_______IN addUserAttributeRef");
418      * this.userAttributeRefSet.add(userAttributeRef); }
419      *  
420      *//**
421         * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setUserAttributeSet(java.util.Collection)
422         */
423     /*
424      * public void setUserAttributeRefSet(Collection userAttributeRefSet) {
425      * this.userAttributeRefSet = userAttributeRefSet; }
426      *  
427      *//**
428         * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#getUserAttributeRefSet()
429         */
430     /*
431      * public Collection getUserAttributeRefSet() { return
432      * this.userAttributeRefSet; }
433      */
434     /***
435      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setInitParameter(java.lang.String,
436      *      java.lang.String, java.lang.String)
437      */
438     public ParameterComposite addInitParameter( String name, String value, DescriptionSet description )
439     {
440         ParameterComposite pc = addInitParameter(name, value);
441         pc.setDescriptionSet(description);
442         return pc;
443     }
444 
445     /***
446      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addInitParameter(java.lang.String,
447      *      java.lang.String, java.lang.String, java.util.Locale)
448      */
449     public ParameterComposite addInitParameter( String name, String value, String description, Locale locale )
450     {
451         ParameterComposite param = addInitParameter(name, value);
452         param.addDescription(locale, description);
453         return param;
454     }
455 
456     public void addInitParameter( Parameter parameter )
457     {
458         parameterSet.add(parameter);
459     }
460 
461     /***
462      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setInitParameter(java.lang.String,
463      *      java.lang.String)
464      */
465     public ParameterComposite addInitParameter( String name, String value )
466     {
467         paramListWrapper.setInnerCollection(parameterSet);
468         return (ParameterComposite) paramListWrapper.add(name, value);
469     }
470 
471     /***
472      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setExpirationCache(java.lang.String)
473      */
474     public void setExpirationCache( String cache )
475     {
476         expirationCache = cache;
477     }
478 
479     /***
480      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addContentType(org.apache.pluto.om.portlet.ContentType)
481      */
482     public void addContentType( ContentType cType )
483     {
484         ctListWrapper.setInnerCollection(contentTypes);
485         ctListWrapper.addContentType(cType);
486     }
487     
488     /***
489      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addContentType(java.lang.String, java.lang.String[])
490      */
491     public void addContentType(String contentType, Collection modes)
492     {
493         ContentTypeImpl ct = new ContentTypeImpl();
494         ct.setContentType(contentType);
495         ct.setPortletModes(modes);
496         
497         addContentType(ct);
498     }
499 
500     /***
501      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addPreference(java.lang.String,
502      *      java.util.Collection)
503      */
504     public PreferenceComposite addPreference( String name, String[] values )
505     {
506         return (PreferenceComposite) ((PrefsPreferenceSetImpl) getPreferenceSet()).add(name, Arrays.asList(values));
507     }
508 
509     public void setPortletIdentifier( String portletIdentifier )
510     {
511         this.portletIdentifier = portletIdentifier;
512     }
513 
514     public String getPortletIdentifier()
515     {
516         return this.portletIdentifier;
517     }
518 
519     /***
520      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setPortletApplicationDefinition(org.apache.pluto.om.portlet.PortletApplicationDefinition)
521      */
522     public void setPortletApplicationDefinition( PortletApplicationDefinition pad )
523     {
524         app = (MutablePortletApplication) pad;
525     }
526 
527     /***
528      * @see java.lang.Object#equals(java.lang.Object)
529      */
530     public boolean equals( Object obj )
531     {
532         if (obj != null && obj.getClass().equals(getClass()))
533         {
534             PortletDefinitionImpl pd = (PortletDefinitionImpl) obj;
535             boolean sameId = (id != null && pd.id != null && id.equals(pd.id));
536             if (sameId)
537             {
538                 return true;
539             }
540             boolean sameAppId = (appId == pd.appId);
541             boolean sameName = (pd.getName() != null && name != null && pd.getName().equals(name));
542             return sameName && sameAppId;
543         }
544         return false;
545     }
546 
547     /***
548      * @see java.lang.Object#hashCode()
549      */
550     public int hashCode()
551     {
552         HashCodeBuilder hasher = new HashCodeBuilder(1, 3);
553         hasher.append(name);
554         if (app != null)
555         {
556             if ( getId() != null )
557             {
558               hasher.append(getId().toString());
559             }
560             hasher.append(app.getName());
561         }
562         return hasher.toHashCode();
563     }
564 
565     /***
566      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#getUniqueName()
567      */
568     public String getUniqueName()
569     {
570         if (app != null && name != null)
571         {
572             return app.getName() + "::" + name;
573         }
574         else
575         {
576             throw new IllegalStateException(
577                     "Cannot generate a unique portlet name until the application and portlet name have been set");
578         }
579     }
580 
581     /***
582      * @see org.apache.pluto.om.portlet.PortletDefinition#getDescription(java.util.Locale)
583      */
584     public Description getDescription( Locale arg0 )
585     {
586         if (descriptions != null)
587         {
588             descListWrapper.setInnerCollection(descriptions);
589             return descListWrapper.get(arg0);
590         }
591         return null;
592     }
593 
594     /***
595      * @see org.apache.pluto.om.portlet.PortletDefinition#getDisplayName(java.util.Locale)
596      */
597     public DisplayName getDisplayName( Locale arg0 )
598     {
599         if (displayNames != null)
600         {
601             DNListWrapper.setInnerCollection(displayNames);
602             return DNListWrapper.get(arg0);
603         }
604         return null;
605     }
606 
607     /***
608      * @see org.apache.pluto.om.portlet.PortletDefinitionCtrl#setDescriptions(org.apache.pluto.om.common.DescriptionSet)
609      */
610     public void setDescriptions( DescriptionSet arg0 )
611     {
612         this.descriptions = ((DescriptionSetImpl) arg0).getInnerCollection();
613     }
614 
615     /***
616      * @see org.apache.pluto.om.portlet.PortletDefinitionCtrl#setDisplayNames(org.apache.pluto.om.common.DisplayNameSet)
617      */
618     public void setDisplayNames( DisplayNameSet arg0 )
619     {
620         this.displayNames = ((DisplayNameSetImpl) arg0).getInnerCollection();
621     }
622 
623     /***
624      * Returns localized text of this PortletDefinitions display name.
625      * 
626      * @param locale
627      *            Locale to get the display name for
628      * @return Localized text string of the display name or <code>null</code>
629      *         if no DisplayName exists for this locale
630      */
631     public String getDisplayNameText( Locale locale )
632     {
633         DisplayName dn = getDisplayName(locale);
634         if (dn != null)
635         {
636             return dn.getDisplayName();
637         }
638         return null;
639     }
640 
641     /***
642      * Returns localized text of this PortletDefinitions description.
643      * 
644      * @param locale
645      *            Locale to get the description for
646      * @return Localized text string of the display name or <code>null</code>
647      *         if no Description exists for this locale
648      */
649     public String getDescriptionText( Locale locale )
650     {
651         Description desc = getDescription(locale);
652         if (desc != null)
653         {
654             return desc.getDescription();
655         }
656         return null;
657     }
658     
659     public DescriptionSet getDescriptionSet()
660     {
661         return this.descListWrapper;
662     }
663 
664     /***
665      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addDescription(java.util.Locale,
666      *      java.lang.String)
667      */
668     public void addDescription( Locale locale, String description )
669     {
670         if (descriptions == null)
671         {
672             descriptions = new ArrayList();
673         }
674         descListWrapper.setInnerCollection(descriptions);
675         MutableDescription descObj = new PortletDescriptionImpl();
676         descObj.setLocale(locale);
677         descObj.setDescription(description);
678         descListWrapper.addDescription(descObj);
679     }
680 
681     public void addDescription( Description description )
682     {
683         if (descriptions == null)
684         {
685             descriptions = new ArrayList();
686         }
687         descListWrapper.setInnerCollection(descriptions);
688         descListWrapper.addDescription(description);
689     }
690 
691     /***
692      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addDisplayName(java.util.Locale,
693      *      java.lang.String)
694      */
695     public void addDisplayName( Locale locale, String displayName )
696     {
697         if (displayNames == null)
698         {
699             displayNames = new ArrayList();
700         }
701         DNListWrapper.setInnerCollection(displayNames);
702         MutableDisplayName dn = new PortletDisplayNameImpl();
703         dn.setLocale(locale);
704         dn.setDisplayName(displayName);
705         DNListWrapper.addDisplayName(dn);
706     }
707 
708     public void addDisplayName( DisplayName displayName )
709     {
710         if (displayNames == null)
711         {
712             displayNames = new ArrayList();
713         }
714         DNListWrapper.setInnerCollection(displayNames);
715         DNListWrapper.addDisplayName(displayName);
716     }
717     
718     public DisplayNameSet getDisplayNameSet()
719     {
720         if ( displayNames != null )
721         {
722             DNListWrapper.setInnerCollection(displayNames);
723         }
724         return DNListWrapper;
725     }
726 
727     /***
728      * <p>
729      * store will attempt to perform an atomic persistence call against this
730      * portletDefinition.
731      * </p>
732      * 
733      * @see org.apache.pluto.om.portlet.PortletDefinitionCtrl#store()
734      * @throws java.io.IOException
735      */
736     public void store() throws IOException
737     {
738         if(registry != null)
739         {
740             try
741             {
742                 registry.savePortletDefinition(this);
743             }
744             catch (RegistryException e)
745             {
746                 IOException ioe = new IOException("Failed to store portlet definition: "+e.getMessage());
747                 ioe.initCause(e);
748             }
749         }
750         else
751         {
752             throw new IllegalStateException("The portlet registry for PortletDefinitionImpl has not been set.  "+
753                                              "Please invoke PortletDefinitionImpl.setPortletRegistry before invoking the store() method.");
754         }
755     }
756 
757     /***
758      * <p>
759      * getPreferenceValidatorClassname
760      * </p>
761      * 
762      * @return
763      */
764     public String getPreferenceValidatorClassname()
765     {
766         return preferenceValidatorClassname;
767     }
768 
769     /***
770      * <p>
771      * setPreferenceValidatorClassname
772      * </p>
773      * 
774      * @param string
775      *  
776      */
777     public void setPreferenceValidatorClassname( String string )
778     {
779         preferenceValidatorClassname = string;
780     }
781 
782     /***
783      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addPreference(org.apache.pluto.om.common.Preference)
784      * @param preference
785      */
786     public void addPreference( Preference preference )
787     {
788         Iterator valueItr = preference.getValues();
789         ArrayList list = new ArrayList();
790         while (valueItr.hasNext())
791         {
792             list.add(valueItr.next());
793         }
794 
795         PreferenceComposite newPref = (PreferenceComposite) ((PreferenceSetComposite) getPreferenceSet()).add(
796                 preference.getName(), list);
797 
798         Iterator descItr = newPref.getDescriptions();
799         while (descItr.hasNext())
800         {
801             Description desc = (Description) descItr.next();
802             newPref.addDescription(desc.getLocale(), desc.getDescription());
803         }
804 
805     }
806 
807     /***
808      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addSecurityRoleRef(org.apache.pluto.om.common.SecurityRoleRef)
809      */
810     public void addSecurityRoleRef( SecurityRoleRef securityRef )
811     {
812         secListWrapper.setInnerCollection(securityRoleRefSet);
813         secListWrapper.add(securityRef);
814     }
815     
816     /***
817      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#addSecurityRoleRef(java.lang.String, java.lang.String)
818      */
819     public SecurityRoleRef addSecurityRoleRef(String roleName, String roleLink)
820     {
821         SecurityRoleRefImpl ref = new SecurityRoleRefImpl();
822         ref.setRoleName(roleName);
823         ref.setRoleLink(roleLink);
824         
825         addSecurityRoleRef(ref);
826         
827         return ref;
828     }
829 
830     /***
831      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getMetadata()
832      */
833     public GenericMetadata getMetadata()
834     {
835         if (metadataFields == null)
836         {
837             metadataFields = new ArrayList();
838         }
839 
840         GenericMetadata metadata = new PortletDefinitionMetadataImpl();
841         metadata.setFields(metadataFields);
842 
843         return metadata;
844     }
845 
846     /***
847      * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setMetadata(org.apache.jetspeed.om.common.GenericMetadata)
848      */
849     public void setMetadata( GenericMetadata metadata )
850     {
851         this.metadataFields = metadata.getFields();
852     }
853 
854     /***
855      * @return
856      */
857     protected Collection getMetadataFields()
858     {
859         return metadataFields;
860     }
861 
862     /***
863      * @param collection
864      */
865     protected void setMetadataFields( Collection metadataFields )
866     {
867         this.metadataFields = metadataFields;
868     }
869     
870     /***
871      * @return
872      */
873     public String getResourceBundle()
874     {
875         return resourceBundle;
876     }
877 
878     /***
879      * @param string
880      */
881     public void setResourceBundle(String string)
882     {
883         resourceBundle = string;
884     }
885     
886     public Collection getSupportedLocales()
887     {
888         return supportedLocales;
889     }
890 
891     public void addSupportedLocale(String locale)
892     {
893         // parse locale String
894         StringTokenizer tokenizer = new StringTokenizer(locale, "_");
895         String[] localeDef = new String[3];
896         for (int i = 0; i < 3; i++)
897         {
898             if (tokenizer.hasMoreTokens())
899             {
900                 localeDef[i] = tokenizer.nextToken();
901             }
902             else
903             {
904                 localeDef[i] = "";
905             }
906         }
907         supportedLocales.add(new Locale(localeDef[0], localeDef[1], localeDef[2]));
908     }
909 
910     /* (non-Javadoc)
911      * @see org.apache.jetspeed.om.Support#postLoad(java.lang.Object)
912      */
913     public void postLoad(Object parameter) throws Exception
914     {
915         if (resourceBundle != null)
916         {
917             langListWrapper.setResources(resourceBundle);
918         }
919         
920         if (parameter instanceof ClassLoader)
921         {
922             // newly created PD from portlet.xml
923             langListWrapper.setClassLoader((ClassLoader) parameter);
924             // create supported locale languages and
925             // retrieve title, shortTitle and keywords from resourceBundle if defined
926             langListWrapper.postLoad(this.supportedLocales);
927         }
928         else
929         {
930             // loaded from persistent store
931             langListWrapper.setClassLoader(getPortletClassLoader());
932         }
933     }
934     
935     public static void setPortletRegistry(PortletRegistry registry)
936     {
937         PortletDefinitionImpl.registry = registry;
938     }
939 
940     public static void setPortletFactory(PortletFactory portletFactory)
941     {
942         PortletDefinitionImpl.portletFactory = portletFactory;
943     }
944 
945     public PreferencesValidator getPreferencesValidator()
946     {
947         if ( portletFactory != null )
948         {
949             return portletFactory.getPreferencesValidator(this);
950         }
951         return null;
952     }
953 
954     /* (non-Javadoc)
955      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#getJetspeedSecurityConstraint()
956      */
957     public String getJetspeedSecurityConstraint()
958     {
959         return this.jetspeedSecurityConstraint;
960     }
961 
962     /* (non-Javadoc)
963      * @see org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite#setJetspeedSecurityConstraint(java.lang.String)
964      */
965     public void setJetspeedSecurityConstraint(String constraint)
966     {
967         this.jetspeedSecurityConstraint = constraint;
968     }
969 }