01: package org.mockejb.test;
02:
03: import javax.ejb.*;
04: import javax.jms.*;
05: import javax.naming.InitialContext;
06:
07: import org.apache.commons.logging.*;
08:
09: /**
10: * Primitive example of a message bean
11: * @author Alexander Ananiev
12: * @ejb.bean name="SampleMessageBean" destination-type="javax.jms.Topic"
13: * @weblogic.message-driven destination-jndi-name="SampleTopic" connection-factory-jndi-name="SampleConnectionFactory"
14: *
15: */
16: public class SampleMessageBean implements MessageDrivenBean,
17: MessageListener {
18:
19: // logger for this class
20: private static Log logger = LogFactory
21: .getLog(SampleMessageBean.class.getName());
22:
23: /**
24: * Calls StatelessSamppleBean
25: *
26: * @ejb.interface-method
27: * @ejb:transaction type="Required"
28: */
29: public void onMessage(Message msg) {
30:
31: try {
32:
33: String messageText = ((TextMessage) msg).getText();
34:
35: System.out.println("Got message: " + messageText);
36:
37: // Lookup the home
38: SampleServiceHome sampleHome = (SampleServiceHome) (new InitialContext())
39: .lookup(SampleService.JNDI_NAME);
40:
41: // create the bean
42: SampleService sampleBean = sampleHome.create();
43:
44: sampleBean.echoString(messageText);
45: } catch (Exception exception) {
46: throw new EJBException(exception);
47: }
48:
49: }
50:
51: /**
52: * Sets the session context.
53: *
54: * @param ctx MessageDrivenContext Context for session
55: */
56: public void setMessageDrivenContext(MessageDrivenContext ctx) {
57: log("setMessageDrivenContext called");
58: }
59:
60: /**
61: * This method is required by the EJB Specification,
62: * but is not used by this bean.
63: */
64: public void ejbCreate() throws CreateException {
65: log("ejbCreate called");
66: }
67:
68: /**
69: * This method is required by the EJB Specification,
70: * but is not used by this bean.
71: */
72: public void ejbRemove() {
73: log("ejbRemove called");
74: }
75:
76: private void log(String message) {
77: logger.debug(message);
78: }
79:
80: }
|