1 48 49 package com.caucho.hessian.io; 50 51 import java.io.IOException ; 52 53 56 public class ClassDeserializer extends AbstractDeserializer { 57 public ClassDeserializer() 58 { 59 } 60 61 public Class getType() 62 { 63 return Class .class; 64 } 65 66 public Object readMap(AbstractHessianInput in) 67 throws IOException 68 { 69 int ref = in.addRef(null); 70 71 String name = null; 72 73 while (! in.isEnd()) { 74 String key = in.readString(); 75 76 if (key.equals("name")) 77 name = in.readString(); 78 else 79 in.readObject(); 80 } 81 82 in.readMapEnd(); 83 84 return create(name); 85 } 86 87 public Object readObject(AbstractHessianInput in, String []fieldNames) 88 throws IOException 89 { 90 String name = null; 91 92 for (int i = 0; i < fieldNames.length; i++) { 93 if ("name".equals(fieldNames[i])) 94 name = in.readString(); 95 else 96 in.readObject(); 97 } 98 99 return create(name); 100 } 101 102 Object create(String name) 103 throws IOException 104 { 105 if (name == null) 106 throw new IOException ("Serialized Class expects name."); 107 108 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 109 110 try { 111 if (loader != null) 112 return Class.forName(name, false, loader); 113 else 114 return Class.forName(name); 115 } catch (Exception e) { 116 throw new IOExceptionWrapper(e); 117 } 118 } 119 } 120 | Popular Tags |