1 16 package org.apache.cocoon.portal.pluto.om.common; 17 18 import java.util.ArrayList ; 19 import java.util.Collection ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.apache.commons.lang.BooleanUtils; 24 import org.apache.pluto.om.common.Preference; 25 import org.apache.pluto.om.common.PreferenceCtrl; 26 import org.apache.pluto.util.StringUtils; 27 28 35 public class PreferenceImpl implements Preference, PreferenceCtrl, java.io.Serializable { 36 37 private final static String NULL_VALUE = "#*!0_NULL_0!*#"; 38 private final static String NULL_ARRAYENTRY = "#*!1_NULL_1!*#"; 39 40 private String name; 41 private ArrayList value; 42 private Boolean readOnly; 43 44 public PreferenceImpl() { 45 } 47 48 51 public String getName() { 52 return name; 53 } 54 55 58 public Iterator getValues() { 59 if (value.contains(NULL_VALUE)) { 61 return null; 62 } 63 64 ArrayList returnValue = new ArrayList (value.size()); 65 returnValue.addAll(value); 66 67 for (int i = 0; i < returnValue.size(); i++) { 69 if (NULL_ARRAYENTRY.equals(returnValue.get(i))) { 70 returnValue.set(i, null); 71 } 72 } 73 74 return returnValue.iterator(); 75 } 76 77 80 public boolean isReadOnly() { 81 if (readOnly == null) { 82 return false; 83 } 84 return readOnly.booleanValue(); 85 } 86 87 90 public boolean isValueSet() { 91 return value != null; 92 } 93 94 96 99 public void setName(String name) { 100 this.name = name; 101 } 102 103 106 public void setValues(java.util.List _value) { 107 if (this.value == null) { 108 this.value = new ArrayList (); 109 } else { 110 this.value.clear(); 111 } 112 113 List addValue = null; 114 115 if (_value == null) { 117 addValue = new ArrayList (1); 118 addValue.add(NULL_VALUE); 119 } else { 120 addValue = new ArrayList (_value.size()); 122 addValue.addAll(_value); 123 for (int i=0;i<addValue.size();i++) { 124 if (addValue.get(i) == null) { 125 addValue.set(i, NULL_ARRAYENTRY); 126 } 127 } 128 } 129 130 this.value.addAll(addValue); 131 } 132 133 136 public void setReadOnly(String readOnly) { 137 this.readOnly = BooleanUtils.toBooleanObject(readOnly); 138 } 139 140 142 144 public String getReadOnly() { 145 return BooleanUtils.toStringTrueFalse(BooleanUtils.toBoolean(readOnly)); 146 } 147 148 public Collection getCastorValues() { 149 return value; 150 } 151 152 public void setCastorValues(Collection _value) { 153 if (value == null) { 154 value = new ArrayList (); 155 } else { 156 value.clear(); 157 } 158 value.addAll(_value); 159 } 160 161 protected List getClonedCastorValuesAsList() { 162 List returnValue = new ArrayList (value.size()); 163 164 Iterator iter = value.iterator(); 165 while (iter.hasNext()) { 166 String value = (String ) iter.next(); 167 returnValue.add(value); 168 } 169 return returnValue; 170 } 171 172 public String toString() { 173 return toString(0); 174 } 175 176 public String toString(int indent) { 177 StringBuffer buffer = new StringBuffer (50); 178 StringUtils.newLine(buffer,indent); 179 buffer.append(getClass().toString()); 180 buffer.append(": name='"); 181 buffer.append(name); 182 buffer.append("', value='"); 183 184 if (value == null) { 185 buffer.append("null"); 186 } else { 187 StringUtils.newLine(buffer,indent); 188 buffer.append("{"); 189 Iterator iterator = value.iterator(); 190 if (iterator.hasNext()) { 191 StringUtils.newLine(buffer,indent); 192 buffer.append((String )iterator.next()); 193 } 194 while (iterator.hasNext()) { 195 StringUtils.indent(buffer,indent+2); 196 buffer.append((String )iterator.next()); 197 } 198 StringUtils.newLine(buffer,indent); 199 buffer.append("}"); 200 } 201 202 buffer.append("', isReadOnly='"); 203 buffer.append(isReadOnly()); 204 buffer.append("'"); 205 return buffer.toString(); 206 } 207 208 } 209 | Popular Tags |