Source Code Cross Referenced for JStatefulInputStream.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas_ejb » container » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas_ejb.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999-2004 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: JStatefulInputStream.java 9280 2006-08-01 10:15:24Z japaz $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas_ejb.container;
025:
026:        import java.io.ByteArrayInputStream;
027:        import java.io.IOException;
028:        import java.io.InputStream;
029:        import java.io.ObjectInputStream;
030:        import java.io.ObjectStreamClass;
031:        import java.rmi.server.RemoteStub;
032:
033:        import javax.ejb.Handle;
034:        import javax.ejb.HomeHandle;
035:        import javax.naming.InitialContext;
036:        import javax.naming.NamingException;
037:
038:        import org.objectweb.util.monolog.api.BasicLevel;
039:
040:        /**
041:         * Extends ObjectInputStream because we want to enable resolveObject.
042:         * This class is very related to JStatefulOutputStream
043:         */
044:        public class JStatefulInputStream extends ObjectInputStream {
045:
046:            private JStatefulSwitch jss;
047:
048:            /**
049:             * Constructor.
050:             * @throws IOException
051:             */
052:            public JStatefulInputStream(InputStream in, JStatefulSwitch jss)
053:                    throws IOException {
054:                super (in);
055:                TraceEjb.ssfpool.log(BasicLevel.DEBUG, "constructor");
056:                enableResolveObject(true);
057:                this .jss = jss;
058:            }
059:
060:            /**
061:             * We must care about some object types. See EJB spec. 7.4.1
062:             * @param obj serialized field
063:             * @return resolved object
064:             */
065:            protected Object resolveObject(Object obj) throws IOException {
066:                Object ret;
067:
068:                if (obj instanceof  HomeHandle) {
069:                    // HomeHandle -> EJBHome
070:                    TraceEjb.ssfpool.log(BasicLevel.DEBUG, "HomeHandle");
071:                    ret = ((HomeHandle) obj).getEJBHome();
072:                } else if (obj instanceof  Handle) {
073:                    // Handle -> EJBObject
074:                    TraceEjb.ssfpool.log(BasicLevel.DEBUG, "Handle");
075:                    ret = ((Handle) obj).getEJBObject();
076:                } else if (obj instanceof  JWrapper) {
077:                    int type = ((JWrapper) obj).getType();
078:                    switch (type) {
079:                    case JWrapper.LOCAL_ENTITY:
080:                        TraceEjb.ssfpool.log(BasicLevel.DEBUG, "JEntityLocal");
081:                        String jndiname = (String) ((JWrapper) obj).getObject();
082:                        Object pk = ((JWrapper) obj).getPK();
083:                        JEntityLocalHome lhome = (JEntityLocalHome) JLocalHome
084:                                .getLocalHome(jndiname);
085:                        ret = lhome.findLocalByPK(pk);
086:                        break;
087:                    case JWrapper.LOCAL_HOME:
088:                        TraceEjb.ssfpool.log(BasicLevel.DEBUG, "JLocalHome");
089:                        String jname = (String) ((JWrapper) obj).getObject();
090:                        ret = JLocalHome.getLocalHome(jname);
091:                        break;
092:                    case JWrapper.USER_TX:
093:                        // UserTransaction
094:                        // Should be outside transaction here.
095:                        TraceEjb.ssfpool.log(BasicLevel.DEBUG,
096:                                "UserTransaction");
097:                        ret = jss.getStatefulContext().getUserTransaction();
098:                        break;
099:                    case JWrapper.SESSION_CTX:
100:                        // SessionContext.
101:                        // Should be outside transaction here.
102:                        TraceEjb.ssfpool
103:                                .log(BasicLevel.DEBUG, "SessionContext");
104:                        ret = jss.getStatefulContext();
105:                        break;
106:                    case JWrapper.NAMING_CONTEXT:
107:                        // CompNamingContext
108:                        TraceEjb.ssfpool.log(BasicLevel.DEBUG,
109:                                "CompNamingContext");
110:                        String cname = (String) ((JWrapper) obj).getObject();
111:                        try {
112:                            InitialContext ictx = new InitialContext();
113:                            ret = ictx.lookup(cname);
114:                        } catch (NamingException e) {
115:                            TraceEjb.ssfpool.log(BasicLevel.ERROR,
116:                                    "Cannot retrieve NamingContext" + e);
117:                            throw new IOException(
118:                                    "Cannot retrieve NamingContext");
119:                        }
120:                        break;
121:                    case JWrapper.HANDLE:
122:                        TraceEjb.ssfpool.log(BasicLevel.DEBUG, "Handle");
123:
124:                        // Deserialize the Handle without JStatefulOutputStream
125:                        JWrapper theJWrapper = (JWrapper) obj;
126:                        byte ser[] = (byte[]) theJWrapper.getObject();
127:
128:                        ByteArrayInputStream bais = new ByteArrayInputStream(
129:                                ser);
130:                        ObjectInputStream ois = new ObjectInputStream(bais);
131:                        Handle theHandle;
132:
133:                        try {
134:                            theHandle = (Handle) ois.readObject();
135:                        } catch (ClassNotFoundException e) {
136:                            e.printStackTrace();
137:                            throw new IOException(e.getMessage());
138:                        }
139:
140:                        ret = theHandle;
141:                        break;
142:                    default:
143:                        TraceEjb.ssfpool.log(BasicLevel.DEBUG,
144:                                "Other wrapped object");
145:                        ret = ((JWrapper) obj).getObject();
146:                        break;
147:                    }
148:                } else if (obj instanceof  RemoteStub) {
149:                    // Remote Stub -> Remote
150:                    TraceEjb.ssfpool.log(BasicLevel.DEBUG, "RemoteStub");
151:                    // TODO
152:                    ret = obj;
153:                } else {
154:                    // Default -> keep the object as is.
155:                    TraceEjb.ssfpool.log(BasicLevel.DEBUG, "Other");
156:                    ret = obj;
157:                }
158:                return ret;
159:            }
160:
161:            /**
162:             * Use the thread context class loader to resolve the class
163:             * @param v class to resolve
164:             * @return class resolved
165:             * @throws java.io.IOException thrown by the underlying InputStream.
166:             * @throws ClassNotFoundException thrown by the underlying InputStream.
167:             */
168:            protected Class resolveClass(ObjectStreamClass v)
169:                    throws IOException, ClassNotFoundException {
170:                TraceEjb.ssfpool.log(BasicLevel.DEBUG, v);
171:                ClassLoader cl = Thread.currentThread().getContextClassLoader();
172:                return cl.loadClass(v.getName());
173:            }
174:
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.