1 19 20 package org.apache.cayenne.remote.hessian.service; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import org.apache.cayenne.DataRow; 26 import org.apache.cayenne.map.EntityResolver; 27 import org.apache.cayenne.query.AbstractQuery; 28 import org.apache.cayenne.util.PersistentObjectList; 29 30 import com.caucho.hessian.io.AbstractSerializerFactory; 31 import com.caucho.hessian.io.Deserializer; 32 import com.caucho.hessian.io.HessianProtocolException; 33 import com.caucho.hessian.io.Serializer; 34 35 41 class ServerSerializerFactory extends AbstractSerializerFactory { 42 43 private EntityResolver serverResolver; 44 45 private ServerPersistentObjectListSerializer persistentObjectListSerializer; 46 private ServerDataRowSerializer dataRowSerilaizer; 47 private Map deserializers; 48 49 ServerSerializerFactory() { 50 this.persistentObjectListSerializer = new ServerPersistentObjectListSerializer(); 51 this.dataRowSerilaizer = new ServerDataRowSerializer(); 52 } 53 54 void setEntityResolver(EntityResolver resolver) { 56 this.serverResolver = resolver; 57 } 58 59 public Serializer getSerializer(Class cl) throws HessianProtocolException { 60 61 if (PersistentObjectList.class.isAssignableFrom(cl)) { 62 return persistentObjectListSerializer; 63 } 64 else if (DataRow.class.isAssignableFrom(cl)) { 65 return dataRowSerilaizer; 66 } 67 68 return null; 69 } 70 71 public Deserializer getDeserializer(Class cl) throws HessianProtocolException { 72 Deserializer deserializer = null; 73 74 if (AbstractQuery.class.isAssignableFrom(cl)) { 75 76 synchronized (this) { 77 78 if (deserializers != null) { 79 deserializer = (Deserializer) deserializers.get(cl); 80 } 81 82 if (deserializer == null) { 83 deserializer = new ServerAbstractQueryDeserializer(cl, serverResolver 84 .getClientEntityResolver()); 85 86 if (deserializers == null) { 87 deserializers = new HashMap (); 88 } 89 90 deserializers.put(cl, deserializer); 91 } 92 } 93 94 } 95 96 return deserializer; 97 } 98 } 99 | Popular Tags |