OrderVerifierEJB.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- package day21ex.orderverifier;
- import javax.ejb.*;
- import javax.jms.*;
- import javax.naming.*;
- import javax.rmi.PortableRemoteObject;
- import day21ex.order.*;
- public class OrderVerifierEJB
- implements MessageDrivenBean, MessageListener {
- protected MessageDrivenContext ctx;
- public void onMessage(Message msg) {
- TextMessage tm = (TextMessage) msg;
- try {
- String orderID = tm.getText();
- print("Processing order " + orderID);
- Context ctx = new InitialContext();
- OrderLocalHome home = (OrderLocalHome)
- PortableRemoteObject.narrow(
- ctx.lookup("day21ex/Order"), OrderLocalHome.class);
- OrderLocal order = home.findByPrimaryKey(orderID);
- order.setStatus("Verified");
- }
- catch (Exception e) {
- e.printStackTrace();
- throw new EJBException(e);
- }
- }
- public void setMessageDrivenContext(MessageDrivenContext ctx) {
- this.ctx = ctx;
- print("setMessageDrivenContext()");
- }
- public void ejbCreate() {
- print("ejbCreate()");
- }
- public void ejbRemove() {
- print("ejbRemove()");
- }
- void print(String s) {
- System.out.println("OrderVerifierEJB:"+ s);
- }
- }