KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > server > plugins > preferences > PreferenceSetPlugin


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.server.plugins.preferences;
10
11 import java.util.HashMap JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Map JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.apache.log4j.Logger;
17 import org.jboss.portal.common.metadata.MetaData;
18 import org.jboss.portal.common.plugin.PluginContainer;
19 import org.jboss.portal.common.value.StringValues;
20 import org.jboss.portal.common.value.Value;
21 import org.jboss.portal.server.metadata.PreferenceMetaData;
22 import org.jboss.portal.server.metadata.PreferencesMetaData;
23 import org.jboss.portal.server.plugins.PluginService;
24
25 /**
26  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
27  * @version $Revision: 1.2 $
28  */

29 public class PreferenceSetPlugin
30    extends PluginService
31    implements PreferenceSet
32 {
33
34    protected Logger log = Logger.getLogger(PreferenceSetPlugin.class);
35    protected PreferencesMetaData metaData;
36    protected Map JavaDoc preferences;
37    protected PluginContainer container;
38
39    public PreferenceSetPlugin()
40    {
41       preferences = new HashMap JavaDoc();
42    }
43
44    public void setPluginContainer(PluginContainer container)
45    {
46       this.container = container;
47    }
48
49    public PluginContainer getPluginContainer()
50    {
51       return container;
52    }
53
54    public Preference getPreference(String JavaDoc key)
55    {
56       return (Preference)preferences.get(key);
57    }
58
59    public Set JavaDoc keySet()
60    {
61       return preferences.keySet();
62    }
63
64    public Value getValue(String JavaDoc key)
65    {
66       if (key == null)
67       {
68          throw new IllegalArgumentException JavaDoc("key must not be null");
69       }
70       Preference preference = (Preference)preferences.get(key);
71       return preference.getValue();
72    }
73
74    public void setValue(String JavaDoc key, Value value)
75    {
76       if (key == null)
77       {
78          throw new IllegalArgumentException JavaDoc("key must not be null");
79       }
80       throw new UnsupportedOperationException JavaDoc();
81    }
82
83    public boolean isReadOnly(String JavaDoc key)
84    {
85       if (key == null)
86       {
87          throw new IllegalArgumentException JavaDoc("key must not be null");
88       }
89       Preference preference = (Preference)preferences.get(key);
90       return preference.isReadOnly();
91    }
92
93    public void setReadOnly(String JavaDoc key, boolean readOnly)
94    {
95       if (key == null)
96       {
97          throw new IllegalArgumentException JavaDoc("key must not be null");
98       }
99       throw new UnsupportedOperationException JavaDoc();
100    }
101
102    public void start() throws Exception JavaDoc
103    {
104       for (Iterator JavaDoc i = this.metaData.iterator();i.hasNext();)
105       {
106          PreferenceMetaData preferenceMetaData = (PreferenceMetaData)i.next();
107          String JavaDoc[] values = preferenceMetaData.getValues();
108
109          // We create a value if only that contains at least one value
110
if (values.length > 0)
111          {
112             String JavaDoc name = preferenceMetaData.getName();
113             boolean readOnly = preferenceMetaData.getReadOnly();
114             Value value = new StringValues(values);
115             Preference preference = new AbstractPreference(name, value, readOnly);
116             preferences.put(name, preference);
117          }
118       }
119    }
120
121    public void setMetaData(MetaData metaData)
122    {
123       this.metaData = (PreferencesMetaData)metaData;
124    }
125
126    public MetaData getMetaData()
127    {
128       return metaData;
129    }
130 }
131
Popular Tags