⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 requestitemsbean.java

📁 使用J2EE编写的网上商店系统
💻 JAVA
字号:
/*
 * Created on 1999-5-18
 */
package mdb;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Iterator;

import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.MessageDrivenBean;
import javax.jms.JMSException;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.naming.NamingException;

import cmp.*;

import stateless.*;
/**
 * @ejb.bean name="RequestItems" 
 *     acknowledge-mode="Auto-acknowledge" 
 *     destination-type="javax.jms.Queue" 
 *     transaction-type="Bean" 
 * 
 *--
 * This is needed for JOnAS.
 * If you are not using JOnAS you can safely remove the tags below.
 * @jonas.bean ejb-name="RequestItems"
 *	jndi-name="RequestItemsBean"
 * @jonas.message-driven-destination jndi-name="YOUR_DESTINATION"
 * 
 *--
 * 
 *--
 * This is needed for JBOSS.
 * If you are not using JBOSS you can safely remove the tags below.
 * @jboss.destination-jndi-name name="MDB_DESTINATION"
 * 
 * @ejb.ejb-ref
 * ejb-name="StoreAccess"
 * view-type="remote"
 * ref-name="StoreAccess"
 * 
 * @jboss.ejb-ref-jndi ref-name="StoreAccess"
 * jndi-name="StoreAccessBean"
 * 
 * @ejb.ejb-ref
 * ejb-name="Supplier"
 * view-type="local"
 * ref-name="SupplierLocal
 * 
 * @jboss.ejb-ref-jndi ref-name="SupplierLocal"
 * jndi-name="SupplierLocal"
 * 
 * @jboss.destination-jndi-name
 * name="queue/MdbQueue"
 *--
 **/
public class RequestItemsBean implements MessageDrivenBean, MessageListener {
	private StoreAccessHome storeAccess = null;
	private SupplierLocalHome suppLocalHome = null;
	private ItemLocalHome itemLocalHome = null;

	
	/** Required method for container to set context. */
	public void setMessageDrivenContext(
			javax.ejb.MessageDrivenContext messageContext)
			throws javax.ejb.EJBException {
		this.messageContext = messageContext;
	}
	/** 
	 * Required creation method for message-driven beans. 
	 * 
	 * @ejb.create-method 
	 */
	public void ejbCreate() {
		// no specific action required for message-driven beans 
	}
	/** Required removal method for message-driven beans. */
	public void ejbRemove() {
		messageContext = null;
	}
	/** 
	 * This method implements the business logic for the EJB. 
	 * 
	 * <p>Make sure that the business logic accounts for asynchronous message processing. 
	 * For example, it cannot be assumed that the EJB receives messages in the order they were 
	 * sent by the client. Instance pooling within the container means that messages are not 
	 * received or processed in a sequential order, although individual onMessage() calls to 
	 * a given message-driven bean instance are serialized. 
	 * 
	 * <p>The <code>onMessage()</code> method is required, and must take a single parameter 
	 * of type javax.jms.Message. The throws clause (if used) must not include an application 
	 * exception. Must not be declared as final or static. 
	 */
	public void onMessage(javax.jms.Message message) {
		System.out.println("Message Driven Bean got message " + message);
		System.out.println("Entering RequestitemsBean.onMessage()");
		ArrayList outOfStockItems = null;       
		Iterator itemsIterator = null;
		
		if(message instanceof ObjectMessage) {
			try {
				RequestItem ri=(RequestItem)((ObjectMessage)message).getObject();
				StoreAccess access=StoreAccessUtil.getHome().create();
				String mgrUsrID=access.loginUser(ri.getUsername(), ri.getPasswd());
				outOfStockItems=access.getOutOfStockItems();
				itemsIterator=outOfStockItems.iterator();
				
				this.suppLocalHome=SupplierUtil.getLocalHome();
				System.out.println("List of out of stock items ");
				while(itemsIterator.hasNext()) {
					ItemData itemData=(ItemData)itemsIterator.next();
					String suppID=itemData.getSupplierID();
					SupplierLocal supplier=this.suppLocalHome.findByPrimaryKey(suppID);
					Integer quantity=new Integer(ri.getQuantity());
					String itemID=ri.getItemID();
					supplier.requestItem(itemID, quantity);
				}
				
			} catch (JMSException e) {
				e.printStackTrace();
			} catch (RemoteException e) {
				e.printStackTrace();
			} catch (CreateException e) {
				e.printStackTrace();
			} catch (NamingException e) {
				e.printStackTrace();
			} catch (FinderException e) {
				e.printStackTrace();
			}
			
		}
		
		// do business logic here 
	}
	/** The context for the message-driven bean, set by the EJB container. */
	private javax.ejb.MessageDrivenContext messageContext = null;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -