1 2 8 29 package org.jboss.test.testbean.bean; 30 31 import java.rmi.*; 32 import javax.ejb.*; 33 import javax.naming.InitialContext ; 34 import javax.naming.Context ; 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 } 62 63 public void callBusinessMethodA() { 64 66 try { 67 Object tx = ((javax.transaction.TransactionManager ) new InitialContext ().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 e) {log.debug("failed", e);} 74 log.debug("StatelessSessionBean.callBusinessMethodA() called"); 75 } 76 77 public String callBusinessMethodB() { 78 log.debug("StatelessSessionBean.callBusinessMethodB() called"); 79 try { 80 81 Context context = new InitialContext (); 82 String name = (String ) context.lookup("java:comp/env/myNameProp"); 83 return "from the environment properties my name is "+name; 84 85 }catch (Exception e) { return "Error in the lookup of properties "+e.getMessage();} 86 } 87 88 public String callBusinessMethodB(String words) { 89 log.debug("StatelessSessionBean.callBusinessMethodB(String) called"); 91 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 callBusinessMethodC() { 105 log.debug("StatelessSessionBean.callBusinessMethodC() called"); 106 try { 107 108 Context context = new InitialContext (); 109 String name = (String ) context.lookup("java:comp/env/subContext/myNameProp"); 110 return "from the environment properties (subContext) my name is "+name; 111 112 }catch (Exception 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 callBusinessMethodE() { 121 log.debug("StatelessSessionBean.callBusinessMethodE() called"); 122 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 e){ 138 log.debug("failed", e); 139 throw new BusinessMethodException(); 140 } 141 } 142 143 } 144 | Popular Tags |