1 19 20 package org.apache.cayenne.remote.hessian.service; 21 22 import java.io.ByteArrayInputStream ; 23 import java.io.ByteArrayOutputStream ; 24 import java.io.Serializable ; 25 26 import org.apache.cayenne.map.EntityResolver; 27 import org.apache.cayenne.remote.hessian.HessianConfig; 28 import org.apache.cayenne.remote.hessian.HessianConnection; 29 30 import com.caucho.hessian.io.HessianInput; 31 import com.caucho.hessian.io.HessianOutput; 32 33 39 public final class HessianUtil { 40 41 45 public static Object cloneViaClientServerSerialization( 46 Serializable object, 47 EntityResolver serverResolver) throws Exception { 48 ByteArrayOutputStream bytes = new ByteArrayOutputStream (); 49 HessianOutput out = new HessianOutput(bytes); 50 out.setSerializerFactory(HessianConfig.createFactory( 51 HessianConnection.CLIENT_SERIALIZER_FACTORIES, 52 null)); 53 out.writeObject(object); 54 55 byte[] data = bytes.toByteArray(); 56 57 HessianInput in = new HessianInput(new ByteArrayInputStream (data)); 58 in.setSerializerFactory(HessianConfig.createFactory( 59 HessianService.SERVER_SERIALIZER_FACTORIES, 60 serverResolver)); 61 62 return in.readObject(); 63 } 64 65 public static Object cloneViaServerClientSerialization( 66 Serializable object, 67 EntityResolver serverResolver) throws Exception { 68 ByteArrayOutputStream bytes = new ByteArrayOutputStream (); 69 HessianOutput out = new HessianOutput(bytes); 70 out.setSerializerFactory(HessianConfig.createFactory( 71 HessianService.SERVER_SERIALIZER_FACTORIES, 72 serverResolver)); 73 out.writeObject(object); 74 75 byte[] data = bytes.toByteArray(); 76 77 HessianInput in = new HessianInput(new ByteArrayInputStream (data)); 78 in.setSerializerFactory(HessianConfig.createFactory( 79 HessianConnection.CLIENT_SERIALIZER_FACTORIES, 80 null)); 81 return in.readObject(); 82 } 83 84 private HessianUtil() { 85 86 } 87 } 88 | Popular Tags |