EJB.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: EJB.java,v 1.6 2004/12/07 15:35:25 danesa Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.container;
00027 
00028 import java.util.Enumeration;
00029 import java.util.HashSet;
00030 import java.util.Hashtable;
00031 import java.util.Set;
00032 import java.util.Vector;
00033 
00034 import org.objectweb.jonas.dbm.DataBaseServiceImpl;
00035 import org.objectweb.jonas.mail.MailServiceImpl;
00036 import org.objectweb.jonas.management.j2eemanagement.J2EEManagedObject;
00037 import org.objectweb.jonas.service.ServiceException;
00038 import org.objectweb.jonas.service.ServiceManager;
00039 import org.objectweb.jonas_ejb.container.JFactory;
00040 import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
00041 import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp1Desc;
00042 import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp2Desc;
00043 import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc;
00044 import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc;
00045 
00051 public class EJB extends J2EEManagedObject {
00055     protected JFactory ejbToManage = null;
00056     protected BeanDesc desc = null;
00057     protected String fileName = null;
00058 
00059     public EJB(String objectName, JFactory ejbToManage) {
00060         super(objectName);
00061         this.ejbToManage = ejbToManage;
00062         this.fileName = ejbToManage.getContainer().getFileName();
00063         this.desc = ejbToManage.getDeploymentDescriptor();
00064     }
00065 
00066 
00070     public String getName() {
00071         return desc.getEjbName();
00072     }
00073 
00077     public String getFileName() {
00078         return fileName;
00079     }
00080 
00084     public Hashtable getAllDataSourceName() {
00085         Hashtable result = new Hashtable();
00086         
00087         DataBaseServiceImpl bdmServ = null;
00088         String jndiName = null;
00089         Vector jndiNames = new Vector();
00090         String datasourceName = null;
00091 
00092         // find the resource refs
00093         ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
00094         for (int i = 0; i < rrDesc.length; i ++) {
00095             if (rrDesc[i].isJdbc()) {
00096                 // get the DD provided JNDI name
00097                 jndiName = rrDesc[i].getJndiName();
00098                 jndiNames.add(jndiName);
00099             }
00100         }
00101 
00102         // if the EJB is an entity with CMP, we have to find jndi name in the jdbc_mapping
00103         // in case of CMP1 :
00104         EntityJdbcCmp1Desc jdbcCmp1Desc = null;
00105         try {
00106             jdbcCmp1Desc = (EntityJdbcCmp1Desc) desc;
00107             jndiName = jdbcCmp1Desc.getDatasourceJndiName();
00108             jndiNames.add(jndiName);
00109         } catch (Exception e) {
00110         }
00111         // in case of CMP2 :
00112         EntityJdbcCmp2Desc jdbcCmp2Desc = null;
00113         try {
00114             jdbcCmp2Desc = (EntityJdbcCmp2Desc) desc;
00115             jndiName = jdbcCmp2Desc.getDatasourceJndiName();
00116             jndiNames.add(jndiName);
00117         } catch (Exception e) {
00118         }
00119 
00120         if (!jndiNames.isEmpty()) {
00121             try {
00122                 // Modified for use with the gcj compiler
00123                 ServiceManager sm = ServiceManager.getInstance();
00124                 bdmServ = (DataBaseServiceImpl) sm.getDataBaseService();
00125             } catch(Exception e) {
00126                 // DataBase Service not available
00127                 // Temporary solution
00128                 return result;                  
00129             }
00130         }
00131 
00132         for (Enumeration e = jndiNames.elements() ; e.hasMoreElements() ;) {
00133             jndiName = (String)e.nextElement();
00134             datasourceName = bdmServ.getDatasourceName(jndiName);
00135             if (datasourceName != null)
00136                 result.put(jndiName, datasourceName);
00137             else
00138                 result.put(jndiName, "");
00139         }
00140 
00141         return result;
00142     }
00143 
00144  
00148     public Set getAllJMSConnectionFactoryName(){
00149         Set result= new HashSet();
00150         ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
00151         for (int i = 0; i < rrDesc.length; i ++) {
00152             if ("javax.jms.TopicConnectionFactory".equals(rrDesc[i].getTypeName())
00153                 || "javax.jms.QueueConnectionFactory".equals(rrDesc[i].getTypeName())
00154                 || "javax.jms.ConnectionFactory".equals(rrDesc[i].getTypeName())) {
00155                 result.add(rrDesc[i].getJndiName()); 
00156             }
00157         }
00158         return result;
00159     }
00160 
00165     public Hashtable getAllMailFactorySName(){
00166         Hashtable result = new Hashtable();
00167         MailServiceImpl mailServ = null;
00168         try {
00169             // Modified for use with the gcj compiler
00170             ServiceManager sm = ServiceManager.getInstance();
00171             mailServ = (MailServiceImpl) sm.getMailService();
00172         } catch(Exception e) {
00173             // Mail Service not available, mailServ null
00174         }
00175         String jndiName = null; // name provided by the DD
00176         String factoryName = null; // resource name 
00177 
00178         ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
00179         for (int i = 0; i < rrDesc.length; i ++) {
00180             if ("javax.mail.Session".equals(rrDesc[i].getTypeName())) {
00181                 // The Bean uses a javax.mail.Session resource
00182 
00183                 // get the DD provided JNDI name
00184                 jndiName = rrDesc[i].getJndiName();
00185 
00186                 // try to get the mail service
00187                 if (mailServ != null) {                         
00188                     // get the resource factory name (maybe null if no resource factory registered under the jndiName)
00189                     factoryName = mailServ.getFactoryName(jndiName);
00190                     if (factoryName != null)
00191                         result.put(jndiName, factoryName);
00192                     else
00193                         result.put(jndiName, "");
00194                 } else {
00195                     // Mail Service not available
00196                     result.put(jndiName, "");
00197                 }
00198             }
00199         }
00200         return result;
00201     }
00202 
00207     public Hashtable getAllMailFactoryMName() {
00208         Hashtable result = new Hashtable();
00209         MailServiceImpl mailServ = null; 
00210         try {
00211             // Modified for use with the gcj compiler
00212             ServiceManager sm = ServiceManager.getInstance();
00213             mailServ = (MailServiceImpl) sm.getMailService();
00214         } catch(Exception e) {
00215             // Mail Service not available, mailServ null
00216         }
00217         String jndiName = null;
00218         String factoryName = null;
00219 
00220         ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
00221         for (int i = 0; i < rrDesc.length; i ++) {
00222             if ("javax.mail.internet.MimePartDataSource".equals(rrDesc[i].getTypeName())) {
00223                 // the Bean uses a javax.mail.internet.MimePartDataSource resource
00224 
00225                 // get the DD provided JNDI name
00226                 jndiName = rrDesc[i].getJndiName();
00227 
00228                 if (mailServ != null) {
00229                     // get the resource factory name (maybe bull if no resource factory registered under the jndiName)
00230                     factoryName = mailServ.getFactoryName(jndiName);
00231                     if (factoryName != null) 
00232                         result.put(jndiName, factoryName);
00233                     else
00234                         result.put(jndiName, "");
00235                 } else {
00236                     // Mail Service not available
00237                     result.put(jndiName, "");
00238                 }
00239             }
00240         }
00241         return result;
00242     }
00243 
00247     public Set getAllJMSDestinationName(){
00248         Set result= new HashSet();
00249         ResourceEnvRefDesc[] rrDesc = desc.getResourceEnvRefDesc();
00250         for (int i = 0; i < rrDesc.length; i ++) {
00251             if ((rrDesc[i].getType() == javax.jms.Topic.class )
00252                 ||(rrDesc[i].getType() == javax.jms.Queue.class )) { 
00253                 result.add(rrDesc[i].getJndiName()); 
00254             }
00255         }
00256         return result;
00257     }
00258 
00262     public Set getAllURLs() {
00263         Set result= new HashSet();
00264         ResourceRefDesc[] rrDesc = desc.getResourceRefDesc();
00265         for (int i = 0; i < rrDesc.length; i ++) {
00266             if ("java.net.URL".equals(rrDesc[i].getTypeName())) {
00267                 result.add(rrDesc[i].getJndiName()); 
00268             }
00269         }
00270         return result;        
00271     }
00272 
00276     public  int getCurrentInstancePoolSize(){
00277         return ejbToManage.getPoolSize();
00278     }
00279 
00283     public String getEjbClass(){
00284         return desc.getEjbClass().getName();
00285     }
00286 
00290     public String getDisplayName() {
00291         return desc.getDisplayName() != null ? desc.getDisplayName() : desc.getEjbName();
00292     }
00293 
00297     public String getJndiName() {
00298         return desc.getJndiName();
00299     }
00300 
00304     public String getHomeClass() {
00305         if (desc.getHomeClass() != null) {
00306             return desc.getHomeClass().getName();
00307         } else {
00308             return null;
00309         }
00310     }
00311 
00315     public String getRemoteClass() {
00316         if (desc.getRemoteClass() != null) {
00317             return desc.getRemoteClass().getName();
00318         } else {
00319             return null;
00320         }
00321     }
00322 
00326     public String getLocalHomeClass() {
00327         if (desc.getLocalHomeClass() != null) {
00328             return desc.getLocalHomeClass().getName();
00329         } else {
00330             return null;
00331         }
00332     }
00333 
00337     public String getLocalClass() {
00338         if (desc.getLocalClass() != null) {
00339             return desc.getLocalClass().getName();
00340         } else {
00341             return null;
00342         }
00343     }
00344 
00345 }

Generated on Tue Feb 15 15:05:14 2005 for JOnAS by  doxygen 1.3.9.1