1 9 package org.jboss.portal.server.plugins.preferences; 10 11 import java.io.Serializable ; 12 import java.util.HashMap ; 13 import java.util.Map ; 14 import java.util.Set ; 15 16 import org.jboss.portal.common.value.Value; 17 18 25 public class AbstractPreferenceSet implements PreferenceSet, Serializable 26 { 27 28 protected Map map; 29 30 public AbstractPreferenceSet() 31 { 32 this(new HashMap ()); 33 } 34 35 public AbstractPreferenceSet(Map map) 36 { 37 this.map = map; 38 } 39 40 public Set keySet() 41 { 42 return map.keySet(); 43 } 44 45 public Preference getPreference(String key) 46 { 47 if (key == null) 48 { 49 throw new IllegalArgumentException ("key must not be null"); 50 } 51 return (Preference)map.get(key); 52 } 53 54 public Value getValue(String key) 55 { 56 if (key == null) 57 { 58 throw new IllegalArgumentException ("key must not be null"); 59 } 60 Preference preference = getPreference(key); 61 if (preference != null) 62 { 63 return preference.getValue(); 64 } 65 else 66 { 67 return null; 68 } 69 } 70 71 public void setValue(String key, Value value) 72 { 73 if (key == null) 74 { 75 throw new IllegalArgumentException ("key must not be null"); 76 } 77 if (value == null) 78 { 79 map.remove(key); 80 } 81 else 82 { 83 AbstractPreference pref = (AbstractPreference)map.get(key); 84 if (pref == null) 85 { 86 pref = new AbstractPreference(key, value, false); 87 map.put(key, pref); 88 } 89 else 90 { 91 pref.setValue(value); 92 } 93 } 94 } 95 96 public boolean isReadOnly(String key) 97 { 98 if (key == null) 99 { 100 throw new IllegalArgumentException ("key must not be null"); 101 } 102 return false; 103 } 104 105 public void setReadOnly(String key, boolean readOnly) 106 { 107 throw new UnsupportedOperationException ("Should not be called"); 108 } 109 } 110 | Popular Tags |