1 5 package com.tc.object.dna.impl; 6 7 import com.tc.object.loaders.ClassProvider; 8 9 import java.io.Serializable ; 10 import java.util.HashMap ; 11 import java.util.Map ; 12 13 public class ClassInstance implements Serializable { 14 private final static Map PRIMITIVE_TYPE_MAP = new HashMap (); 15 16 private final UTF8ByteDataHolder name; 17 private final UTF8ByteDataHolder loaderDef; 18 19 static { 20 PRIMITIVE_TYPE_MAP.put(Integer.TYPE.getName(), Integer.TYPE); 21 PRIMITIVE_TYPE_MAP.put(Short.TYPE.getName(), Short.TYPE); 22 PRIMITIVE_TYPE_MAP.put(Long.TYPE.getName(), Long.TYPE); 23 PRIMITIVE_TYPE_MAP.put(Byte.TYPE.getName(), Byte.TYPE); 24 PRIMITIVE_TYPE_MAP.put(Double.TYPE.getName(), Double.TYPE); 25 PRIMITIVE_TYPE_MAP.put(Float.TYPE.getName(), Float.TYPE); 26 PRIMITIVE_TYPE_MAP.put(Double.TYPE.getName(), Double.TYPE); 27 PRIMITIVE_TYPE_MAP.put(Boolean.TYPE.getName(), Boolean.TYPE); 28 PRIMITIVE_TYPE_MAP.put(Void.TYPE.getName(), Void.TYPE); 29 } 30 31 private static Class getPrimitiveClass(String className) { 32 return (Class )PRIMITIVE_TYPE_MAP.get(className); 33 } 34 35 ClassInstance(String className, String loaderDefinition) { 37 this(new UTF8ByteDataHolder(className), new UTF8ByteDataHolder(loaderDefinition)); 38 } 39 40 public ClassInstance(UTF8ByteDataHolder className, UTF8ByteDataHolder loaderDefinition) { 41 name = className; 42 loaderDef = loaderDefinition; 43 } 44 45 public Class asClass(ClassProvider classProvider) throws ClassNotFoundException { 46 String classLoaderdef = loaderDef.asString(); 47 String className = name.asString(); 48 Class clazz = getPrimitiveClass(className); 49 if (clazz != null) { return clazz; } 50 return classProvider.getClassFor(className, classLoaderdef); 51 } 52 53 public boolean equals(Object obj) { 54 if (obj instanceof ClassInstance) { 55 ClassInstance other = (ClassInstance) obj; 56 return this.name.equals(other.name) && this.loaderDef.equals(other.loaderDef); 57 } 58 return false; 59 } 60 61 public int hashCode() { 62 int hash = 17; 63 hash = (37 * hash) + name.hashCode(); 64 hash = (37 * hash) + loaderDef.hashCode(); 65 return hash; 66 } 67 68 public UTF8ByteDataHolder getLoaderDef() { 69 return loaderDef; 70 } 71 72 public UTF8ByteDataHolder getName() { 73 return name; 74 } 75 76 public String toString() { 77 return "Class(" + name.asString() + "," + loaderDef.asString() + ")"; 78 } 79 80 } 81 | Popular Tags |