1 package org.sapia.ubik.rmi.server.transport; 2 3 import java.io.Externalizable ; 4 import java.io.IOException ; 5 import java.io.ObjectInput ; 6 import java.io.ObjectOutput ; 7 import java.util.HashMap ; 8 import java.util.Map ; 9 10 11 24 public class ClassDescriptor implements Externalizable { 25 private static final long serialVersionUID = 6382603348796329430l; 26 private static Map _primitives = new HashMap (); 27 28 static { 29 _primitives.put(boolean.class.getName(), boolean.class); 30 _primitives.put(byte.class.getName(), byte.class); 31 _primitives.put(char.class.getName(), char.class); 32 _primitives.put(short.class.getName(), short.class); 33 _primitives.put(int.class.getName(), int.class); 34 _primitives.put(long.class.getName(), long.class); 35 _primitives.put(float.class.getName(), float.class); 36 _primitives.put(double.class.getName(), double.class); 37 } 38 39 private transient Class _type; 40 private String _className; 41 private boolean _primitive; 42 43 44 public ClassDescriptor() { 45 } 46 47 public ClassDescriptor(Class type) { 48 _type = type; 49 _primitive = type.isPrimitive(); 50 _className = type.getName(); 51 } 52 53 public void readExternal(ObjectInput in) 54 throws IOException , ClassNotFoundException { 55 _className = in.readUTF(); 56 _primitive = in.readBoolean(); 57 } 58 59 public void writeExternal(ObjectOutput out) throws IOException { 60 out.writeUTF(_className); 61 out.writeBoolean(_primitive); 62 } 63 64 public Class resolve(ClassLoader loader) throws ClassNotFoundException { 65 if (_primitive) { 66 Class clazz = (Class ) _primitives.get(_className); 67 68 if (clazz == null) { 69 throw new ClassNotFoundException (_className); 70 } 71 72 return clazz; 73 } else { 74 if (_type == null) { 75 _type = loader.loadClass(_className); 76 return _type; 77 } 78 else{ 79 return _type; 80 } 81 } 82 } 83 } 84 | Popular Tags |