WebLogic Server 6.0 Code Examples, BEA Systems, Inc.

examples.ejb.basic.statefulSession
Class TraderBean

java.lang.Object
  |
  +--examples.ejb.basic.statefulSession.TraderBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, java.io.Serializable, javax.ejb.SessionBean

public class TraderBean
extends java.lang.Object
implements javax.ejb.SessionBean

TraderBean is a stateful SessionBean. This EJBean illustrates:

Author:
Copyright (c) 1998 by WebLogic, Inc. All Rights Reserved., Copyright (c) 1998-2000 by BEA Systems, Inc. All Rights Reserved.

Field Summary
(package private) static boolean VERBOSE
           
 
Constructor Summary
TraderBean()
           
 
Method Summary
 TradeResult buy(java.lang.String customerName, java.lang.String stockSymbol, int shares)
          Buys shares of a stock for a named customer.
 void ejbActivate()
          This method is required by the EJB Specification, but is not used by this example.
 void ejbCreate()
          This method corresponds to the create method in the home interface "TraderHome.java".
 void ejbPassivate()
          This method is required by the EJB Specification, but is not used by this example.
 void ejbRemove()
          This method is required by the EJB Specification, but is not used by this example.
 double getBalance()
          Returns the current balance of a trading session.
 double getStockPrice(java.lang.String stockSymbol)
          Returns the stock price for a given stock.
 TradeResult sell(java.lang.String customerName, java.lang.String stockSymbol, int shares)
          Sells shares of a stock for a named customer.
 void setSessionContext(javax.ejb.SessionContext ctx)
          Sets the session context.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERBOSE

static final boolean VERBOSE
Constructor Detail

TraderBean

public TraderBean()
Method Detail

buy

public TradeResult buy(java.lang.String customerName,
                       java.lang.String stockSymbol,
                       int shares)
                throws ProcessingErrorException
Buys shares of a stock for a named customer.
Parameters:
customerName - String Customer name
stockSymbol - String Stock symbol
shares - int Number of shares to buy
Returns:
TradeResult Trade Result
Throws:
ProcessingErrorException - if there is an error while buying the shares

ejbActivate

public void ejbActivate()
This method is required by the EJB Specification, but is not used by this example.
Specified by:
ejbActivate in interface javax.ejb.SessionBean

ejbCreate

public void ejbCreate()
               throws javax.ejb.CreateException
This method corresponds to the create method in the home interface "TraderHome.java". The parameter sets of the two methods are identical. When the client calls TraderHome.create(), the container allocates an instance of the EJBean and calls ejbCreate().
Throws:
javax.ejb.CreateException - if there is a problem creating the bean
See Also:
Trader

ejbPassivate

public void ejbPassivate()
This method is required by the EJB Specification, but is not used by this example.
Specified by:
ejbPassivate in interface javax.ejb.SessionBean

ejbRemove

public void ejbRemove()
This method is required by the EJB Specification, but is not used by this example.
Specified by:
ejbRemove in interface javax.ejb.SessionBean

getBalance

public double getBalance()
Returns the current balance of a trading session.
Returns:
double Balance

getStockPrice

public double getStockPrice(java.lang.String stockSymbol)
                     throws ProcessingErrorException
Returns the stock price for a given stock.
Parameters:
stockSymbol - String Stock symbol
Returns:
double Stock price
Throws:
ProcessingErrorException - if there is an error while checking the price

sell

public TradeResult sell(java.lang.String customerName,
                        java.lang.String stockSymbol,
                        int shares)
                 throws ProcessingErrorException
Sells shares of a stock for a named customer.
Parameters:
customerName - String Customer name
stockSymbol - String Stock symbol
shares - int Number of shares to buy
Returns:
TradeResult Trade Result
Throws:
ProcessingErrorException - if there is an error while selling the shares

setSessionContext

public void setSessionContext(javax.ejb.SessionContext ctx)
Sets the session context.
Specified by:
setSessionContext in interface javax.ejb.SessionBean
Parameters:
ctx - SessionContext Context for session

Documentation is available at
http://e-docs.bea.com/wls/docs60

Copyright © 2000 BEA Systems, Inc. All Rights Reserved.