KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > plugins > preferences > PortletPreferenceSetPlugin


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.portlet.plugins.preferences;
10
11 import javax.portlet.PreferencesValidator;
12
13 import org.jboss.portal.common.metadata.MetaData;
14 import org.jboss.portal.portlet.metadata.PortletPreferencesMetaData;
15 import org.jboss.portal.server.Application;
16 import org.jboss.portal.server.Component;
17 import org.jboss.portal.server.plugins.preferences.PreferenceSetPlugin;
18
19 /**
20  * An extension of the preferences plugin that adds the preference validator.
21  *
22  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
23  * @version $Revision: 1.2 $
24  */

25 public class PortletPreferenceSetPlugin
26    extends PreferenceSetPlugin
27 {
28
29    /** The preference validator instance. */
30    protected PreferencesValidator preferencesValidator;
31
32    public PortletPreferenceSetPlugin()
33    {
34    }
35
36    public void start() throws Exception JavaDoc
37    {
38       try
39       {
40          String JavaDoc preferencesValidatorClassName = ((PortletPreferencesMetaData)metaData).getPreferenceValidator();
41          if (preferencesValidatorClassName != null)
42          {
43             // The loader to load the validator class from
44
Component component = (Component)container;
45             Application application = component.getApplication();
46             ClassLoader JavaDoc loader = application.getClassLoader();
47
48             // Load the class
49
Class JavaDoc preferencesValidatorClass = loader.loadClass(preferencesValidatorClassName);
50             preferencesValidator = (PreferencesValidator)preferencesValidatorClass.newInstance();
51          }
52       }
53       catch (ClassNotFoundException JavaDoc e)
54       {
55          log.error("Class for preference validator not found", e);
56       }
57       catch (InstantiationException JavaDoc e)
58       {
59          log.error("Cannot instantiate preference validator", e);
60       }
61       catch (IllegalAccessException JavaDoc e)
62       {
63          throw new Error JavaDoc();
64       }
65
66       // Call super to build the preferences
67
super.start();
68    }
69
70    public void setMetaData(MetaData metaData)
71    {
72       super.setMetaData(metaData);
73    }
74
75    public PreferencesValidator getPreferencesValidator()
76    {
77       return preferencesValidator;
78    }
79
80 }
81
Popular Tags