📄 mallnavigationbean.java
字号:
/* * @author : Neelesh * @Version : 1.0 * * Development Environment : Oracle 9i JDeveloper * Name of the File : MallNavigationBean.java * Creation/Modification History : * * Neelesh 30-Dec-2002 Created * */package oracle.otnsamples.vsm.services;// Data structuresimport java.util.ArrayList;import java.util.Collection;import java.util.Iterator;import java.util.List;import java.util.TreeMap;import javax.ejb.FinderException;import javax.ejb.SessionBean;import javax.ejb.SessionContext;import javax.naming.NamingException;import oracle.otnsamples.util.KeyFactory;import oracle.otnsamples.util.ServiceLocator;import oracle.otnsamples.vsm.Constants;import oracle.otnsamples.vsm.entities.CategoryAttributeLocal;import oracle.otnsamples.vsm.entities.CategoryLocal;import oracle.otnsamples.vsm.entities.CategoryLocalHome;import oracle.otnsamples.vsm.entities.CountryLocal;import oracle.otnsamples.vsm.entities.CountryLocalHome;import oracle.otnsamples.vsm.entities.GuestbookLocalHome;import oracle.otnsamples.vsm.entities.InventoryLocalHome;import oracle.otnsamples.vsm.entities.ItemAttributeLocal;import oracle.otnsamples.vsm.entities.ItemAttributeLocalHome;import oracle.otnsamples.vsm.entities.ItemDetailLocal;import oracle.otnsamples.vsm.entities.ItemDetailLocalHome;import oracle.otnsamples.vsm.entities.ItemDetailPK;import oracle.otnsamples.vsm.entities.ItemLocal;import oracle.otnsamples.vsm.entities.ItemLocalHome;import oracle.otnsamples.vsm.entities.ShopDetailLocal;import oracle.otnsamples.vsm.entities.ShopDetailLocalHome;import oracle.otnsamples.vsm.entities.ShopDetailPK;import oracle.otnsamples.vsm.entities.ShopLocal;import oracle.otnsamples.vsm.entities.ShopLocalHome;import oracle.otnsamples.vsm.entities.SubCategoryLocal;import oracle.otnsamples.vsm.entities.SubCategoryLocalHome;import oracle.otnsamples.vsm.services.data.Category;import oracle.otnsamples.vsm.services.data.Country;import oracle.otnsamples.vsm.services.data.Guestbook;import oracle.otnsamples.vsm.services.data.Item;import oracle.otnsamples.vsm.services.data.Shop;import oracle.otnsamples.vsm.services.data.ShopDetail;import oracle.otnsamples.vsm.services.data.SubCategory;/** * The service bean has implementations for remote methods related to mall * navigation functionality.The bean provides implementations for methods to * get shop details, item details and subcategories */public class MallNavigationBean implements SessionBean { /** * Default create method */ public void ejbCreate() { } /** * Container call back, called just after instance of this bean is activated */ public void ejbActivate() { } /** * Container call back, called just before instance of this bean is * passivated */ public void ejbPassivate() { } /** * Container call back, called by container before it ends the life of the * session object. */ public void ejbRemove() { } /** * Set the associated session context. The container calls this method after * the instance creation. * * @param ctx - A SessionContext interface for the instance. */ public void setSessionContext(SessionContext ctx) { } /** * The service method returns an array of shops in a given category, with the * details of the shops in the given language * * @param <b>catID</b> The category id * @param <b>langID</b> The language in which details should be retrieved * * @return <b>Shop[]</b> an array of Shop value objects * * @throws ShopException if there was a problem finding shops */ public Shop[] findShopsInCategory(String catID, String langID) throws ShopException { if( (catID == null) || "".equals(catID.trim()) || (langID == null) || "".equals(langID.trim())) { throw new ShopException( "Cat id/lang id is empty or null", "error.shop.null"); } try { ShopLocalHome shopHome = getShopLocalHome(); Collection shopCollection = shopHome.findByCategory(catID); Iterator shopIter = shopCollection.iterator(); ShopLocal shopBean = null; Shop shop = null; Collection shopList = new ArrayList(); Collection detailCollection = null; ShopDetailLocal detailBean = null; List shopDetailList = null; while(shopIter.hasNext()) { try{ shopBean = (ShopLocal) shopIter.next(); // if the shop is approved, add it to the list if(Constants.APPROVED.equals(shopBean.getStatus())){ // find shop details for the language detailBean = getShopDetailLocalHome().findByPrimaryKey(new ShopDetailPK( shopBean.getId(), langID)); shop = new Shop(); shop.setId(shopBean.getId()); shop.setCategoryId(shopBean.getCatID()); shop.setRegDate(shopBean.getRegDate()); shop.setStatus(shopBean.getStatus()); shop.setUserName(shopBean.getOwnerName()); detailCollection = shopBean.getShopDetails(); shopDetailList = new ArrayList(); shop.addShopDetail(new ShopDetail( detailBean.getLangID(), detailBean.getShopName(), detailBean.getDescription())); shopList.add(shop); } }catch(FinderException ex){ // no details for this shop in this language, continue processing with // next shop. } } return (Shop[]) shopList.toArray(new Shop[ shopList.size() ]); } catch(FinderException ex) { ex.printStackTrace(); return new Shop[ 0 ]; } catch(Exception ex) { ex.printStackTrace(); throw new ShopException( "Unable to retrieve shops in category because " + ex.getMessage(), "error.shop.searchincat"); } } /** * The service method returns an array of items in a given category, with the * details of the items in the given language * * @param <b>catID</b> The category id * @param <b>langID</b> The language in which details should be retrieved * * @return <b>Item[]</b> an array of Item value objects * * @throws ItemException if there was a problem finding items */ public Item[] findItemsInSubCategory(String subCatID, String langID) throws ItemException { if( (subCatID == null) || "".equals(subCatID.trim()) || (langID == null) || "".equals(langID.trim())) { throw new ItemException( "sub Cat id/lang id is empty or null", "error.item.null"); } try { ItemLocalHome itemHome = getItemLocalHome(); Collection itemCollection = itemHome.findBySubCategory(subCatID, langID); Iterator iter = itemCollection.iterator(); List itemList = new ArrayList(); while(iter.hasNext()) { itemList.add(createItemValueObject((ItemLocal) iter.next(), langID)); } return (Item[]) itemList.toArray(new Item[ itemList.size() ]); } catch(Exception ex) { throw new ItemException( "Unable to retrieve items because " + ex.getMessage(), "error.item.iteminsubcat"); } } /** * The service method returns an array of subcategories in a given shop,with * the details of the subcategories in the given language * * @param <b>catID</b> The category id * @param <b>langID</b> The language in which details should be retrieved * * @return <b>SubCategory[]</b> an array of SubCategory value objects * * @throws CategoryException if there was a problem finding sub categories */ public SubCategory[] findSubCategoriesInShop(String shopID, String langID) throws CategoryException { if( (shopID == null) || "".equals(shopID.trim()) || (langID == null) || "".equals(langID.trim())) { throw new CategoryException( "Shop id/lang id is empty or null", "error.subcategory.null"); } try { SubCategoryLocalHome subHome = getSubCategoryLocalHome(); Collection subcatCollection = subHome.findByShopAndLanguage(shopID, langID); Iterator subcatIter = subcatCollection.iterator(); SubCategoryLocal subcatBean = null; SubCategory subcat = null; Collection subcatList = new ArrayList(); while(subcatIter.hasNext()) { subcatBean = (SubCategoryLocal) subcatIter.next(); subcatList.add(new SubCategory( subcatBean.getSubCatID(), subcatBean.getShopID(), subcatBean.getSubCatName(), subcatBean.getCatID(), subcatBean.getLangID())); } return (SubCategory[]) subcatList.toArray(new SubCategory[ subcatList.size() ]); } catch(Exception ex) { ex.printStackTrace(); throw new CategoryException( "Unable to retrieve sub categories for " + " shop, because " + ex.getMessage(), "error.subcategory.subcatsinshop"); } } /** * The service method returns an array of top items in a given shop, with the * details of the items in the given language * * @param <b>catID</b> The category id * @param <b>langID</b> The language in which details should be retrieved * * @return <b>Item[]</b> an array of Item value objects * * @throws ItemException if there was a problem finding items */ public Item[] getTopItemsInShop(String shopID, String langID) throws ItemException { if( (shopID == null) || "".equals(shopID.trim()) || (langID == null) || "".equals(langID.trim())) { throw new ItemException( "Shop id/lang id is empty or null", "error.item.null"); } try { ItemLocalHome itemHome = getItemLocalHome(); Collection itemCollection = itemHome.findTopItemsInShop(shopID, langID, 4); Iterator iter = itemCollection.iterator(); List itemList = new ArrayList(); while(iter.hasNext()) { itemList.add(createItemValueObject((ItemLocal) iter.next(), langID)); } return (Item[]) itemList.toArray(new Item[ itemList.size() ]); } catch(Exception ex) { throw new ItemException( "Unable to retrieve items because " + ex.getMessage(), "error.item.topitems"); } } /** * The service method returns an array of items matching the keyword with the * details of the items in the given language * * @param <b>keword</b> The keyword * @param <b>String</b> The language in which details should be retrieved * * @return <b>Item[]</b> an array of Item value objects * * @throws ItemException if there was a problem finding items */ public Item[] searchItem(String keyword, String langID) throws ItemException { if((langID == null) || "".equals(langID.trim())) { throw new ItemException("Lang id is empty or null", "error.item.null"); } if((keyword == null) || "".equals(keyword.trim())) { return new Item[ 0 ]; } try { ItemLocalHome itemHome = getItemLocalHome(); Collection itemCollection = itemHome.findByKeyword("%" + keyword + "%", langID); Iterator iter = itemCollection.iterator(); List itemList = new ArrayList(); while(iter.hasNext()) { itemList.add(createItemValueObject((ItemLocal) iter.next(), langID)); } return (Item[]) itemList.toArray(new Item[ itemList.size() ]); } catch(Exception ex) { throw new ItemException( "Unable to retrieve items because " + ex.getMessage(), "error.item.search"); } } /* * Method to get the home for ItemDetailLocal bean */ private ItemDetailLocalHome getItemDetailLocalHome() throws NamingException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -