KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > base > io > EJBObjectInputStream


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.ejb.base.io;
25
26 import com.sun.enterprise.util.ObjectInputStreamWithLoader;
27 import java.io.InputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.StreamCorruptedException JavaDoc;
30 import java.rmi.Remote JavaDoc;
31
32 import java.util.logging.*;
33 import com.sun.logging.*;
34 import java.lang.reflect.Proxy JavaDoc;
35 import java.lang.reflect.Modifier JavaDoc;
36
37 import com.sun.enterprise.Switch;
38 import com.sun.corba.ee.spi.presentation.rmi.StubAdapter;
39 import com.sun.ejb.spi.io.SerializableObjectFactory;
40
41 /**
42  * A class that is used to restore SFSB conversational state
43  *
44  * @author Mahesh Kannan
45  */

46 class EJBObjectInputStream
47     extends ObjectInputStreamWithLoader
48 {
49
50     private static Logger _ejbLogger =
51        LogDomains.getLogger(LogDomains.EJB_LOGGER);
52
53     EJBObjectInputStream(InputStream JavaDoc in, ClassLoader JavaDoc cl, boolean resolve)
54         throws IOException JavaDoc, StreamCorruptedException JavaDoc
55     {
56         super(in, cl);
57         if (resolve == true) {
58             enableResolveObject(resolve);
59         }
60     }
61
62     protected Object JavaDoc resolveObject(Object JavaDoc obj)
63         throws IOException JavaDoc
64     {
65         try {
66             if ( StubAdapter.isStub(obj) ) {
67                 // connect the Remote object to the Protocol Manager
68
Switch.getSwitch().getProtocolManager().
69                     connectObject((Remote JavaDoc)obj);
70                 return obj;
71             } else if (obj instanceof SerializableObjectFactory) {
72                 return ((SerializableObjectFactory) obj).createObject();
73             } else {
74                 return obj;
75             }
76         } catch (IOException JavaDoc ioEx ) {
77             _ejbLogger.log(Level.SEVERE, "ejb.resolve_object_exception", ioEx);
78             throw ioEx;
79         } catch (Exception JavaDoc ex) {
80             _ejbLogger.log(Level.SEVERE, "ejb.resolve_object_exception", ex);
81             IOException JavaDoc ioe = new IOException JavaDoc();
82             ioe.initCause(ex);
83             throw ioe;
84         }
85     }
86
87     protected Class JavaDoc resolveProxyClass(String JavaDoc[] interfaces)
88         throws IOException JavaDoc, ClassNotFoundException JavaDoc
89     {
90         Class JavaDoc[] classObjs = new Class JavaDoc[interfaces.length];
91         for (int i = 0; i < interfaces.length; i++) {
92             Class JavaDoc cl = Class.forName(interfaces[i], false, loader);
93             // If any non-public interfaces, delegate to JDK's
94
// implementation of resolveProxyClass.
95
if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
96                 return super.resolveProxyClass(interfaces);
97             } else {
98                 classObjs[i] = cl;
99             }
100         }
101         try {
102             return Proxy.getProxyClass(loader, classObjs);
103         } catch (IllegalArgumentException JavaDoc e) {
104             throw new ClassNotFoundException JavaDoc(null, e);
105         }
106     }
107 }
108
Popular Tags