samples.j2ee.ejb.basic.statelessSession
Class TraderBean

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

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

TraderBean is a stateless SessionBean. This bean illustrates:

See Also:
Serialized Form

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 getStockPrice(java.lang.String stockSymbol)
          Returns the stock price for a given stock.
 int getTradeLimit()
          This method retrieves the tradeLimit environment property from the deployment descriptor.
 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
 

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()
               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 communications or systems failure
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

getTradeLimit

public int getTradeLimit()
This method retrieves the tradeLimit environment property from the deployment descriptor. This is done using JNDI lookup. Returns the trading limit.
Returns:
int Trading limit

getStockPrice

public double getStockPrice(java.lang.String stockSymbol)
                     throws ProcessingErrorException
Returns the stock price for a given stock. Stock symbol and its price are entered in the deployment descriptor's environment section.
Parameters:
stockSymbol - String Stock symbol
Returns:
double Stock price
Throws:
ProcessingErrorException - if there is an error while checking the price