KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > containers > EJBObjectImpl


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 package com.sun.ejb.containers;
24
25 import java.rmi.Remote JavaDoc;
26 import java.rmi.RemoteException JavaDoc;
27 import java.lang.reflect.Method JavaDoc;
28
29 import javax.ejb.*;
30
31 import com.sun.ejb.*;
32 import com.sun.ejb.portable.*;
33 import com.sun.enterprise.*;
34
35 import com.sun.enterprise.log.Log;
36 import com.sun.enterprise.util.LocalStringManagerImpl;
37
38 import java.util.Map JavaDoc;
39 import java.util.HashMap JavaDoc;
40
41 import java.util.logging.*;
42 import com.sun.logging.*;
43
44 /**
45  * EJBObjectImpl implements EJBObject methods for EJBs.
46  * It is extended by the generated concrete type-specific EJBObject
47  * implementation (e.g. Hello_EJBObject).
48  * Instances of this class are NEVER given to beans or clients.
49  * Beans and clients get only stubs (instances of the stub class
50  * generated by rmic).
51  *
52  */

53
54 public abstract class EJBObjectImpl
55     extends EJBLocalRemoteObject
56     implements EJBObject
57 {
58     private static Logger _logger;
59     private static Class JavaDoc[] NO_PARAMS = new Class JavaDoc[] {};
60     private static LocalStringManagerImpl localStrings =
61         new LocalStringManagerImpl(EJBObjectImpl.class);
62     private static Method JavaDoc REMOVE_METHOD = null;
63
64     static {
65         _logger=LogDomains.getLogger(LogDomains.EJB_LOGGER);
66
67         try {
68             REMOVE_METHOD = EJBObject.class.getMethod("remove", NO_PARAMS);
69         } catch ( NoSuchMethodException JavaDoc e ) {
70             _logger.log(Level.FINE, "Exception retrieving remove method", e);
71         }
72     }
73
74     transient private java.rmi.Remote JavaDoc stub;
75     transient private java.rmi.Remote JavaDoc ejbObject;
76     transient private Map JavaDoc businessStubs = new HashMap JavaDoc();
77     transient private Map JavaDoc businessEJBObjects = new HashMap JavaDoc();
78     transient private boolean beingCreated=false;
79     
80     // True if this object instance represents the RemoteHomeview
81
// False if this object instance represents the RemoteBusiness view
82
private boolean isRemoteHomeView;
83
84     protected EJBObjectImpl() throws RemoteException JavaDoc {
85     }
86     
87     final void setStub(java.rmi.Remote JavaDoc stub) {
88         this.stub = stub;
89     }
90     
91     /**
92      * Stubs are keyed by the name of generated RMI-IIOP version of
93      * each remote business interface.
94      */

95     final void setStub(String JavaDoc generatedBusinessInterface,
96                        java.rmi.Remote JavaDoc stub) {
97         businessStubs.put(generatedBusinessInterface, stub);
98     }
99     
100     public final java.rmi.Remote JavaDoc getStub() {
101         return stub;
102     }
103
104     public final java.rmi.Remote JavaDoc getStub(String JavaDoc generatedBusinessInterface) {
105         return (java.rmi.Remote JavaDoc) businessStubs.get(generatedBusinessInterface);
106     }
107
108     void setIsRemoteHomeView(boolean flag) {
109         isRemoteHomeView = flag;
110     }
111
112     boolean isRemoteHomeView() {
113         return isRemoteHomeView;
114     }
115
116     /**
117      * Get the Remote object corresponding to an EJBObjectImpl for
118      * the RemoteHome view.
119      */

120     public java.rmi.Remote JavaDoc getEJBObject() {
121         return ejbObject;
122     }
123
124     /**
125      * Get the Remote object corresponding to an EJBObjectImpl for
126      * the RemoteBusiness view.
127      */

128     public java.rmi.Remote JavaDoc getEJBObject(String JavaDoc generatedBusinessInterface) {
129         return (java.rmi.Remote JavaDoc) businessEJBObjects.get
130             (generatedBusinessInterface);
131     }
132
133     public void setEJBObject(java.rmi.Remote JavaDoc ejbObject) {
134         this.ejbObject = ejbObject;
135     }
136
137     public void setEJBObject(String JavaDoc generatedBusinessInterface,
138                              java.rmi.Remote JavaDoc ejbObject) {
139         businessEJBObjects.put(generatedBusinessInterface, ejbObject);
140     }
141
142     final void setBeingCreated(boolean b) {
143         beingCreated = b;
144     }
145     
146     final boolean isBeingCreated() {
147         return beingCreated;
148     }
149     
150     /**************************************************************************
151     The following are implementations of EJBObject methods.
152      **************************************************************************/

153     /**
154      */

155     public boolean isIdentical(EJBObject ejbo) throws RemoteException JavaDoc {
156         container.authorizeRemoteMethod(BaseContainer.EJBObject_isIdentical);
157         
158         return container.isIdentical(this, ejbo);
159     }
160     
161     
162     /**
163      */

164     public Object JavaDoc getPrimaryKey() throws RemoteException JavaDoc {
165         if ( container instanceof EntityContainer ) {
166             container.authorizeRemoteMethod(
167                 BaseContainer.EJBObject_getPrimaryKey);
168             
169             return primaryKey;
170         }
171         else {
172             throw new RemoteException JavaDoc(localStrings.getLocalString(
173                 "containers.invalid_operation",
174                 "Invalid operation for Session EJBs."));
175         }
176     }
177     
178     /**
179      *
180      */

181     public final EJBHome getEJBHome() throws RemoteException JavaDoc {
182         container.authorizeRemoteMethod(BaseContainer.EJBObject_getEJBHome);
183         
184         return container.getEJBHomeStub();
185     }
186     
187     /**
188      * This is called when the EJB client does ejbref.remove().
189      * or EJBHome/LocalHome.remove(primaryKey).
190      * Since there is no generated code in the *_EJBObjectImpl class
191      * for remove, we need to call preInvoke, postInvoke etc here.
192      */

193     public final void remove() throws RemoteException JavaDoc, RemoveException {
194         container.authorizeRemoteMethod(BaseContainer.EJBObject_remove);
195         
196         container.removeBean(this, REMOVE_METHOD, false);
197     }
198     
199     /**
200      * This is called when the EJB client does ejbref.getHandle().
201      * Return a serializable implementation of javax.ejb.Handle.
202      */

203     public final Handle getHandle() throws RemoteException JavaDoc {
204         container.authorizeRemoteMethod(BaseContainer.EJBObject_getHandle);
205
206         // We can assume the stub an EJBObject since getHandle() is only
207
// visible through the RemoteHome view.
208
return new HandleImpl((EJBObject)stub);
209     }
210 }
211
Popular Tags