01: /*
02: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. U.S.
03: * Government Rights - Commercial software. Government users are subject
04: * to the Sun Microsystems, Inc. standard license agreement and
05: * applicable provisions of the FAR and its supplements. Use is subject
06: * to license terms.
07: *
08: * This distribution may include materials developed by third parties.
09: * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
10: * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
11: * other countries.
12: *
13: * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
14: *
15: * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
16: * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
17: * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
18: * en vigueur de la FAR (Federal Acquisition Regulations) et des
19: * supplements a celles-ci. Distribue par des licences qui en
20: * restreignent l'utilisation.
21: *
22: * Cette distribution peut comprendre des composants developpes par des
23: * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
24: * sont des marques de fabrique ou des marques deposees de Sun
25: * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
26: */
27:
28: package beans;
29:
30: import java.util.logging.Logger;
31: import javax.ejb.MessageDrivenBean;
32: import javax.ejb.MessageDrivenContext;
33: import javax.jms.*;
34:
35: /**
36: * This is the bean class for the SimpleMessageBean enterprise bean.
37: * Created Mar 23, 2005 11:11:52 AM
38: * @author blaha
39: */
40: public class SimpleMessageBean implements MessageDrivenBean,
41: MessageListener {
42: static final Logger logger = Logger.getLogger("SimpleMessageBean");
43: private MessageDrivenContext context;
44:
45: // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click on the + sign on the left to edit the code.">
46:
47: /**
48: * @see javax.ejb.MessageDrivenBean#setMessageDrivenContext(javax.ejb.MessageDrivenContext)
49: */
50: public void setMessageDrivenContext(MessageDrivenContext aContext) {
51: logger.info("In SimpleMessageBean.setMessageDrivenContext()");
52: context = aContext;
53: }
54:
55: /**
56: * See section 15.4.4 of the EJB 2.0 specification
57: * See section 15.7.3 of the EJB 2.1 specification
58: */
59: public void ejbCreate() {
60: // TODO Add code to acquire and use other enterprise resources (DataSource, JMS, enterprise bean, Web services)
61: logger.info("In SimpleMessageBean.ejbCreate()");
62: }
63:
64: /**
65: * @see javax.ejb.MessageDrivenBean#ejbRemove()
66: */
67: public void ejbRemove() {
68: // TODO release any resource acquired in ejbCreate.
69: // The code here should handle the possibility of not getting invoked
70: // See section 15.7.3 of the EJB 2.1 specification
71: logger.info("In SimpleMessageBean.ejbRemove()");
72: }
73:
74: // </editor-fold>
75:
76: public void onMessage(Message aMessage) {
77: TextMessage msg = null;
78: try {
79: if (aMessage instanceof TextMessage) {
80: msg = (TextMessage) aMessage;
81: logger.info("MESSAGE BEAN: Message received: "
82: + msg.getText());
83: } else {
84: logger.warning("Message of wrong type: "
85: + aMessage.getClass().getName());
86: }
87: } catch (JMSException e) {
88: e.printStackTrace();
89: context.setRollbackOnly();
90: } catch (Throwable te) {
91: te.printStackTrace();
92: }
93:
94: }
95:
96: }
|