1 9 package org.jboss.portal.server.plugins.preferences; 10 11 import java.util.HashMap ; 12 import java.util.Iterator ; 13 import java.util.Map ; 14 import java.util.Set ; 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 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 preferences; 37 protected PluginContainer container; 38 39 public PreferenceSetPlugin() 40 { 41 preferences = new HashMap (); 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 key) 55 { 56 return (Preference)preferences.get(key); 57 } 58 59 public Set keySet() 60 { 61 return preferences.keySet(); 62 } 63 64 public Value getValue(String key) 65 { 66 if (key == null) 67 { 68 throw new IllegalArgumentException ("key must not be null"); 69 } 70 Preference preference = (Preference)preferences.get(key); 71 return preference.getValue(); 72 } 73 74 public void setValue(String key, Value value) 75 { 76 if (key == null) 77 { 78 throw new IllegalArgumentException ("key must not be null"); 79 } 80 throw new UnsupportedOperationException (); 81 } 82 83 public boolean isReadOnly(String key) 84 { 85 if (key == null) 86 { 87 throw new IllegalArgumentException ("key must not be null"); 88 } 89 Preference preference = (Preference)preferences.get(key); 90 return preference.isReadOnly(); 91 } 92 93 public void setReadOnly(String key, boolean readOnly) 94 { 95 if (key == null) 96 { 97 throw new IllegalArgumentException ("key must not be null"); 98 } 99 throw new UnsupportedOperationException (); 100 } 101 102 public void start() throws Exception 103 { 104 for (Iterator i = this.metaData.iterator();i.hasNext();) 105 { 106 PreferenceMetaData preferenceMetaData = (PreferenceMetaData)i.next(); 107 String [] values = preferenceMetaData.getValues(); 108 109 if (values.length > 0) 111 { 112 String 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 |