KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 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  * Initial developer(s): Philippe Durieux
22  * Contributor(s):
23  * --------------------------------------------------------------------------
24  * $Id: JLocalHome.java,v 1.12 2005/04/28 16:52:59 benoitf Exp $
25  * --------------------------------------------------------------------------
26  */

27
28 package org.objectweb.jonas_ejb.container;
29
30 import java.util.HashMap JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import javax.ejb.EJBLocalHome JavaDoc;
34 import javax.ejb.RemoveException JavaDoc;
35 import javax.naming.NamingException JavaDoc;
36 import javax.naming.Reference JavaDoc;
37 import javax.naming.StringRefAddr JavaDoc;
38
39 import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
40 import org.objectweb.jonas_ejb.lib.EJBInvocation;
41
42 import org.objectweb.util.monolog.api.BasicLevel;
43
44 /**
45  * This class represents an EJBLocalHome It is shared between Sessions and
46  * Entities.
47  * @author Philippe Durieux
48  */

49 public abstract class JLocalHome implements EJBLocalHome JavaDoc {
50
51     protected BeanDesc dd;
52
53     protected JFactory bf;
54
55     // The static table of all JLocalHome objects
56
protected static Map JavaDoc homeList = new HashMap JavaDoc();
57
58     /**
59      * Constructor for the base class of the specific generated Home object.
60      * @param dd The Bean Deployment Descriptor
61      * @param bf The Bean Factory
62      */

63     public JLocalHome(BeanDesc dd, JFactory bf) {
64         if (TraceEjb.isDebugIc()) {
65             TraceEjb.interp.log(BasicLevel.DEBUG, "");
66         }
67         this.dd = dd;
68         this.bf = bf;
69     }
70
71     // ---------------------------------------------------------------
72
// EJBLocalHome Implementation
73
// ---------------------------------------------------------------
74

75     /**
76      * Removes an EJB object identified by its primary key.
77      * @param primaryKey The Primary Key
78      */

79     public abstract void remove(Object JavaDoc primaryKey) throws RemoveException JavaDoc;
80
81     // ---------------------------------------------------------------
82
// other public methods
83
// ---------------------------------------------------------------
84

85     /**
86      * register this bean to JNDI (rebind) We register actually a Reference
87      * object.
88      */

89     protected void register() throws NamingException JavaDoc {
90         if (TraceEjb.isDebugIc()) {
91             TraceEjb.interp.log(BasicLevel.DEBUG, "");
92         }
93         String JavaDoc name = dd.getJndiLocalName();
94
95         // Keep it in the static list for later retrieving.
96
homeList.put(name, this);
97
98         Reference JavaDoc ref = new Reference JavaDoc("org.objectweb.jonas_ejb.container.JLocalHome",
99                 "org.objectweb.jonas_ejb.container.HomeFactory", null);
100         ref.add(new StringRefAddr JavaDoc("bean.name", name));
101         bf.getInitialContext().rebind(name, ref);
102     }
103
104     /**
105      * unregister this bean in JNDI (unbind)
106      */

107     protected void unregister() throws NamingException JavaDoc {
108         if (TraceEjb.isDebugIc()) {
109             TraceEjb.interp.log(BasicLevel.DEBUG, "");
110         }
111         String JavaDoc name = dd.getJndiLocalName();
112         // unregister in default InitialContext
113
bf.getInitialContext().unbind(name);
114         // remove from the static list
115
homeList.remove(name);
116     }
117
118     /**
119      * Get JLocalHome by its name
120      * @param beanName The Bean JNDI local Name
121      * @return The Bean LocalHome
122      */

123     public static JLocalHome getLocalHome(String JavaDoc beanName) {
124         if (TraceEjb.isDebugIc()) {
125             TraceEjb.interp.log(BasicLevel.DEBUG, beanName);
126         }
127         JLocalHome lh = (JLocalHome) homeList.get(beanName);
128         return lh;
129     }
130
131     /**
132      * preInvoke is called before any request.
133      * @param txa Transaction Attribute (Supports, Required, ...)
134      * @return A RequestCtx object
135      * @throws EJBException
136      */

137     public RequestCtx preInvoke(int txa) {
138         if (TraceEjb.isDebugIc()) {
139             TraceEjb.interp.log(BasicLevel.DEBUG, "");
140         }
141         return bf.preInvoke(txa);
142     }
143
144     /**
145      * Check if the access to the bean is authorized
146      * @param ejbInv object containing security signature of the method, args of
147      * method, etc
148      */

149      public void checkSecurity(EJBInvocation ejbInv) {
150          if (TraceEjb.isDebugIc()) {
151              TraceEjb.interp.log(BasicLevel.DEBUG, "");
152          }
153          bf.checkSecurity(ejbInv);
154      }
155
156     /**
157      * postInvoke is called after any request.
158      * @param rctx The RequestCtx that was returned at preInvoke()
159      */

160     public void postInvoke(RequestCtx rctx) {
161         if (TraceEjb.isDebugIc()) {
162             TraceEjb.interp.log(BasicLevel.DEBUG, "");
163         }
164         bf.postInvoke(rctx);
165     }
166
167 }
Popular Tags