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.banknew.ejb;
023:
024: import java.rmi.RemoteException;
025: import java.util.ArrayList;
026: import java.util.Collection;
027: import java.util.Iterator;
028:
029: import javax.ejb.CreateException;
030: import javax.ejb.EJBException;
031: import javax.ejb.FinderException;
032: import javax.ejb.RemoveException;
033: import javax.ejb.SessionContext;
034: import javax.naming.InitialContext;
035: import javax.naming.NamingException;
036:
037: import org.jboss.test.banknew.interfaces.Bank;
038: import org.jboss.test.banknew.interfaces.BankData;
039: import org.jboss.test.banknew.interfaces.BankHome;
040: import org.jboss.test.banknew.interfaces.BankPK;
041: import org.jboss.test.banknew.interfaces.CustomerData;
042: import org.jboss.test.banknew.interfaces.CustomerSession;
043: import org.jboss.test.banknew.interfaces.CustomerSessionHome;
044: import org.jboss.test.util.ejb.SessionSupport;
045:
046: /**
047: * The Session bean represents a bank's business interface.
048: *
049: * @author Andreas Schaefer
050: * @version $Revision: 57211 $
051: *
052: * @ejb:bean name="bank/BankSession"
053: * display-name="Bank Session"
054: * type="Stateless"
055: * view-type="remote"
056: * jndi-name="ejb/bank/BankSession"
057: *
058: * @ejb:interface extends="javax.ejb.EJBObject"
059: *
060: * @ejb:home extends="javax.ejb.EJBHome"
061: *
062: * @ejb:pk extends="java.lang.Object"
063: *
064: * @ejb:transaction type="Required"
065: *
066: * @ejb:ejb-ref ejb-name="bank/Bank"
067: *
068: * @ejb:ejb-ref ejb-name="bank/CustomerSession"
069: */
070: public class BankSessionBean extends SessionSupport {
071:
072: // Constants -----------------------------------------------------
073:
074: // Attributes ----------------------------------------------------
075:
076: // Static --------------------------------------------------------
077:
078: // Constructors --------------------------------------------------
079:
080: // Public --------------------------------------------------------
081:
082: /** The serialVersionUID */
083: private static final long serialVersionUID = -4732008507323917820L;
084:
085: /**
086: * @ejb:interface-method view-type="remote"
087: **/
088: public BankData createBank(String pName, String pAddress)
089: throws CreateException, RemoteException {
090: Bank lBank = getBankHome().create(pName, pAddress);
091: return lBank.getData();
092: }
093:
094: /**
095: * @ejb:interface-method view-type="remote"
096: **/
097: public void removeBank(String pBankId) throws RemoveException,
098: RemoteException {
099: try {
100: getBankHome().findByPrimaryKey(new BankPK(pBankId))
101: .remove();
102: } catch (FinderException fe) {
103: }
104: }
105:
106: /**
107: * @ejb:interface-method view-type="remote"
108: **/
109: public Collection getBanks() throws FinderException,
110: RemoteException {
111: Collection lBanks = getBankHome().findAll();
112: Collection lList = new ArrayList(lBanks.size());
113: Iterator i = lBanks.iterator();
114: while (i.hasNext()) {
115: lList.add(((Bank) i.next()).getData());
116: }
117: return lList;
118: }
119:
120: /**
121: * @ejb:interface-method view-type="remote"
122: **/
123: public CustomerData getCustomer(String pCustomerId)
124: throws FinderException, RemoteException {
125: return getCustomerSession().getCustomer(pCustomerId);
126: }
127:
128: /**
129: * @ejb:interface-method view-type="remote"
130: **/
131: public Collection getCustomers(String pBankId)
132: throws FinderException, RemoteException {
133: return getCustomerSession().getCustomers(pBankId);
134: }
135:
136: /**
137: * @ejb:interface-method view-type="remote"
138: **/
139: public CustomerData createCustomer(String pBankId, String pName,
140: float pInitialDeposit) throws CreateException,
141: RemoteException {
142: return getCustomerSession().createCustomer(pBankId, pName,
143: pInitialDeposit);
144: }
145:
146: /**
147: * @ejb:interface-method view-type="remote"
148: **/
149: public void removeCustomer(String pCustomerId)
150: throws RemoveException, RemoteException {
151: getCustomerSession().removeCustomer(pCustomerId);
152: }
153:
154: private BankHome getBankHome() {
155: try {
156: return (BankHome) new InitialContext()
157: .lookup(BankHome.COMP_NAME);
158: } catch (NamingException ne) {
159: throw new EJBException(ne);
160: }
161: }
162:
163: private CustomerSession getCustomerSession() throws RemoteException {
164: try {
165: return ((CustomerSessionHome) new InitialContext()
166: .lookup(CustomerSessionHome.COMP_NAME)).create();
167: } catch (NamingException ne) {
168: throw new EJBException(ne);
169: } catch (CreateException ce) {
170: throw new EJBException(ce);
171: }
172: }
173:
174: // SessionBean implementation ------------------------------------
175: public void setSessionContext(SessionContext context) {
176: super .setSessionContext(context);
177: }
178: }
179:
180: /*
181: * $Id: BankSessionBean.java 57211 2006-09-26 12:39:46Z dimitris@jboss.org $
182: * Currently locked by:$Locker$
183: * Revision:
184: * $Log$
185: * Revision 1.1.16.2 2006/03/01 15:58:56 adrian
186: * Remove xdoclet from the jca tests + other tidyup
187: *
188: * Revision 1.1.16.1 2005/10/29 05:04:35 starksm
189: * Update the LGPL header
190: *
191: * Revision 1.1 2002/05/04 01:08:25 schaefera
192: * Added new Stats classes (JMS related) to JSR-77 implemenation and added the
193: * bank-new test application but this does not work right now properly but
194: * it is not added to the default tests so I shouldn't bother someone.
195: *
196: * Revision 1.1.2.2 2002/04/29 21:05:17 schaefera
197: * Added new marathon test suite using the new bank application
198: *
199: * Revision 1.1.2.1 2002/04/17 05:07:24 schaefera
200: * Redesigned the banknew example therefore to a create separation between
201: * the Entity Bean (CMP) and the Session Beans (Business Logic).
202: * The test cases are redesigned but not finished yet.
203: *
204: * Revision 1.1.2.2 2002/04/15 04:28:15 schaefera
205: * Minor fixes regarding to the JNDI names of the beans.
206: *
207: * Revision 1.1.2.1 2002/04/15 02:32:24 schaefera
208: * Add a new test version of the bank because the old did no use transactions
209: * and the new uses XDoclet 1.1.2 to generate the DDs and other Java classes.
210: * Also a marathon test is added. Please specify the jbosstest.duration for
211: * how long and the test.timeout (which must be longer than the duration) to
212: * run the test with run_tests.xml, tag marathon-test-and-report.
213: *
214: * Revision 1.2 2001/01/07 23:14:34 peter
215: * Trying to get JAAS to work within test suite.
216: *
217: * Revision 1.1.1.1 2000/06/21 15:52:37 oberg
218: * Initial import of jBoss test. This module contains CTS tests, some simple examples, and small bean suites.
219: *
220: *
221: *
222: */
|