FileDocCategorySizeDatePackage
OrderProcessorMDB.javaAPI DocJBoss 4.2.17247Fri Jul 13 20:55:58 BST 2007xpetstore.services.order.ejb

OrderProcessorMDB

public class OrderProcessorMDB extends Object implements javax.jms.MessageListener
ejb.bean name="OrderProcessor" acknowledge-mode="Auto-acknowledge" destination-type="javax.jms.Queue" subscription-durability="Durable" transaction-type="Container"
ejb.transaction type="Required"
ejb.ejb-ref ejb-name="Order" view-type="local" ref-name="ejb/OrderLocal"
ejb.resource-ref res-ref-name="${jndi.queue.ConnectionFactory}" res-type="javax.jms.QueueConnectionFactory" res-auth="Container" jndi-name="${orion.queue.ConnectionFactory}"
ejb.resource-ref res-ref-name="${jndi.queue.mail}" res-type="javax.jms.Queue" res-auth="Container" jndi-name="${orion.queue.mail}"
jboss.destination-jndi-name name="${jboss.queue.order}"
jboss.resource-ref res-ref-name="${jndi.queue.ConnectionFactory}" jndi-name="${jboss.queue.ConnectionFactory}"
jboss.resource-ref res-ref-name="${jndi.queue.mail}" jndi-name="${jboss.queue.mail}"
weblogic.message-driven destination-jndi-name="${weblogic.queue.order}"
weblogic.resource-description res-ref-name="${jndi.queue.ConnectionFactory}" jndi-name="${weblogic.queue.ConnectionFactory}"
weblogic.resource-description res-ref-name="${jndi.queue.mail}" jndi-name="${weblogic.queue.mail}"
orion.bean connection-factory-location="${orion.queue.ConnectionFactory}" destination-location="${orion.queue.order}"

Fields Summary
private EntityManager
manager
Constructors Summary
Methods Summary
private voidcancelOrder(xpetstore.domain.order.ejb.Order order)

        order.changeStatus( OrderStatus.CANCELLED );
        notifyCustomer( order );
    
private voidnotifyCustomer(xpetstore.domain.order.ejb.Order order)

    	Customer customer = order.getCustomer(  );
    	if ( customer == null)
    	{
    		Debug.print( "No customer to notify" );
    		return;
    	}
    	 
        String to = customer.getEmail(  );
        String subject = "[Petstore] Order Confirmation";
        String body = toHtml( order );
        JMSUtil.sendToJMSQueue( JNDINames.QUEUE_MAIL, new Email( to, subject, body ), false );
    
public voidonMessage(javax.jms.Message recvMsg)
This method expect a javax.jms.ObjectMessage that contains the orderUId as the message object

        Integer    orderUId = null;
        Order order = null;

        try
        {
            Debug.print( "OrderProcessorMDB.onMessage(" + recvMsg + ")" );

            /* Get the order to proceed */
            ObjectMessage msg = ( ObjectMessage ) recvMsg;
            orderUId = ( Integer ) msg.getObject(  );
            order    = manager.find( Order.class, orderUId );

            /* Proceed the order */
            proceedPayment( order );
            proceedOrder( order );
        }
        catch ( CreditCardException c )
        {
            try
            {
                cancelOrder( order );
            }
            catch ( Exception e )
            {
                Debug.print( "Unable to cancel the order[" + orderUId + "]", e );
            }
        }
        catch ( Exception e )
        {
            Debug.print( "Unable to proceed the order[" + orderUId + "]", e );
        }
    
private voidproceedOrder(xpetstore.domain.order.ejb.Order order)

        order.changeStatus( OrderStatus.TO_DELIVER );
        notifyCustomer( order );
    
private voidproceedPayment(xpetstore.domain.order.ejb.Order order)

private java.lang.StringtoHtml(xpetstore.domain.order.ejb.Order order)

        StringBuffer buff = new StringBuffer(  );

        /* Id/Status */
        buff.append( "<table border='1' width='100%'>" );
        buff.append( "<tr><td width='10%'><b>Order ID:</b></td><td>" + order.getOrderUId(  ) + "</td></tr>" );
        buff.append( "<tr><td width='10%'><b>Status:</b></td><td>" + order.getStatus(  ) + "</td></tr>" );
        buff.append( "</table>" );

        /* Shipping/Bill address Address */
        buff.append( "<table border='1' width='100%'><tr>" );
        buff.append( "<td width='10%' valign='top'><b>Address:</b></td>" );
        buff.append( "<td>" );
        buff.append( order.getStreet1(  ) + "<br>" );
        buff.append( order.getStreet2(  ) + "<br>" );
        buff.append( order.getCity(  ) + "," + order.getState(  ) + "<br>" );
        buff.append( order.getZipcode(  ) + "<br>" );
        buff.append( order.getCountry(  ) );
        buff.append( "</td>" );
        buff.append( "</tr></table>" );

        /* Items */
        Collection orderItems = order.getOrderItems(  );
        buff.append( "<table border='1' width='100%'>" );
        buff.append( "<tr>" );
        buff.append( "<th bgcolor='#c0c0c0'>ID</td>" );
        buff.append( "<th bgcolor='#c0c0c0'>Description</th>" );
        buff.append( "<th bgcolor='#c0c0c0'>Unit Price</th>" );
        buff.append( "<th bgcolor='#c0c0c0'>Quantity</th>" );
        buff.append( "<th bgcolor='#c0c0c0'> </th>" );
        buff.append( "</tr>" );

        for ( Iterator it = orderItems.iterator(  ); it.hasNext(  ); )
        {
            OrderItem orderItem = ( OrderItem ) it.next(  );
            buff.append( toHtml( orderItem ) );
        }

        buff.append( "<tr>" );
        buff.append( "<td colspan=4 align=right bgcolor='#c0c0c0'>TOTAL:</td>" );
        buff.append( "<td bgcolor='#c0c0c0'><b>" + order.calculateTotal(  ) + "<b></td>" );
        buff.append( "</tr>" );
        buff.append( "</table>" );

        return buff.toString(  );
    
private java.lang.StringtoHtml(xpetstore.domain.order.ejb.OrderItem orderItem)

        StringBuffer   buff = new StringBuffer(  );

        buff.append( "<tr>" );
        buff.append( "<td>" + orderItem.getItem(  ).getItemId(  ) + "</td>>" );
        buff.append( "<td>" + orderItem.getItem(  ).getDescription(  ) + "<br>" );
        buff.append( "<td>" + orderItem + "</td>" );
        buff.append( "<td>" + orderItem + "</td>" );
        buff.append( "<td>" + orderItem.calculateSubTotal(  ) + "</td>" );
        buff.append( "</tr>" );

        return buff.toString(  );