1 25 26 package com.rift.coad.lib.configuration.xml; 27 28 33 public class XMLConfigurationType { 34 35 public final static long STRING_VALUE = 1; 37 public final static String STRING_ID = "string"; 38 public final static long LONG_VALUE = 2; 39 public final static String LONG_ID = "long"; 40 public final static long BOOLEAN_VALUE = 3; 41 public final static String BOOLEAN_ID = "boolean"; 42 43 private long type = 0; 45 46 52 public XMLConfigurationType(long type) throws XMLConfigurationException { 53 if ((type != STRING_VALUE) &&(type != LONG_VALUE)) { 54 throw new XMLConfigurationException( 55 "Invalid type information can either be [STRING] or [LONG]"); 56 } 57 this.type = type; 58 } 59 60 66 public XMLConfigurationType(String type) throws XMLConfigurationException { 67 setTypeFromString(type); 68 } 69 70 71 76 public long getType() { 77 return type; 78 } 79 80 81 87 public void setType(long type) throws XMLConfigurationException { 88 if ((type != STRING_VALUE) &&(type != LONG_VALUE) && 89 (type != BOOLEAN_VALUE)) { 90 throw new XMLConfigurationException( 91 "Invalid type information can either be [STRING] or [LONG] " + 92 "or [BOOLEAN]"); 93 } 94 this.type = type; 95 } 96 97 98 104 public void setTypeFromString(String type) 105 throws XMLConfigurationException { 106 if (type.equalsIgnoreCase(STRING_ID)) { 107 this.type = STRING_VALUE; 108 } else if (type.equalsIgnoreCase(LONG_ID)) { 109 this.type = LONG_VALUE; 110 } else if (type.equalsIgnoreCase(BOOLEAN_ID)) { 111 this.type = BOOLEAN_VALUE; 112 } else { 113 throw new XMLConfigurationException("Invalid type [" + type 114 + "] can either be [string] or [long]."); 115 } 116 } 117 118 124 public boolean equals(Object ref) { 125 if (!(ref instanceof XMLConfigurationType)) { 126 return false; 127 } else if (((XMLConfigurationType)ref).getType() == type) { 128 return true; 129 } 130 return false; 131 } 132 133 } 134 | Popular Tags |