KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > testbean > bean > StatelessSessionBean


1
2 //Title: telkel
3
//Version:
4
//Copyright: Copyright (c) 1999
5
//Author: Marc Fleury
6
//Company: telkel
7

8 /*
9   * JBoss, Home of Professional Open Source
10   * Copyright 2005, JBoss Inc., and individual contributors as indicated
11   * by the @authors tag. See the copyright.txt in the distribution for a
12   * full listing of individual contributors.
13   *
14   * This is free software; you can redistribute it and/or modify it
15   * under the terms of the GNU Lesser General Public License as
16   * published by the Free Software Foundation; either version 2.1 of
17   * the License, or (at your option) any later version.
18   *
19   * This software is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22   * Lesser General Public License for more details.
23   *
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this software; if not, write to the Free
26   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
28   */

29 package org.jboss.test.testbean.bean;
30
31 import java.rmi.*;
32 import javax.ejb.*;
33 import javax.naming.InitialContext JavaDoc;
34 import javax.naming.Context JavaDoc;
35 import org.jboss.test.testbean.interfaces.BusinessMethodException;
36
37 public class StatelessSessionBean implements SessionBean {
38    org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass());
39   private SessionContext sessionContext;
40
41   public void ejbCreate() throws RemoteException, CreateException {
42   log.debug("StatelessSessionBean.ejbCreate() called");
43   }
44
45   public void ejbActivate() throws RemoteException {
46     log.debug("StatelessSessionBean.ejbActivate() called");
47   }
48
49   public void ejbPassivate() throws RemoteException {
50       log.debug("StatelessSessionBean.ejbPassivate() called");
51   }
52
53   public void ejbRemove() throws RemoteException {
54      log.debug("StatelessSessionBean.ejbRemove() called");
55   }
56
57   public void setSessionContext(SessionContext context) throws RemoteException {
58     sessionContext = context;
59     //Exception e = new Exception("in set Session context");
60
//log.debug("failed", e);
61
}
62
63   public void callBusinessMethodA() {
64       //Do nothing just make sure the call works
65

66       try {
67          Object JavaDoc tx = ((javax.transaction.TransactionManager JavaDoc) new InitialContext JavaDoc().lookup("java:/TransactionManager")).getTransaction();
68          if (tx == null)
69            log.debug("I don't see a transaction");
70          else
71            log.debug("I see a transaction "+tx.hashCode());
72       }
73       catch (Exception JavaDoc e) {log.debug("failed", e);}
74       log.debug("StatelessSessionBean.callBusinessMethodA() called");
75    }
76
77   public String JavaDoc callBusinessMethodB() {
78        log.debug("StatelessSessionBean.callBusinessMethodB() called");
79        try {
80
81            Context JavaDoc context = new InitialContext JavaDoc();
82            String JavaDoc name = (String JavaDoc) context.lookup("java:comp/env/myNameProp");
83            return "from the environment properties my name is "+name;
84
85        }catch (Exception JavaDoc e) { return "Error in the lookup of properties "+e.getMessage();}
86   }
87
88   public String JavaDoc callBusinessMethodB(String JavaDoc words) {
89          // test if overloaded methods are properly called
90
log.debug("StatelessSessionBean.callBusinessMethodB(String) called");
91          // Check that my EJBObject is there
92
EJBObject ejbObject = sessionContext.getEJBObject();
93         if (ejbObject == null) {
94           return "ISNULL:NOT FOUND!!!!!";
95        
96         }
97         else {
98          return "OK ejbObject is "+ejbObject.toString()+" words "+words;
99          
100         }
101   
102   }
103
104   public String JavaDoc callBusinessMethodC() {
105        log.debug("StatelessSessionBean.callBusinessMethodC() called");
106        try {
107
108            Context JavaDoc context = new InitialContext JavaDoc();
109            String JavaDoc name = (String JavaDoc) context.lookup("java:comp/env/subContext/myNameProp");
110            return "from the environment properties (subContext) my name is "+name;
111
112        }catch (Exception JavaDoc e) { return "Error in the lookup of properties "+e.getMessage();}
113   }
114
115    public void callBusinessMethodD() throws BusinessMethodException {
116        log.debug("StatelessSessionBean.callBusinessMethodD() called");
117        throw new BusinessMethodException();
118   }
119   
120   public String JavaDoc callBusinessMethodE() {
121         log.debug("StatelessSessionBean.callBusinessMethodE() called");
122          // Check that my EJBObject is there
123
EJBObject ejbObject = sessionContext.getEJBObject();
124         if (ejbObject == null) {
125           return "ISNULL:NOT FOUND!!!!!";
126         }
127         else {
128          return ejbObject.toString();
129         }
130   }
131   
132    public void testClassLoading() throws BusinessMethodException {
133        log.debug("StatelessSessionBean.testClassLoading() called");
134        
135         try{
136             Class.forName("org.somepackage.SomeClass");
137         } catch( Exception JavaDoc e){
138             log.debug("failed", e);
139             throw new BusinessMethodException();
140         }
141   }
142   
143 }
144
Popular Tags