1 22 package org.jboss.web.tomcat.tc6.session; 23 24 import org.jboss.invocation.MarshalledValueInputStream; 25 import org.jboss.invocation.MarshalledValueOutputStream; 26 import org.jboss.invocation.MarshalledValue; 27 import org.jboss.logging.Logger; 28 import org.jboss.serial.io.JBossObjectInputStreamSharedTree; 29 import org.jboss.serial.io.JBossObjectOutputStreamSharedTree; 30 import org.jboss.serial.io.MarshalledObject; 31 32 import java.io.ByteArrayInputStream ; 33 import java.io.IOException ; 34 import java.io.ObjectInputStream ; 35 import java.io.ObjectOutputStream ; 36 import java.io.OutputStream ; 37 38 48 public class SessionSerializationFactory 49 { 50 static Logger log_ = Logger.getLogger(SessionSerializationFactory.class); 51 static boolean useJBossSerialization = false; 52 53 static 54 { 55 String useJBossSerializationStr = System.getProperty("session.serialization.jboss", "true"); 56 useJBossSerialization = Boolean.valueOf(useJBossSerializationStr).booleanValue(); 57 } 58 59 public static ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException 60 { 61 if (log_.isDebugEnabled()) 62 { 63 log_.debug("createObjectOutputStream using JBossSerialization = " + useJBossSerialization); 64 } 65 return useJBossSerialization ? new JBossObjectOutputStreamSharedTree(out) : new MarshalledValueOutputStream(out); 66 } 67 68 public static ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException 69 { 70 if (log_.isDebugEnabled()) 71 { 72 log_.debug("createObjectInputStream using JBossSerialization = " + useJBossSerialization); 73 } 74 ByteArrayInputStream in = new ByteArrayInputStream (bytes); 75 return useJBossSerialization ? new JBossObjectInputStreamSharedTree(in) : new MarshalledValueInputStream(in); 76 } 77 78 public static MarshalledValue createMarshalledValue(Object o) throws IOException 79 { 80 if (log_.isDebugEnabled()) 81 { 82 log_.debug("createMarshalledValue using JBossSerialization = " + useJBossSerialization); 83 } 84 return new MarshalledValue (o); 85 } 86 87 public static MarshalledObject createMarshalledObject(Object o) throws IOException 88 { 89 if (log_.isDebugEnabled()) 90 { 91 log_.debug("createMarshalledObject using JBossSerialization = " + useJBossSerialization); 92 } 93 return new MarshalledObject(o); 94 } 95 96 public static boolean useJBossSerialization() 97 { 98 return useJBossSerialization; 99 } 100 101 } 102 | Popular Tags |