KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > container > JStatefulInputStream


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JStatefulInputStream.java,v 1.1 2005/07/13 06:29:45 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.container;
27
28 import java.io.IOException JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.io.ObjectInputStream JavaDoc;
31 import java.io.ObjectStreamClass JavaDoc;
32 import java.rmi.server.RemoteStub JavaDoc;
33
34 import javax.ejb.Handle JavaDoc;
35 import javax.ejb.HomeHandle JavaDoc;
36
37
38 import org.objectweb.util.monolog.api.BasicLevel;
39
40 /**
41  * Extends ObjectInputStream because we want to enable resolveObject.
42  * This class is very related to JStatefulOutputStream
43  */

44 public class JStatefulInputStream extends ObjectInputStream JavaDoc {
45
46     private JStatefulSwitch jss;
47
48     /**
49      * Constructor.
50      * @throws IOException
51      */

52     public JStatefulInputStream(InputStream JavaDoc in, JStatefulSwitch jss) throws IOException JavaDoc {
53         super(in);
54         TraceEjb.ssfpool.log(BasicLevel.DEBUG, "constructor");
55         enableResolveObject(true);
56         this.jss = jss;
57     }
58
59     /**
60      * We must care about some object types. See EJB spec. 7.4.1
61      * @param obj serialized field
62      * @return resolved object
63      */

64     protected Object JavaDoc resolveObject(Object JavaDoc obj) throws IOException JavaDoc {
65         Object JavaDoc ret;
66
67         if (obj instanceof HomeHandle JavaDoc) {
68             // HomeHandle -> EJBHome
69
TraceEjb.ssfpool.log(BasicLevel.DEBUG, "HomeHandle");
70             ret = ((HomeHandle JavaDoc)obj).getEJBHome();
71         } else if (obj instanceof Handle JavaDoc) {
72             // Handle -> EJBObject
73
TraceEjb.ssfpool.log(BasicLevel.DEBUG, "Handle");
74             ret = ((Handle JavaDoc)obj).getEJBObject();
75         } else if (obj instanceof JWrapper) {
76             int type = ((JWrapper) obj).getType();
77             switch (type) {
78                 case JWrapper.USER_TX:
79                     // UserTransaction
80
// Should be outside transaction here.
81
TraceEjb.ssfpool.log(BasicLevel.DEBUG, "UserTransaction");
82                     ret = jss.getStatefulContext().getUserTransaction();
83                     break;
84                 case JWrapper.SESSION_CTX:
85                     // SessionContext.
86
// Should be outside transaction here.
87
TraceEjb.ssfpool.log(BasicLevel.DEBUG, "SessionContext");
88                     ret = jss.getStatefulContext();
89                     break;
90                 default:
91                     TraceEjb.ssfpool.log(BasicLevel.DEBUG, "Other wrapped object");
92                     ret = ((JWrapper) obj).getObject();
93                     break;
94             }
95         } else if (obj instanceof RemoteStub JavaDoc) {
96             // Remote Stub -> Remote
97
TraceEjb.ssfpool.log(BasicLevel.DEBUG, "RemoteStub");
98             // TODO
99
ret = obj;
100         } else {
101             // Default -> keep the object as is.
102
TraceEjb.ssfpool.log(BasicLevel.DEBUG, "Other");
103             ret = obj;
104         }
105         return ret;
106     }
107
108     /**
109      * Use the thread context class loader to resolve the class
110      * @param v class to resolve
111      * @return class resolved
112      * @throws java.io.IOException thrown by the underlying InputStream.
113      * @throws ClassNotFoundException thrown by the underlying InputStream.
114      */

115     protected Class JavaDoc resolveClass(ObjectStreamClass JavaDoc v) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
116        TraceEjb.ssfpool.log(BasicLevel.DEBUG, v);
117        ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
118        return cl.loadClass(v.getName());
119     }
120
121 }
122
Popular Tags