1 7 8 9 package javax.management.openmbean; 10 11 12 import java.io.InvalidObjectException ; 15 import java.io.ObjectStreamException ; 16 import java.io.Serializable ; 17 import java.util.Map ; 18 import java.util.HashMap ; 19 20 23 24 43 public final class SimpleType 44 extends OpenType 45 implements Serializable { 46 47 48 static final long serialVersionUID = 2215577471957694503L; 49 50 53 57 public static final SimpleType VOID ; 58 59 63 public static final SimpleType BOOLEAN ; 64 65 69 public static final SimpleType CHARACTER ; 70 71 75 public static final SimpleType BYTE ; 76 77 81 public static final SimpleType SHORT ; 82 83 87 public static final SimpleType INTEGER ; 88 89 93 public static final SimpleType LONG ; 94 95 99 public static final SimpleType FLOAT ; 100 101 105 public static final SimpleType DOUBLE ; 106 107 111 public static final SimpleType STRING ; 112 113 117 public static final SimpleType BIGDECIMAL ; 118 119 123 public static final SimpleType BIGINTEGER ; 124 125 129 public static final SimpleType DATE ; 130 131 135 public static final SimpleType OBJECTNAME ; 136 137 138 static 141 { 142 SimpleType t; 143 try { 144 t = new SimpleType ("java.lang.Void"); 145 } catch (OpenDataException e) { 146 t = null; } 148 VOID = t; 149 try { 150 t = new SimpleType ("java.lang.Boolean"); 151 } catch (OpenDataException e) { 152 t = null; } 154 BOOLEAN = t; 155 try { 156 t = new SimpleType ("java.lang.Character"); 157 } catch (OpenDataException e) { 158 t = null; } 160 CHARACTER = t; 161 try { 162 t = new SimpleType ("java.lang.Byte"); 163 } catch (OpenDataException e) { 164 t = null; } 166 BYTE = t; 167 try { 168 t = new SimpleType ("java.lang.Short"); 169 } catch (OpenDataException e) { 170 t = null; } 172 SHORT = t; 173 try { 174 t = new SimpleType ("java.lang.Integer"); 175 } catch (OpenDataException e) { 176 t = null; } 178 INTEGER = t; 179 try { 180 t = new SimpleType ("java.lang.Long"); 181 } catch (OpenDataException e) { 182 t = null; } 184 LONG = t; 185 try { 186 t = new SimpleType ("java.lang.Float"); 187 } catch (OpenDataException e) { 188 t = null; } 190 FLOAT = t; 191 try { 192 t = new SimpleType ("java.lang.Double"); 193 } catch (OpenDataException e) { 194 t = null; } 196 DOUBLE = t; 197 try { 198 t = new SimpleType ("java.lang.String"); 199 } catch (OpenDataException e) { 200 t = null; } 202 STRING = t; 203 try { 204 t = new SimpleType ("java.math.BigDecimal"); 205 } catch (OpenDataException e) { 206 t = null; } 208 BIGDECIMAL = t; 209 try { 210 t = new SimpleType ("java.math.BigInteger"); 211 } catch (OpenDataException e) { 212 t = null; } 214 BIGINTEGER = t; 215 try { 216 t = new SimpleType ("java.util.Date"); 217 } catch (OpenDataException e) { 218 t = null; } 220 DATE = t; 221 try { 222 t = new SimpleType ("javax.management.ObjectName"); 223 } catch (OpenDataException e) { 224 t = null; } 226 OBJECTNAME = t; 227 } 228 229 private static final SimpleType [] typeArray = { 230 VOID, BOOLEAN, CHARACTER, BYTE, SHORT, INTEGER, LONG, FLOAT, 231 DOUBLE, STRING, BIGDECIMAL, BIGINTEGER, DATE, OBJECTNAME, 232 }; 233 234 235 private transient Integer myHashCode = null; private transient String myToString = null; 238 239 240 241 246 private SimpleType(String className) throws OpenDataException { 247 248 super(className, className, className); 251 } 252 253 254 255 256 270 public boolean isValue(Object obj) { 271 272 if (obj == null) { 275 return false; 276 } 277 278 return this.getClassName().equals(obj.getClass().getName()); 281 } 282 283 284 285 286 298 public boolean equals(Object obj) { 299 300 304 305 if (!(obj instanceof SimpleType )) 306 return false; 307 308 SimpleType other = (SimpleType ) obj; 309 310 return this.getClassName().equals(other.getClassName()); 313 } 314 315 325 public int hashCode() { 326 327 if (myHashCode == null) { 330 myHashCode = new Integer (this.getClassName().hashCode()); 331 } 332 333 return myHashCode.intValue(); 336 } 337 338 350 public String toString() { 351 352 if (myToString == null) { 355 myToString = this.getClass().getName()+ "(name="+ getTypeName() +")"; 356 } 357 358 return myToString; 361 } 362 363 private static final Map canonicalTypes = new HashMap (); 364 static { 365 for (int i = 0; i < typeArray.length; i++) { 366 final SimpleType type = typeArray[i]; 367 canonicalTypes.put(type, type); 368 } 369 } 370 371 381 public Object readResolve() throws ObjectStreamException { 382 final SimpleType canonical = (SimpleType ) canonicalTypes.get(this); 383 if (canonical == null) { 384 throw new InvalidObjectException ("Invalid SimpleType: " + this); 386 } 387 return canonical; 388 } 389 } 390 | Popular Tags |