samples.j2ee.ejb.basic.statefulSession
Class TraderBean

java.lang.Object
  |
  +--samples.j2ee.ejb.basic.statefulSession.TraderBean

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

TraderBean is a stateful SessionBean. This EJBean illustrates:

See Also:
Serialized Form

Field Summary
 java.lang.String traderName
           
 double tradingBalance
           
 
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(java.lang.String traderName)
          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.
 java.lang.String getTraderName()
          Returns the name of this Trader.
 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

traderName

public java.lang.String traderName

tradingBalance

public double tradingBalance
Constructor Detail

TraderBean

public TraderBean()
Method Detail

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

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

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

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

ejbCreate

public void ejbCreate(java.lang.String traderName)
               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().
Parameters:
traderName - String Trader Name
Throws:
javax.ejb.CreateException - if there is a problem creating the bean
See Also:
Trader

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

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

getTraderName

public java.lang.String getTraderName()
Returns the name of this Trader.
Returns:
String traderName

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