1 23 package com.sun.enterprise.util; 24 25 import java.io.*; 26 27 import java.lang.reflect.Array ; 28 29 33 public class ObjectInputStreamWithLoader extends ObjectInputStream { 34 protected ClassLoader loader; 35 36 42 43 public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader) 44 throws IOException, StreamCorruptedException { 45 46 super(in); 47 if (loader == null) { 48 throw new IllegalArgumentException ("Illegal null argument to ObjectInputStreamWithLoader"); 49 } 50 this.loader = loader; 51 } 52 53 56 57 private Class primitiveType(char type) { 58 switch (type) { 59 case 'B': return byte.class; 60 case 'C': return char.class; 61 case 'D': return double.class; 62 case 'F': return float.class; 63 case 'I': return int.class; 64 case 'J': return long.class; 65 case 'S': return short.class; 66 case 'Z': return boolean.class; 67 default: return null; 68 } 69 } 70 71 76 protected Class resolveClass(ObjectStreamClass classDesc) 77 throws IOException, ClassNotFoundException { 78 79 String cname = classDesc.getName(); 80 if (cname.startsWith("[")) { 81 Class component; int dcount; for (dcount=1; cname.charAt(dcount)=='['; dcount++) ; 85 if (cname.charAt(dcount) == 'L') { 86 component = loader.loadClass(cname.substring(dcount+1, 87 cname.length()-1)); 88 } else { 89 if (cname.length() != dcount+1) { 90 throw new ClassNotFoundException (cname); } 92 component = primitiveType(cname.charAt(dcount)); 93 } 94 int dim[] = new int[dcount]; 95 for (int i=0; i<dcount; i++) { 96 dim[i]=0; 97 } 98 return Array.newInstance(component, dim).getClass(); 99 } else { 100 return loader.loadClass(cname); 101 } 102 } 103 } 104 | Popular Tags |