1 23 24 package com.rift.coad.lib.configuration.xml; 26 27 32 public class XMLConfigurationEntry { 33 34 private String key = null; 36 private XMLConfigurationType type = null; 37 private String stringValue = null; 38 private long longValue = 0; 39 private boolean booleanValue = false; 40 41 44 public XMLConfigurationEntry() { 45 } 46 47 48 53 public String getKey() { 54 return this.key; 55 } 56 57 58 63 public void setKey(String key) { 64 this.key = key; 65 } 66 67 68 73 public XMLConfigurationType getType() { 74 return type; 75 } 76 77 78 83 public void setType(XMLConfigurationType type) { 84 this.type = type; 85 } 86 87 88 94 public String getStringValue() throws XMLConfigurationException { 95 if (type == null) { 96 throw new XMLConfigurationException( 97 "The type has not been initialized"); 98 } else if (XMLConfigurationType.STRING_VALUE == type.getType()) { 99 return stringValue; 100 } else { 101 throw new XMLConfigurationException( 102 "The value for [" + key + "]is not of type [string]."); 103 } 104 } 105 106 107 113 public void setStringValue(String value) throws XMLConfigurationException { 114 if (type == null) { 115 throw new XMLConfigurationException( 116 "The type has not been initialized"); 117 } else if (XMLConfigurationType.STRING_VALUE == type.getType()) { 118 stringValue = value; 119 } else { 120 throw new XMLConfigurationException( 121 "The value is not of type [string]."); 122 } 123 } 124 125 126 132 public long getLongValue() throws XMLConfigurationException { 133 if (type == null) { 134 throw new XMLConfigurationException( 135 "The type has not been initialized"); 136 } else if (XMLConfigurationType.LONG_VALUE == type.getType()) { 137 return longValue; 138 } else { 139 throw new XMLConfigurationException( 140 "The value is not of type [long]."); 141 } 142 } 143 144 145 151 public void setLongValue(long value) throws XMLConfigurationException { 152 if (type == null) { 153 throw new XMLConfigurationException( 154 "The type has not been initialized"); 155 } else if (XMLConfigurationType.LONG_VALUE == type.getType()) { 156 longValue = value; 157 } else { 158 throw new XMLConfigurationException( 159 "The value is not of type [long]."); 160 } 161 } 162 163 164 170 public boolean getBooleanValue() throws XMLConfigurationException { 171 if (type == null) { 172 throw new XMLConfigurationException( 173 "The type has not been initialized"); 174 } else if (XMLConfigurationType.BOOLEAN_VALUE == type.getType()) { 175 return booleanValue; 176 } else { 177 throw new XMLConfigurationException( 178 "The value is not of type [boolean]."); 179 } 180 } 181 182 183 189 public void setBooleanValue(boolean value) throws XMLConfigurationException { 190 if (type == null) { 191 throw new XMLConfigurationException( 192 "The type has not been initialized"); 193 } else if (XMLConfigurationType.BOOLEAN_VALUE == type.getType()) { 194 booleanValue = value; 195 } else { 196 throw new XMLConfigurationException( 197 "The value is not of type [boolean]."); 198 } 199 } 200 201 202 208 public void setValueFromString(String value) throws XMLConfigurationException { 209 try { 210 if (type == null) { 211 throw new XMLConfigurationException( 212 "The type has not been initialized"); 213 } else if (XMLConfigurationType.STRING_VALUE == type.getType()) { 214 stringValue = value; 215 } else if (XMLConfigurationType.BOOLEAN_VALUE == type.getType()) { 216 if (value.trim().equalsIgnoreCase("TRUE")) { 217 booleanValue = true; 218 } else { 219 booleanValue = false; 220 } 221 } else { 222 longValue = Long.parseLong(value); 223 } 224 } catch (Exception ex) { 225 throw new XMLConfigurationException("Failed to store the value [" + 226 value + "] because :" + ex.getMessage(),ex); 227 } 228 } 229 230 236 public boolean isIntiailized() { 237 if ((key == null) || (type == null)) { 238 return false; 239 } else if ((type.getType() == XMLConfigurationType.STRING_VALUE) && 240 stringValue == null) { 241 return false; 242 } 243 return true; 244 } 245 } 246 | Popular Tags |