1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) 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   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package uut.ejb;
22  
23  import java.rmi.RemoteException;
24  import javax.ejb.*;
25  
26  import org.apache.log4j.Logger;
27  
28  import uut.service.*;
29  
30  /***
31   * Stateless session bean that provides services for testing.
32   *
33   * Created on 11.12.2004
34   * 
35   * Contributing Author(s):
36   *   Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
37   *   Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
38   *
39   * @author vlads
40   * @version $Revision: 1.2 $ ($Author: vlads $)  $Date: 2004/12/12 02:00:04 $
41   */
42  public class JourUutSessionBean implements SessionBean {
43  
44      protected static final Logger log = Logger.getLogger(JourUutSessionBean.class);
45      
46      private SessionContext ctx;
47      
48      String serviceName;
49      transient private ServiceImplementation si;
50  
51      public int selectService(String serviceName) throws RemoteException {
52          this.serviceName = serviceName;
53          try {
54              Class c = Class.forName(serviceName);
55              //Class c = ClassLoader.getSystemClassLoader().loadClass(serviceName);
56              
57              Object obj = c.newInstance();
58              if (!(obj instanceof ServiceImplementation)) {
59                  log.error("Class " + obj.getClass().getName() + " is not ServiceImplementation");
60                  return 0;
61              }
62              si = (ServiceImplementation) obj;
63              
64              log.debug("class loaded:" + si.getClass().getName());
65  
66          } catch (InstantiationException  e) {
67              log.error("Class instantiation fails " + serviceName, e);
68              return 0;
69          } catch (IllegalAccessException e) {
70              log.error("Class constructor is not accessible " + serviceName, e);
71              return 0;
72          } catch (ClassNotFoundException e) {
73              log.error("Class Not Found " + serviceName, e);
74              return 0;
75          } 
76          return 1;
77      }
78      
79      public int callService(String args) throws RemoteException {
80          if (si == null) {
81              if (selectService(this.serviceName) == 0) {
82                  return 0;
83              }
84          }
85          si.callDoService(args);
86          return 1;
87      }
88  
89  
90  	public void setSessionContext(SessionContext sessionContext) throws EJBException, RemoteException {
91  	    ctx = sessionContext;
92  	}
93  
94  	/***
95  	 * This method corresponds to the create method in the home interface.
96  	 * The parameter sets of the two methods are identical. When the client calls
97  	 * ReportSessionHome.create(), the container allocates an instance of
98  	 * the EJBean and calls <code>ejbCreate()</code>.
99  	 * @exception javax.ejb.CreateException if there is a communications or systems failure
100 	 */
101 	public void ejbCreate() throws EJBException, RemoteException {
102 	}
103 
104 	/***
105 	 * This method is required by the EJB Specification, but is not used by this bean.
106 	 */
107 	public void ejbActivate() throws EJBException, RemoteException {
108 	}
109 	/***
110 	 * This method is required by the EJB Specification, but is not used by this bean.
111 	 */
112 	public void ejbPassivate() throws EJBException, RemoteException {
113 	}
114 
115 	/***
116 	 * This method is required by the EJB Specification, but is not used by this bean.
117 	 */
118 	public void ejbRemove() throws EJBException, RemoteException {
119 	}
120 
121 }
122