1 48 49 package com.caucho.hessian.io; 50 51 import java.io.IOException ; 52 import java.util.HashMap ; 53 import java.util.Map ; 54 import java.util.SortedMap ; 55 import java.util.TreeMap ; 56 57 60 public class MapDeserializer extends AbstractMapDeserializer { 61 private Class type; 62 63 public MapDeserializer(Class type) 64 { 65 this.type = type; 66 } 67 68 public Class getType() 69 { 70 if (this.type != null) 71 return this.type; 72 else 73 return HashMap .class; 74 } 75 76 public Object readMap(AbstractHessianInput in) 77 throws IOException 78 { 79 Map map; 80 81 if (type == null) 82 map = new HashMap (); 83 else if (type.equals(Map .class)) 84 map = new HashMap (); 85 else if (type.equals(SortedMap .class)) 86 map = new TreeMap (); 87 else { 88 try { 89 map = (Map ) type.newInstance(); 90 } catch (Exception e) { 91 throw new IOExceptionWrapper(e); 92 } 93 } 94 95 in.addRef(map); 96 97 while (! in.isEnd()) { 98 map.put(in.readObject(), in.readObject()); 99 } 100 101 in.readEnd(); 102 103 return map; 104 } 105 } 106 | Popular Tags |