1 9 package org.jboss.portal.core.impl.preferences; 10 11 import org.jboss.portal.common.value.StringValues; 12 import org.jboss.portal.common.value.Value; 13 import org.jboss.portal.server.plugins.preferences.Preference; 14 15 22 public class MappedPreference 23 implements Preference 24 { 25 26 private static final String [] EMPTY_STRING_ARRAY = new String [0]; 27 private static final Value EMPTY_VALUE = new StringValues(EMPTY_STRING_ARRAY); 28 29 private Integer id; 31 32 private String name; 34 35 private int type; 37 private String [] strings; 38 39 private Value value; 41 42 private boolean dirty; 46 47 public MappedPreference() 48 { 49 this.id = null; 50 this.name = null; 51 this.type = 0; 52 this.strings = EMPTY_STRING_ARRAY; 53 this.value = EMPTY_VALUE; 54 this.dirty = false; 55 } 56 57 public MappedPreference(String name) 58 { 59 this.id = null; 60 this.name = name; 61 this.type = 0; 62 this.strings = EMPTY_STRING_ARRAY; 63 this.value = EMPTY_VALUE; 64 } 65 66 71 protected Integer getID() 72 { 73 return id; 74 } 75 76 79 protected void setID(Integer id) 80 { 81 this.id = id; 82 } 83 84 90 public String getName() 91 { 92 return name; 93 } 94 95 98 protected void setName(String name) 99 { 100 this.name = name; 101 } 102 103 107 public int getType() 108 { 109 return type; 110 } 111 112 115 protected void setType(int type) 116 { 117 this.type = type; 118 this.dirty = true; 119 } 120 121 133 public String [] getStrings() 134 { 135 return strings; 136 } 137 138 public void setValue(Value value) 139 { 140 TypedStringArray tsa = ValueManager.createTypedStringArray(value); 141 this.value = value; 142 this.type = tsa.getType(); 143 this.strings = tsa.getStrings(); 144 } 145 146 149 private void setStrings(String [] strings) 150 { 151 this.strings = strings; 152 this.dirty = true; 153 } 154 155 public Value getValue() 156 { 157 if (dirty) 158 { 159 value = ValueManager.createValue(new TypedStringArray(type, strings)); 160 dirty = false; 161 } 162 return value; 163 } 164 165 168 public boolean isReadOnly() 169 { 170 return false; 171 } 172 173 176 public String toString() 177 { 178 StringBuffer buffer = new StringBuffer ("["); 179 buffer.append(id).append(",") 180 .append(name).append(","); 181 if (strings == null) 182 { 183 buffer.append("null,"); 184 } 185 else 186 { 187 buffer.append("("); 188 for (int i = 0;i < strings.length;i++) 189 { 190 String s = strings[i]; 191 buffer.append(i > 0 ? "," : "").append(s); 192 } 193 buffer.append("),"); 194 } 195 buffer.append(value).append("]"); 196 return buffer.toString(); 197 } 198 } 199 | Popular Tags |