KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.ejb.*;
26 import com.sun.ejb.portable.*;
27 import com.sun.enterprise.*;
28 import com.sun.enterprise.deployment.*;
29 import java.lang.reflect.Method JavaDoc;
30
31 import javax.ejb.*;
32
33 import java.rmi.Remote JavaDoc;
34 import java.rmi.RemoteException JavaDoc;
35 import java.rmi.NoSuchObjectException JavaDoc;
36
37 import java.util.Hashtable JavaDoc;
38 import java.util.Properties JavaDoc;
39
40 import java.util.logging.*;
41 import com.sun.logging.*;
42
43 /**
44  * This class implements the EJBHome interface.
45  * This class is also the base class for all generated concrete EJBHome
46  * implementations.
47  * At deployment time, one instance of the EJBHome is created
48  * for each EJB class in a JAR that has a remote home.
49  *
50  */

51
52 public abstract class EJBHomeImpl
53     implements javax.ejb.EJBHome JavaDoc
54 {
55
56     private static Logger _logger;
57     static {
58         _logger=LogDomains.getLogger(LogDomains.EJB_LOGGER);
59     }
60     
61     private BaseContainer container;
62
63     /**
64      * This constructor is called from an EJBHome implementation's constructor.
65      */

66     protected EJBHomeImpl()
67         throws RemoteException JavaDoc
68     {
69     }
70     
71     /**
72      * Called from EJBHome implementation.
73      */

74     protected final Container getContainer() {
75         return container;
76     }
77     
78     
79     /**
80      * Called from BaseContainer only.
81      */

82     final void setContainer(BaseContainer c) {
83         container = c;
84     }
85
86     /**
87      * Get the EJBHome corresponding to an EJBHomeImpl.
88      * These objects are one and the same when the home is generated,
89      * but distinct in the case of dynamic proxies. Therefore, code can't
90      * assume it can cast an EJBHomeImpl to the EJBHome that
91      * the client uses, and vice-versa. This is overridden in the
92      * InvocationHandler.
93      */

94     protected EJBHome getEJBHome() {
95         return this;
96     }
97     
98     /**
99      * Create a new EJBObject and new EJB if necessary.
100      * This is called from the generated "HelloEJBHomeImpl" create method.
101      * Return the EJBObject for the bean.
102      */

103     public final EJBObjectImpl createEJBObjectImpl()
104         throws RemoteException JavaDoc, CreateException
105     {
106         return container.createEJBObjectImpl();
107     }
108
109     public EJBObjectImpl createRemoteBusinessObjectImpl()
110         throws RemoteException JavaDoc, CreateException
111     {
112         return container.createRemoteBusinessObjectImpl();
113     }
114     
115     
116     /***************************************
117 ***********************************
118     The following are implementations of javax.ejb.EJBHome methods.
119      **************************************************************************/

120     
121     /**
122      * This is the implementation of the javax.ejb.EJBHome remove method.
123      * @exception RemoveException on error during removal
124      */

125     public final void remove(Handle handle)
126         throws RemoteException JavaDoc, RemoveException
127     {
128         container.authorizeRemoteMethod(BaseContainer.EJBHome_remove_Handle);
129         
130         EJBObject ejbo;
131         try {
132             ejbo = handle.getEJBObject();
133         } catch ( RemoteException JavaDoc ex ) {
134             _logger.log(Level.FINE, "Exception in method remove()", ex);
135             NoSuchObjectException JavaDoc nsoe =
136                 new NoSuchObjectException JavaDoc(ex.toString());
137             nsoe.initCause(ex);
138             throw nsoe;
139         }
140         ejbo.remove();
141     }
142     
143     
144     /**
145      * This is the implementation of the javax.ejb.EJBHome remove method.
146      * @exception RemoveException on error during removal
147      */

148     public final void remove(Object JavaDoc primaryKey)
149         throws RemoteException JavaDoc, RemoveException
150     {
151         if ( !(container instanceof EntityContainer) ) {
152             // Session beans dont have primary keys. EJB2.0 Section 6.6
153
throw new RemoveException("Invalid remove operation.");
154         }
155         
156         container.authorizeRemoteMethod(BaseContainer.EJBHome_remove_Pkey);
157         
158         Method JavaDoc method=null;
159         try {
160             method = EJBHome.class.getMethod("remove",
161                         new Class JavaDoc[]{Object JavaDoc.class});
162         } catch ( NoSuchMethodException JavaDoc e ) {
163             _logger.log(Level.FINE, "Exception in method remove()", e);
164         }
165         
166         ((EntityContainer)container).removeBean(primaryKey, method, false);
167     }
168     
169     
170     /**
171      * This is the implementation of the javax.ejb.EJBHome method.
172      */

173     public final EJBMetaData getEJBMetaData()
174         throws RemoteException JavaDoc
175     {
176         container.authorizeRemoteMethod(BaseContainer.EJBHome_getEJBMetaData);
177         
178         return container.getEJBMetaData();
179     }
180     
181     /**
182      * This is the implementation of the javax.ejb.EJBHome getHomeHandle
183      * method.
184      */

185     public final HomeHandle getHomeHandle()
186         throws RemoteException JavaDoc
187     {
188         container.authorizeRemoteMethod(BaseContainer.EJBHome_getHomeHandle);
189         
190         return new HomeHandleImpl(container.getEJBHomeStub());
191     }
192 }
193
Popular Tags