您的位置:首页 >> 编程开发 >> Java >> Java基础 >> Eclipse >> 正文
Eclipse RSS
 

TutorialforbuildingJ2EEApplicationsusingJBOSSandECLIPSE-7

http://www.rdxx.com 06年12月09日 04:26 互联网 我要投稿

关键词: Tutorial , san , J2EE , Eclipse , JB , ATI , UI , ONS , IP




Once a message is received from the JMS producer as a Message object, its data is extracted and filled into the immutable value object and then transferred to the relevant bean. This is covered later on in this chapter.

Now, before we add any functionality, create a class or immutable value object for extracting information from the message.

Create Immutable Value Object RequestItem :

Go to src > under package au.com.tusc.mdb > New >Class.




The java class wizard will pop up > Add class name as RequestItem, Superclass as java.lang.Object and Interfaces as Serializable as as shown below in figure.




This will generate a RequestItem class under au.com.tusc.mdb as shown below.

Add the following attributes to the RequestItem class as shown below.

private String username;private String passwd;private String itemID;private int quantity;

Add accessor and mutator method for these attributes.

Select all attributes > Right click> Select source > Generate Getter and Setter as shown below.




Add a constructor for the class which has parameters with the same type as the attributes and assigns them to the attributes as shown below.




The RequestItem constructor is complete. Now to implement the onMessage method in the RequestItem Bean.



Implement onMessage Method :

This method is responsible for extracting the information from the message and transferring it to the relevant bean.

The MyStore Manager will check for items which are out of stock and generate a request to suppliers specifying the itemID and quantity required.

First import the packages java.util.ArrayList and java.util.Iterator .

Add the following variables to store references.

ArrayList outOfStockItems = null;       Iterator itemsIterator = null;private StoreAccessHome storeAccess = null;private SupplierLocalHome suppLocalHome = null;private ItemLocalHome itemLocalHome = null;

Extract the data from the message into the immutable value object as shown below.

RequestItem ri =  (RequestItem) ((ObjectMessage) message).getObject();

Add the lines of code shown below, so that the manager can login.

StoreAccess access = StoreAccessUtil.getHome().create();                                String mgrAccessID = access.loginUser(ri.getUsername(),ri.getPasswd());                                           

Get items with zero quantity (no stock), by invoking getOutOfStockItems() on the StoreAccess Bean (which returns a Collection).

outOfStockItems = access.getOutOfStockItems();                                                                                

Now, iterating over each item, get the supplierId associated with it by invoking the finder methods on the Supplier Bean, finally sending the required message to that supplier by invoking the business method requestItem() on the Supplier Bean.

itemsIterator = outOfStockItems.iterator();while ( itemsIterator.hasNext() ) {                         ItemData itemData= ( ItemData ) itemsIterator.next();    String suppID = itemData.getSupplierID();

上一页 下一页


 
 
标签: Tutorial , san , J2EE , Eclipse , JB , ATI , UI , ONS , IP 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved