📄 exchangebean.java
字号:
/*
* @author : Elangovan
* @version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the File : ExchangeBean.java
*
* Creation / Modification History
* Elangovan 26-Apr-2002 Created
*
*/
package oracle.otnsamples.ibfbs.admin.ejb;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.InitialContext;
import javax.naming.Context;
import java.util.Date;
/**
* This class implements the Exchange interface. This bean stimulates a Stock
* Exchange, it executes all orders it receives and sends an conformation email.
* To enable asynchronous processing, all orders are queued in the ExchangeQueue
* and then processed by Exchange Service.
*
* @see ExchangeQueue.java
*
*/
public class ExchangeBean implements SessionBean {
// Handle to MailService Home
private MailServiceHome mailServiceHome = null;
/**
* Standard callback method, invoked by Container when this Session Bean
* is created. Initializes MailService.
*/
public void ejbCreate() {
try {
// Lookup for mailservice
Context ctx = new InitialContext();
mailServiceHome = (MailServiceHome) ctx.lookup("MailService");
} catch(Exception ex) {
System.err.println("ExchangeBean.ejbCreate: Could not initialize Mail Service :"+
ex.toString());
}
}
/**
* Executes the trade order and sends a confirmation mail.
*
* @param toAddress To mail address where confirmation has to be sent
* @param symbol stock symbol traded
* @param tradeDate trade date
* @param tradeType Trade type, S - sell, B - buy, T - transfer
* @param qty quantity of stocks traded
* @return status of process order, 0 - success, -1 - failure
* @since 1.0
*/
public Integer processOrder(String toAddress, String symbol, Date tradeDate,
String tradeType, Integer qty) {
// Its assumed that sending a mail sucessfully completes the order processing
// Status of the processed order
Integer executed = new Integer(-1);
try {
// Update Order Status in Trade Details
// ..........
// Send the confirmation mail
MailService mailService = mailServiceHome.create();
executed = mailService.sendMail(toAddress, "Exchange@fbs.com",
" Stock Order executed ",
getMsg(symbol, tradeDate, tradeType,
qty));
} catch (Exception ex) { // Failure
System.err.println("ExchangeBean.processOrder: Error processing Order :" + ex.toString());
}
return executed;
}
/**
* Constructs a HTML message for order confirmation.
*
* @param symbol stock symbol
* @param tradeDate trade date
* @param tradeType trade type , 'S' - sell , 'B' - buy
* @param qty Quantity traded
* @return mail body in HTML format
* @since 1.0
*/
private String getMsg(String symbol, Date tradeDate, String tType,
Integer qty) {
StringBuffer sb = new StringBuffer();
String tradeType = null;
if (tType.equals("T")) {
tradeType = " Transfer ";
} else if (tType.equals("B")) {
tradeType = " Buy ";
} else if (tType.equals("S")) {
tradeType = " Sell ";
}
sb.append("<br><br>")
.append(" Hi, <br><br>")
.append("<br><h4><u>Trade Order Details</u></h4>")
.append("<table border='1'>")
.append(" <tr><td> Symbol</td><td>" + symbol + "</td></tr>")
.append(" <tr><td> Type</td><td>" + tradeType + "</td></tr>")
.append(" <tr><td> Date</td><td>" + tradeDate + "</td></tr>")
.append(" <tr><td> Quantity</td><td>" + qty.intValue() + "</td></tr>")
.append("</table><br>")
.append("<font color='#008000'><b>Your order has been executed ")
.append("successfully.</b></font><br>")
.append("<br><br>")
.append("Thank you for trading with us.")
.append("<br><br>Happy Trading !! <br> FBS Team.");
return sb.toString();
}
// Standard call back methods
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbRemove() {}
public void setSessionContext(SessionContext ctx) {}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -