WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

examples.jms.messageformat
Class MessageTraderBean

java.lang.Object
  |
  +--examples.jms.messageformat.MessageTraderBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, javax.ejb.MessageDrivenBean, javax.jms.MessageListener, java.io.Serializable

public class MessageTraderBean
extends java.lang.Object
implements javax.ejb.MessageDrivenBean, javax.jms.MessageListener

This class reads the XML data from a JMS queue, parses it and and calls the statefulSession.TraderBean EJB to actually perform the stock trade transaction. The class then puts the output of the trade on another JMS queue.

Author:
Copyright (c) 2002 by BEA Systems, Inc. All Rights Reserved.

Field Summary
static java.lang.StringBuffer buffer
           
static java.lang.String JMS_FACTORY
          Defines the JMS connection factory for the queue.
static java.lang.String JNDI_FACTORY
           
static java.lang.String QUEUE
          Defines the queue.
 
Constructor Summary
MessageTraderBean()
           
 
Method Summary
 void close()
          Closes all JMS objects.
 void ejbActivate()
          This method is not used by this example.
 void ejbCreate()
          This method is not used by this example.
 void ejbPassivate()
          This method is not used by this example.
 void ejbRemove()
          This method is not used by this example.
 void init(javax.naming.Context ctx, java.lang.String queueName)
          Creates all the necessary objects for sending messages to a JMS queue.
 void onMessage(javax.jms.Message msg)
          Retrieves the XML data from the first JMS queue then parses the data using a SAX parser.
(package private) static void p(java.lang.String s)
           
 void send(java.lang.String message)
          Sends a message in the form of XML data to a JMS queue.
 void setMessageDrivenContext(javax.ejb.MessageDrivenContext ctx)
          Sets the session context.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

public static final java.lang.StringBuffer buffer

JMS_FACTORY

public static final java.lang.String JMS_FACTORY
Defines the JMS connection factory for the queue.

JNDI_FACTORY

public static final java.lang.String JNDI_FACTORY

QUEUE

public static final java.lang.String QUEUE
Defines the queue.
Constructor Detail

MessageTraderBean

public MessageTraderBean()
Method Detail

close

public void close()
           throws javax.jms.JMSException
Closes all JMS objects.
Throws:
javax.jms.JMSException - if JMS fails to close objects due to internal error

ejbActivate

public void ejbActivate()
This method is not used by this example.

ejbCreate

public void ejbCreate()
               throws javax.ejb.CreateException
This method is not used by this example.

ejbPassivate

public void ejbPassivate()
This method is not used by this example.

ejbRemove

public void ejbRemove()
This method is not used by this example.
Specified by:
ejbRemove in interface javax.ejb.MessageDrivenBean

init

public void init(javax.naming.Context ctx,
                 java.lang.String queueName)
          throws javax.naming.NamingException,
                 javax.jms.JMSException
Creates all the necessary objects for sending messages to a JMS queue.
Parameters:
ctx - JNDI initial context
queueName - name of queue
Throws:
javax.naming.NamingException - if operation cannot be performed
javax.jms.JMSException - if JMS fails to initialize due to internal error

onMessage

public void onMessage(javax.jms.Message msg)
Retrieves the XML data from the first JMS queue then parses the data using a SAX parser. The method then calls the Trader stateful Session EJB to perform the actual trade on the data. Finally, this method creates a new XML message which will be sent to a second JMS queue.
Specified by:
onMessage in interface javax.jms.MessageListener
Parameters:
msg - the JMS message

p

static void p(java.lang.String s)

send

public void send(java.lang.String message)
          throws javax.jms.JMSException
Sends a message in the form of XML data to a JMS queue.
Parameters:
message - the String message to be sent to the JMS queue

setMessageDrivenContext

public void setMessageDrivenContext(javax.ejb.MessageDrivenContext ctx)
Sets the session context.
Specified by:
setMessageDrivenContext in interface javax.ejb.MessageDrivenBean
Parameters:
ctx - MessageDrivenContext Context for session

Documentation is available at
http://e-docs.bea.com/wls/docs70

Copyright © 2002 BEA Systems, Inc. All Rights Reserved.