KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > container > EJB


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  * --------------------------------------------------------------------------
22  * $Id: EJB.java,v 1.8 2005/07/28 07:52:27 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.container;
27
28 import java.util.Enumeration JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.Vector JavaDoc;
33
34 import org.objectweb.jonas.dbm.DataBaseServiceImpl;
35 import org.objectweb.jonas.mail.MailServiceImpl;
36 import org.objectweb.jonas.management.j2eemanagement.J2EEManagedObject;
37 import org.objectweb.jonas.service.ServiceManager;
38 import org.objectweb.jonas_ejb.container.JFactory;
39 import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
40 import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp1Desc;
41 import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp2Desc;
42 import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc;
43 import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc;
44
45 /**
46  * This class implements the EJB type specified in JSR77
47  * @author Adriana Danes
48  *
49  */

50 public class EJB extends J2EEManagedObject {
51     /**
52      * The Bean to manage
53      */

54     protected JFactory ejbToManage = null;
55     protected BeanDesc desc = null;
56     protected String JavaDoc fileName = null;
57
58     public EJB(String JavaDoc objectName, JFactory ejbToManage) {
59         super(objectName);
60         this.ejbToManage = ejbToManage;
61         this.fileName = ejbToManage.getContainer().getExternalFileName();
62         this.desc = ejbToManage.getDeploymentDescriptor();
63     }
64
65
66     /**
67      * @return String The Name of this JFactory
68      */

69     public String JavaDoc getName() {
70         return desc.getEjbName();
71     }
72
73     /**
74      * @return Ejb File Name
75      */

76     public String JavaDoc getFileName() {
77         return fileName;
78     }
79
80     /**
81      * @return Set The Name set of the DataSources
82      */

83     public Hashtable JavaDoc getAllDataSourceName() {
84         Hashtable JavaDoc result = new Hashtable JavaDoc();
85
86         DataBaseServiceImpl bdmServ = null;
87         String JavaDoc jndiName = null;
88         Vector JavaDoc jndiNames = new Vector JavaDoc();
89         String JavaDoc datasourceName = null;
90
91         // find the resource refs
92
ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
93         for (int i = 0; i < rrDesc.length; i ++) {
94             if (rrDesc[i].isJdbc()) {
95                 // get the DD provided JNDI name
96
jndiName = rrDesc[i].getJndiName();
97                 jndiNames.add(jndiName);
98             }
99         }
100
101         // if the EJB is an entity with CMP, we have to find jndi name in the jdbc_mapping
102
if (desc instanceof EntityJdbcCmp1Desc) {
103             // in case of CMP1 :
104
EntityJdbcCmp1Desc jdbcCmp1Desc = (EntityJdbcCmp1Desc) desc;
105             jndiName = jdbcCmp1Desc.getDatasourceJndiName();
106             jndiNames.add(jndiName);
107         } else if (desc instanceof EntityJdbcCmp2Desc) {
108             // in case of CMP2 :
109
EntityJdbcCmp2Desc jdbcCmp2Desc = (EntityJdbcCmp2Desc) desc;
110             jndiName = jdbcCmp2Desc.getDatasourceJndiName();
111             jndiNames.add(jndiName);
112         }
113
114         if (!jndiNames.isEmpty()) {
115             try {
116                 // Modified for use with the gcj compiler
117
ServiceManager sm = ServiceManager.getInstance();
118                 bdmServ = (DataBaseServiceImpl) sm.getDataBaseService();
119             } catch(Exception JavaDoc e) {
120                 // DataBase Service not available
121
// Temporary solution
122
return result;
123             }
124         }
125
126         for (Enumeration JavaDoc e = jndiNames.elements() ; e.hasMoreElements() ;) {
127             jndiName = (String JavaDoc)e.nextElement();
128             datasourceName = bdmServ.getDatasourceName(jndiName);
129             if (datasourceName != null)
130                 result.put(jndiName, datasourceName);
131             else
132                 result.put(jndiName, "");
133         }
134
135         return result;
136     }
137
138
139     /**
140      * @return Set The Name set of the Connection Factories
141      */

142     public Set JavaDoc getAllJMSConnectionFactoryName(){
143         Set JavaDoc result= new HashSet JavaDoc();
144         ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
145         for (int i = 0; i < rrDesc.length; i ++) {
146             if ("javax.jms.TopicConnectionFactory".equals(rrDesc[i].getTypeName())
147                 || "javax.jms.QueueConnectionFactory".equals(rrDesc[i].getTypeName())
148                 || "javax.jms.ConnectionFactory".equals(rrDesc[i].getTypeName())) {
149                 result.add(rrDesc[i].getJndiName());
150             }
151         }
152         return result;
153     }
154
155     /**
156      * @return Hashtable which maps the JNDI names provided by the DD to the Session Mail factyory resources
157      * known by the Mail Service
158      */

159     public Hashtable JavaDoc getAllMailFactorySName(){
160         Hashtable JavaDoc result = new Hashtable JavaDoc();
161         MailServiceImpl mailServ = null;
162         try {
163             // Modified for use with the gcj compiler
164
ServiceManager sm = ServiceManager.getInstance();
165             mailServ = (MailServiceImpl) sm.getMailService();
166         } catch(Exception JavaDoc e) {
167             // Mail Service not available, mailServ null
168
}
169         String JavaDoc jndiName = null; // name provided by the DD
170
String JavaDoc factoryName = null; // resource name
171

172         ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
173         for (int i = 0; i < rrDesc.length; i ++) {
174             if ("javax.mail.Session".equals(rrDesc[i].getTypeName())) {
175                 // The Bean uses a javax.mail.Session resource
176

177                 // get the DD provided JNDI name
178
jndiName = rrDesc[i].getJndiName();
179
180                 // try to get the mail service
181
if (mailServ != null) {
182                     // get the resource factory name (maybe null if no resource factory registered under the jndiName)
183
factoryName = mailServ.getFactoryName(jndiName);
184                     if (factoryName != null)
185                         result.put(jndiName, factoryName);
186                     else
187                         result.put(jndiName, "");
188                 } else {
189                     // Mail Service not available
190
result.put(jndiName, "");
191                 }
192             }
193         }
194         return result;
195     }
196
197     /**
198      * @return Hashtable which maps the JNDI names provided by the DD to the MimePartDataSource Mail factyory resources
199      * known by the Mail Service
200      */

201     public Hashtable JavaDoc getAllMailFactoryMName() {
202         Hashtable JavaDoc result = new Hashtable JavaDoc();
203         MailServiceImpl mailServ = null;
204         try {
205             // Modified for use with the gcj compiler
206
ServiceManager sm = ServiceManager.getInstance();
207             mailServ = (MailServiceImpl) sm.getMailService();
208         } catch(Exception JavaDoc e) {
209             // Mail Service not available, mailServ null
210
}
211         String JavaDoc jndiName = null;
212         String JavaDoc factoryName = null;
213
214         ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
215         for (int i = 0; i < rrDesc.length; i ++) {
216             if ("javax.mail.internet.MimePartDataSource".equals(rrDesc[i].getTypeName())) {
217                 // the Bean uses a javax.mail.internet.MimePartDataSource resource
218

219                 // get the DD provided JNDI name
220
jndiName = rrDesc[i].getJndiName();
221
222                 if (mailServ != null) {
223                     // get the resource factory name (maybe bull if no resource factory registered under the jndiName)
224
factoryName = mailServ.getFactoryName(jndiName);
225                     if (factoryName != null)
226                         result.put(jndiName, factoryName);
227                     else
228                         result.put(jndiName, "");
229                 } else {
230                     // Mail Service not available
231
result.put(jndiName, "");
232                 }
233             }
234         }
235         return result;
236     }
237
238     /**
239      * @return Set The Name set of the JMS Destinations
240      */

241     public Set JavaDoc getAllJMSDestinationName(){
242         Set JavaDoc result= new HashSet JavaDoc();
243         ResourceEnvRefDesc[] rrDesc = desc.getResourceEnvRefDesc();
244         for (int i = 0; i < rrDesc.length; i ++) {
245             if ((rrDesc[i].getType() == javax.jms.Topic JavaDoc.class )
246                 ||(rrDesc[i].getType() == javax.jms.Queue JavaDoc.class )) {
247                 result.add(rrDesc[i].getJndiName());
248             }
249         }
250         return result;
251     }
252
253     /**
254      * @return Set The URL ressources used by the bean
255      */

256     public Set JavaDoc getAllURLs() {
257         Set JavaDoc result= new HashSet JavaDoc();
258         ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
259         for (int i = 0; i < rrDesc.length; i ++) {
260             if ("java.net.URL".equals(rrDesc[i].getTypeName())) {
261                 result.add(rrDesc[i].getJndiName());
262             }
263         }
264         return result;
265     }
266
267     /**
268      * @return The current instance pool size
269      */

270     public int getCurrentInstancePoolSize(){
271         return ejbToManage.getPoolSize();
272     }
273
274     /**
275      * @return String the JFactory Class
276      */

277     public String JavaDoc getEjbClass(){
278         return desc.getEjbClass().getName();
279     }
280
281     /**
282      * @return String the displayName of the bean, or bean name if not defined.
283      */

284     public String JavaDoc getDisplayName() {
285         return desc.getDisplayName() != null ? desc.getDisplayName() : desc.getEjbName();
286     }
287
288     /**
289      * @return String the JNDI Name of the bean.
290      */

291     public String JavaDoc getJndiName() {
292         return desc.getJndiName();
293     }
294
295     /**
296      * @return String the HomeClass of the bean.
297      */

298     public String JavaDoc getHomeClass() {
299         if (desc.getHomeClass() != null) {
300             return desc.getHomeClass().getName();
301         } else {
302             return null;
303         }
304     }
305
306     /**
307      * @return String the RemoteClass of the bean.
308      */

309     public String JavaDoc getRemoteClass() {
310         if (desc.getRemoteClass() != null) {
311             return desc.getRemoteClass().getName();
312         } else {
313             return null;
314         }
315     }
316
317     /**
318      * @return String the LocalHomeClass of the bean.
319      */

320     public String JavaDoc getLocalHomeClass() {
321         if (desc.getLocalHomeClass() != null) {
322             return desc.getLocalHomeClass().getName();
323         } else {
324             return null;
325         }
326     }
327
328     /**
329      * @return String the LocalClass of the bean.
330      */

331     public String JavaDoc getLocalClass() {
332         if (desc.getLocalClass() != null) {
333             return desc.getLocalClass().getName();
334         } else {
335             return null;
336         }
337     }
338
339 }
340
Popular Tags