1 package com.ca.directory.jxplorer.viewer.tableviewer; 2 3 import com.ca.directory.jxplorer.editor.*; 4 import com.ca.commons.cbutil.CBIntText; 5 6 import java.util.logging.Logger ; 7 8 9 16 17 public class AttributeValue implements editablebinary, editablestring 18 { 19 public Object value; 20 Object backup; 21 boolean changed; 22 boolean binary; 23 String id; 24 String [] options = null; 25 26 private final static Logger log = Logger.getLogger(AttributeValue.class.getName()); 27 28 31 32 boolean naming; 33 34 37 public AttributeValue(String ID, Object v) 38 { 39 id = ID; 40 value = v; 41 backup = v; 42 changed=false; 43 naming=false; 44 testBinary(); 45 } 46 47 50 51 public void setNamingStatus(boolean state) 52 { 53 naming = state; 54 } 55 56 59 60 public boolean isNaming() 61 { 62 return naming; 63 } 64 65 69 70 public boolean hasOptions() { return (options!=null); } 71 72 75 76 public void setOptions(String [] ops) 77 { 78 options = ops; 79 } 80 81 84 85 public String [] getOptions() { return options; } 86 87 88 91 public void update(Object data) 92 { 93 value = data; 94 testBinary(); 95 if (binary==false) 96 { 97 value = getStringValue(); } 99 changed = (value != backup); 101 } 102 103 106 public void setValue(byte[] b) 107 { 108 update(b); 109 } 110 111 112 116 public void setStringValue(String b) 117 { 118 update(b); 119 } 120 121 122 public byte[] getValue() 123 { 124 if (binary) 125 { 126 if (value instanceof String ) { 128 log.warning("warning - Attribute Value " + value + " mis represented as byte array data"); 129 return null; } 131 else 132 return ((byte[]) value); 133 } 134 else 135 return null; 136 } 137 138 139 142 143 public String getStringValue() 144 { 145 if (binary == false) 146 { 147 String val = ((String ) value); 148 if (naming) { 150 int len = val.length(); 151 val = val.trim(); 152 if (val.length() == 0 && len>0) 153 val = " "; 154 } 155 return val; 156 } 157 else 158 return null; 159 } 160 161 162 163 166 public void reset() 167 { 168 value = backup; 169 changed = false; 170 testBinary(); 171 } 172 173 177 public void setBinary(boolean bin) 178 { 179 binary = bin; 180 if (bin==true && value instanceof String ) 181 value = null; 182 } 183 184 188 public boolean testBinary() 189 { 190 if (binary==true) return true; 192 binary = (value==null)?false:((value instanceof String )?false:true); 193 return binary; 194 } 195 196 public boolean isEmpty() 197 { 198 if (value==null) return true; 199 if (binary) 200 { 201 if (value instanceof byte[]) 202 if (((byte[])value).length == 0) 203 return true; 205 return false; 206 } 207 208 return (value.toString().length()==0); 209 } 210 211 216 217 public String toString() 218 { 219 if (value == null) return " "; 221 if (value.toString().length() == 0) return " "; 225 if (binary) return CBIntText.get("(non string data)"); 226 227 return value.toString(); 228 } 229 230 public String getID() { return id; } 231 public boolean changed() { return changed; } 232 public Object value() { return value; } 233 public Object backup() { return backup; } 234 public boolean isBinary() { return binary; } 235 } | Popular Tags |