PrescriptionBean.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package bible.ejb.message.prescription;
- import java.io.Serializable;
- import java.rmi.RemoteException;
- import javax.ejb.EJBException;
- import javax.ejb.MessageDrivenBean;
- import javax.ejb.MessageDrivenContext;
- import javax.ejb.CreateException;
- import javax.naming.*;
- import javax.jms.*;
- import org.xml.sax.*;
- import org.xml.sax.helpers.*;
- public class PrescriptionBean implements MessageDrivenBean,javax.jms.MessageListener {
- public PrescriptionBean() {
- }
- public void setMessageDrivenContext(MessageDrivenContext mdc)
- {
- }
- public void ejbCreate() {
- }
- public void onMessage(Message incomingMsg) {
- TextMessage msg = null;
- String msgType = null;
- String msgPayload = null;
- try {
- if (incomingMsg instanceof TextMessage) {
- msg = (TextMessage) incomingMsg;
- msgType = msg.getStringProperty("neccesity");
- msgPayload = msg.getText();
- if (msgType.equals("immediate"))
- processPrescription(msgPayload);
- } else {
- System.out.println("Only accepting text messages");
- }
- } catch (JMSException e) {
- e.printStackTrace();
- } catch (Throwable te) {
- te.printStackTrace();
- }
- }
- public void ejbRemove() {
- }
- public void processPrescription(String prescriptionXmlDocument)
- {
- try {
- PrescriptionXmlParser parser = new PrescriptionXmlParser();
- // Create SAX 2 parser...
- XMLReader xr = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
- // Set the ContentHandler...
- xr.setContentHandler(parser);
- xr.parse( prescriptionXmlDocument );
- Prescription currentPrescription = parser.getPrescription();
- // Now that you have the prescription object
- // you can make calls to various backend order
- // management systems
- }
- catch (Exception e)
- {
- System.out.println("Message not parsed correctly");
- }
- }
- }