package org.mockejb.test;
import javax.ejb.*;
import javax.jms.*;
import javax.naming.InitialContext;
import org.apache.commons.logging.*;
public class SampleMessageBean implements MessageDrivenBean, MessageListener {
private static Log logger = LogFactory.getLog( SampleMessageBean.class.getName() );
public void onMessage(Message msg) {
try {
String messageText = ((TextMessage)msg).getText();
System.out.println("Got message: "+messageText );
SampleServiceHome sampleHome = (SampleServiceHome)
( new InitialContext()).lookup( SampleService.JNDI_NAME );
SampleService sampleBean = sampleHome.create();
sampleBean.echoString( messageText );
}
catch ( Exception exception ){
throw new EJBException( exception );
}
}
public void setMessageDrivenContext(MessageDrivenContext ctx) {
log("setMessageDrivenContext called");
}
public void ejbCreate() throws CreateException {
log("ejbCreate called");
}
public void ejbRemove() {
log("ejbRemove called");
}
private void log(String message) {
logger.debug(message);
}
}