📄 mallnavigationbean.java
字号:
return (ItemDetailLocalHome) ServiceLocator.getLocator().getService("java:comp/env/ejb/ItemDetailLocal"); } /* * Method to get the home for ShopDetailLocal bean */ private ShopDetailLocalHome getShopDetailLocalHome() throws NamingException { return (ShopDetailLocalHome) ServiceLocator.getLocator().getService("java:comp/env/ejb/ShopDetailLocal"); } /* * Method to get the home for ItemAttributeLocal bean */ private ItemAttributeLocalHome getItemAttributeLocalHome() throws NamingException { return (ItemAttributeLocalHome) ServiceLocator.getLocator().getService("java:comp/env/ejb/ItemAttributeLocal"); } /* * Method to get the home for InventoryLocal bean */ private InventoryLocalHome getInventoryLocalHome() throws NamingException { return (InventoryLocalHome) ServiceLocator.getLocator().getService("java:comp/env/ejb/InventoryLocal"); } /* * Method to get the home for SubCategoryLocal bean */ private SubCategoryLocalHome getSubCategoryLocalHome() throws NamingException { return (SubCategoryLocalHome) ServiceLocator.getLocator().getService("java:comp/env/ejb/SubCategoryLocal"); } /* * Method to get the home for ShopLocal bean */ private ShopLocalHome getShopLocalHome() throws NamingException { return (ShopLocalHome) ServiceLocator.getLocator().getService("java:comp/env/ejb/ShopLocal"); } /* * Method to get the home for ItemLocal bean */ private ItemLocalHome getItemLocalHome() throws NamingException { return (ItemLocalHome) ServiceLocator.getLocator().getService("java:comp/env/ejb/ItemLocal"); } /* * Method to get the home for CategoryLocal bean */ private CategoryLocalHome getCategoryLocalHome() throws NamingException { return (CategoryLocalHome) ServiceLocator.getLocator().getService("java:comp/env/ejb/CategoryLocal"); } /* * Method to create a value object for an Item bean,and for a given langauge */ private Item createItemValueObject(ItemLocal itemBean, String langID) throws ItemException { try { Item item = new Item(); // set common details item.setID(itemBean.getId()); item.setShopID(itemBean.getShopID()); item.setLangID(langID); item.setSubCatID(itemBean.getSubCatID()); item.setImage(itemBean.getImage()); // find language specific item details ItemDetailLocal itemDetail = getItemDetailLocalHome().findByPrimaryKey(new ItemDetailPK( item.getID(), langID)); // set language specific details in value object item.setName(itemDetail.getName()); item.setDesc(itemDetail.getDescription()); item.setUnitPrice(itemDetail.getUnitPrice().doubleValue()); item.setQuantity(itemBean.getInventory().getQuantity().intValue()); // set language specific attributes as a table Iterator iter = getItemAttributeLocalHome().findByLanguage(item.getID(), langID) .iterator(); ItemAttributeLocal attrib = null; TreeMap attribTable = new TreeMap(); while(iter.hasNext()) { attrib = (ItemAttributeLocal) iter.next(); attribTable.put(attrib.getLabel(), attrib.getDescription()); } item.setAttributes(attribTable); return item; } catch(Exception ex) { ex.printStackTrace(); throw new ItemException(ex.getMessage(), "error.item.general"); } } /** * The service method returns an array of all categories,in the given * language * * @param <b>langID</b> The language in which details should be retrieved * * @return <b>Category[]</b> an array of Category value objects * * @throws CategoryException if there was a problem finding categories */ public Category[] getAllCategories(String langID) throws CategoryException { try { CategoryLocalHome categoryHome = getCategoryLocalHome(); Collection collection = categoryHome.findByLanguage(langID); Iterator iter = collection.iterator(); Category[] categories = new Category[ collection.size() ]; int i = 0; int j = 0; CategoryLocal categoryBean = null; Collection attribCollection = null; Iterator attribIter = null; while(iter.hasNext()) { categoryBean = (CategoryLocal) iter.next(); categories [ i ] = new Category(); attribCollection = categoryBean.getAttributes(); attribIter = attribCollection.iterator(); String[] attribs = new String[ attribCollection.size() ]; j = 0; while(attribIter.hasNext()) { attribs [ j++ ] = ((CategoryAttributeLocal) attribIter.next()).getLabel(); } categories [ i ].setAttributes(attribs); //categories[i].setCatID(categoryBean.getCatID()); categories [ i ].setLangId(categoryBean.getLanguageID()); categories [ i ].setId(categoryBean.getId()); categories [ i ].setName(categoryBean.getCatName()); i++; } return categories; } catch(Exception ex) { ex.printStackTrace(); throw new CategoryException( "Unable to fetch categories", "error.mallnavigation.category"); } } /** * The service method returns an array of shops in a given category, with the * details of the shops in the given language * * @param <b>shopID</b> The shop id * @param <b>langID</b> The language in which details should be retrieved * * @return <b>Shop[]</b> a Shop value object * * @throws ShopException if there was a problem finding shop */ public Shop getShop(String shopID, String langID) throws ShopException { if( (shopID == null) || "".equals(shopID.trim()) || (langID == null) || "".equals(langID.trim())) { throw new ShopException( "shopID/lang id is empty or null", "error.shop.null"); } try { ShopLocalHome shopHome = getShopLocalHome(); ShopLocal shopBean = shopHome.findByPrimaryKey(shopID); Shop shop = null; Collection detailCollection = null; ShopDetailLocal detailBean = null; List shopDetailList = null; 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(); // find shop details for the language detailBean = getShopDetailLocalHome().findByPrimaryKey(new ShopDetailPK( shopBean.getId(), langID)); shop.addShopDetail(new ShopDetail( detailBean.getLangID(), detailBean.getShopName(), detailBean.getDescription())); return shop; } catch(Exception ex) { ex.printStackTrace(); throw new ShopException( "Unable to retrieve shop because " + ex.getMessage(), "error.shop.getshop"); } } /** * The service method returns a category for a given id,in the given language * * @param <b>langID</b> The language in which details should be retrieved * * @return <b>Category</b> a Category value object * * @throws CategoryException if there was a problem finding category */ public Category getCategory(String catID, String langID) throws CategoryException { try { CategoryLocalHome categoryHome = getCategoryLocalHome(); CategoryLocal categoryBean = categoryHome.findByCategoryAndLanguage(catID, langID); Category category = new Category(); Collection attribCollection = null; Iterator attribIter = null; attribCollection = categoryBean.getAttributes(); attribIter = attribCollection.iterator(); String[] attribs = new String[ attribCollection.size() ]; int i = 0; while(attribIter.hasNext()) { attribs [ i++ ] = ((CategoryAttributeLocal) attribIter.next()).getLabel(); } category.setAttributes(attribs); //category.setCatID(categoryBean.getCatID()); category.setLangId(categoryBean.getLanguageID()); category.setId(categoryBean.getId()); category.setName(categoryBean.getCatName()); return category; } catch(Exception ex) { ex.printStackTrace(); throw new CategoryException( "Unable to fetch categories", "error.mallnavigation.category"); } } /** * The service method returns an array of Country objects * * @return <b>Country[]</b> An array of Country objects * * @throws ServiceException if there was a problem finding category */ public Country[] getCountries() throws ServiceException { //Optimize this by caching valueobjects somewhere try { Country[] countries = CountryCache.getCountries(); if(countries == null || countries.length==0) { CountryLocalHome countryHome = getCountryLocalHome(); Collection countryColl = countryHome.findAll(); countries = new Country[ countryColl.size() ]; Iterator countryIter = countryColl.iterator(); CountryLocal countryBean = null; int i = 0; while(countryIter.hasNext()) { countryBean = (CountryLocal) countryIter.next(); countries [ i ] = new Country(countryBean.getId(), countryBean.getCountryName()); i++; } CountryCache.setCountries(countries); } return countries; } catch(Exception ex) { ex.printStackTrace(); throw new ServiceException(ex.getMessage(), "error.countryerror"); } } /* * Method to get the home for CountryLocal bean */ private CountryLocalHome getCountryLocalHome() throws NamingException { return (CountryLocalHome) ServiceLocator.getLocator().getService("java:comp/env/ejb/CountryLocal"); } /** * The service method adds an entry in to the Guestbook entity * * @param <b>guestbook</b> A Guestbook value object * * @throws GuestbookException if there was a problem adding a guestbook entry */ public void addGuestbookEntry(Guestbook guestbook) throws GuestbookException { try { GuestbookLocalHome guestbookHome = getGuestbookLocalHome(); guestbookHome.create( KeyFactory.getKey(), guestbook.getUserName(), guestbook.getEmail(), guestbook.getComments(), guestbook.getCommentDate(), guestbook.getLangId(), guestbook.getRating()); } catch(Exception ex) { ex.printStackTrace(); throw new GuestbookException(ex.getMessage(), "error.guestbookerror"); } } /* * Method to get the home for GuestbookLocal bean */ private GuestbookLocalHome getGuestbookLocalHome() throws NamingException { return (GuestbookLocalHome) ServiceLocator.getLocator().getService("java:comp/env/ejb/GuestbookLocal"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -