001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.testbean.bean;
023:
024: import java.rmi.*;
025: import javax.ejb.*;
026: import javax.naming.InitialContext;
027: import javax.naming.Context;
028:
029: import org.jboss.test.testbean.interfaces.BusinessMethodException;
030:
031: /**
032: * @author Marc Fleury
033: */
034: public class StatelessSessionBean implements SessionBean {
035: org.apache.log4j.Category log = org.apache.log4j.Category
036: .getInstance(getClass());
037: private SessionContext sessionContext;
038:
039: public void ejbCreate() throws RemoteException, CreateException {
040: log.debug("StatelessSessionBean.ejbCreate() called");
041: }
042:
043: public void ejbActivate() throws RemoteException {
044: log.debug("StatelessSessionBean.ejbActivate() called");
045: }
046:
047: public void ejbPassivate() throws RemoteException {
048: log.debug("StatelessSessionBean.ejbPassivate() called");
049: }
050:
051: public void ejbRemove() throws RemoteException {
052: log.debug("StatelessSessionBean.ejbRemove() called");
053: }
054:
055: public void setSessionContext(SessionContext context)
056: throws RemoteException {
057: sessionContext = context;
058: //Exception e = new Exception("in set Session context");
059: //log.debug("failed", e);
060: }
061:
062: public void callBusinessMethodA() {
063: //Do nothing just make sure the call works
064:
065: try {
066: Object tx = ((javax.transaction.TransactionManager) new InitialContext()
067: .lookup("java:/TransactionManager"))
068: .getTransaction();
069: if (tx == null)
070: log.debug("I don't see a transaction");
071: else
072: log.debug("I see a transaction " + tx.hashCode());
073: } catch (Exception e) {
074: log.debug("failed", e);
075: }
076: log.debug("StatelessSessionBean.callBusinessMethodA() called");
077: }
078:
079: public String callBusinessMethodB() {
080: log.debug("StatelessSessionBean.callBusinessMethodB() called");
081: try {
082:
083: Context context = new InitialContext();
084: String name = (String) context
085: .lookup("java:comp/env/myNameProp");
086: return "from the environment properties my name is " + name;
087:
088: } catch (Exception e) {
089: return "Error in the lookup of properties "
090: + e.getMessage();
091: }
092: }
093:
094: public String callBusinessMethodB(String words) {
095: // test if overloaded methods are properly called
096: log
097: .debug("StatelessSessionBean.callBusinessMethodB(String) called");
098: // Check that my EJBObject is there
099: EJBObject ejbObject = sessionContext.getEJBObject();
100: if (ejbObject == null) {
101: return "ISNULL:NOT FOUND!!!!!";
102:
103: } else {
104: return "OK ejbObject is " + ejbObject.toString()
105: + " words " + words;
106:
107: }
108:
109: }
110:
111: public String callBusinessMethodC() {
112: log.debug("StatelessSessionBean.callBusinessMethodC() called");
113: try {
114:
115: Context context = new InitialContext();
116: String name = (String) context
117: .lookup("java:comp/env/subContext/myNameProp");
118: return "from the environment properties (subContext) my name is "
119: + name;
120:
121: } catch (Exception e) {
122: return "Error in the lookup of properties "
123: + e.getMessage();
124: }
125: }
126:
127: public void callBusinessMethodD() throws BusinessMethodException {
128: log.debug("StatelessSessionBean.callBusinessMethodD() called");
129: throw new BusinessMethodException();
130: }
131:
132: public String callBusinessMethodE() {
133: log.debug("StatelessSessionBean.callBusinessMethodE() called");
134: // Check that my EJBObject is there
135: EJBObject ejbObject = sessionContext.getEJBObject();
136: if (ejbObject == null) {
137: return "ISNULL:NOT FOUND!!!!!";
138: } else {
139: return ejbObject.toString();
140: }
141: }
142:
143: public void testClassLoading() throws BusinessMethodException {
144: log.debug("StatelessSessionBean.testClassLoading() called");
145:
146: try {
147: Class.forName("org.somepackage.SomeClass");
148: } catch (Exception e) {
149: log.debug("failed", e);
150: throw new BusinessMethodException();
151: }
152: }
153:
154: }
|