KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > tomcat > tc6 > session > SessionSerializationFactory


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

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 JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.io.ObjectInputStream JavaDoc;
35 import java.io.ObjectOutputStream JavaDoc;
36 import java.io.OutputStream JavaDoc;
37
38 /**
39  * Factory class for creating object output and input streams,
40  * switching between JDK Serialization and JBoss Serialization classes.
41  * Using MarshalledValue to replace Serializable used inside different
42  * web app class loader context. Assuming that the caller classes are already
43  * handling the switch between web app class loader context.
44  *
45  *
46  * @author <a HREF="hmesha@novell.com">Hany Mesha</a>
47  */

48 public class SessionSerializationFactory
49 {
50    static Logger log_ = Logger.getLogger(SessionSerializationFactory.class);
51    static boolean useJBossSerialization = false;
52
53    static
54    {
55        String JavaDoc useJBossSerializationStr = System.getProperty("session.serialization.jboss", "true");
56        useJBossSerialization = Boolean.valueOf(useJBossSerializationStr).booleanValue();
57    }
58
59    public static ObjectOutputStream JavaDoc createObjectOutputStream(OutputStream out) throws IOException JavaDoc
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 JavaDoc createObjectInputStream(byte[] bytes) throws IOException JavaDoc
69    {
70       if (log_.isDebugEnabled())
71       {
72          log_.debug("createObjectInputStream using JBossSerialization = " + useJBossSerialization);
73       }
74        ByteArrayInputStream JavaDoc in = new ByteArrayInputStream JavaDoc(bytes);
75        return useJBossSerialization ? new JBossObjectInputStreamSharedTree(in) : new MarshalledValueInputStream(in);
76    }
77    
78    public static MarshalledValue createMarshalledValue(Object JavaDoc o) throws IOException JavaDoc
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 JavaDoc o) throws IOException JavaDoc
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