1 48 49 package com.caucho.hessian.io; 50 51 import java.io.IOException ; 52 import java.lang.reflect.Constructor ; 53 54 57 public class SqlDateDeserializer extends AbstractDeserializer { 58 private Class _cl; 59 private Constructor _constructor; 60 61 public SqlDateDeserializer(Class cl) 62 throws NoSuchMethodException 63 { 64 _cl = cl; 65 _constructor = cl.getConstructor(new Class [] { long.class }); 66 } 67 68 public Class getType() 69 { 70 return _cl; 71 } 72 73 public Object readMap(AbstractHessianInput in) 74 throws IOException 75 { 76 long initValue = Long.MIN_VALUE; 77 78 while (! in.isEnd()) { 79 String key = in.readString(); 80 81 if (key.equals("value")) 82 initValue = in.readUTCDate(); 83 else 84 in.readString(); 85 } 86 87 in.readMapEnd(); 88 89 return create(initValue); 90 } 91 92 public Object readObject(AbstractHessianInput in, String []fieldNames) 93 throws IOException 94 { 95 long initValue = Long.MIN_VALUE; 96 97 for (int i = 0; i < fieldNames.length; i++) { 98 String key = fieldNames[i]; 99 100 if (key.equals("value")) 101 initValue = in.readUTCDate(); 102 else 103 in.readObject(); 104 } 105 106 return create(initValue); 107 } 108 109 private Object create(long initValue) 110 throws IOException 111 { 112 if (initValue == Long.MIN_VALUE) 113 throw new IOException (_cl.getName() + " expects name."); 114 115 try { 116 return _constructor.newInstance(new Object [] { new Long (initValue) }); 117 } catch (Exception e) { 118 throw new IOExceptionWrapper(e); 119 } 120 } 121 } 122 | Popular Tags |