List of usage examples for org.apache.commons.beanutils BeanUtils BeanUtils
BeanUtils
From source file:com.salesmanager.core.service.catalog.impl.CategoryCacheImpl.java
public synchronized void loadCategoriesInCache() throws Exception { if (loaded) { return;//ww w .j ava2 s . co m } CatalogService cservice = (CatalogService) ServiceFactory.getService(ServiceFactory.CatalogService); Iterator langs = RefCache.getLanguageswithindex().entrySet().iterator(); Map categoriesMap = null; Map masterCategoriesMap = null; Map subCategoriesMap = null; Map genericCategoriesMap = null; while (langs.hasNext()) { categoriesMap = new LinkedHashMap(); masterCategoriesMap = new LinkedHashMap(); subCategoriesMap = new LinkedHashMap(); genericCategoriesMap = new LinkedHashMap(); Entry e = (Entry) langs.next(); Language l = (Language) e.getValue(); // Get all description List catdesc = cservice.getAllCategoriesByLang(l.getLanguageId()); Iterator allcategsit = catdesc.iterator(); while (allcategsit.hasNext()) { CategoryDescription desc = (CategoryDescription) allcategsit.next(); Category cat = cservice.getCategory(desc.getId().getCategoryId()); if (cat != null) { cat.setName(desc.getCategoryName()); Category categ = new Category(); try { BeanUtils bu = new BeanUtils(); bu.copyProperties(categ, cat); } catch (Exception ie) { log.error(ie); } if (!categoriesMap.containsKey(categ.getCategoryId())) { categoriesMap.put(categ.getCategoryId(), categ); } if (categ.getParentId() == 0) {// this is a master category masterCategoriesMap.put(categ.getCategoryId(), categ); } if (categ.getMerchantId() == Constants.GLOBAL_MERCHANT_ID) { if (!genericCategoriesMap.containsKey(categ.getCategoryId())) { genericCategoriesMap.put(categ.getCategoryId(), categ); } } // populate sub categories long supint = categ.getParentId(); if (supint == 0) { continue; } if (!subCategoriesMap.containsKey(supint)) { Map submap = Collections.synchronizedMap(new LinkedHashMap()); submap.put(categ.getCategoryId(), categ); subCategoriesMap.put(supint, submap); } else { Map submap = (Map) subCategoriesMap.get(supint); submap.put(categ.getCategoryId(), categ); } } } Map masters = ((Map) ((LinkedHashMap) masterCategoriesMap).clone()); Map categs = ((Map) ((LinkedHashMap) categoriesMap).clone()); Map subs = ((Map) ((LinkedHashMap) subCategoriesMap).clone()); Map gen = ((Map) ((LinkedHashMap) genericCategoriesMap).clone()); masterCategoriesMapByLang.put(l.getLanguageId(), Collections.synchronizedMap(masters)); categoriesMapByLang.put(l.getLanguageId(), Collections.synchronizedMap(categs)); subCategoriesMapByLang.put(l.getLanguageId(), Collections.synchronizedMap(subs)); genericCategoriesMapByLang.put(l.getLanguageId(), Collections.synchronizedMap(gen)); } CacheModule module = (CacheModule) SpringUtil.getBean("cache"); // simulate a store MerchantStore store = new MerchantStore(); store.setUseCache(true); module.putInCache("masterCategoriesMapByLang", masterCategoriesMapByLang, Constants.CACHE_CATEGORIES, store); module.putInCache("categoriesMapByLang", categoriesMapByLang, Constants.CACHE_CATEGORIES, store); module.putInCache("subCategoriesMapByLang", subCategoriesMapByLang, Constants.CACHE_CATEGORIES, store); module.putInCache("genericCategoriesMapByLang", subCategoriesMapByLang, Constants.CACHE_CATEGORIES, store); loaded = true; }
From source file:oscar.util.BeanUtilHlp.java
/** * A convenience method used to retrieve the field value of a specified JavaBean * @param bill Object/* w ww . java2 s .co m*/ * @param fieldName String * @return String */ public String getPropertyValue(Object bean, String fieldName) { BeanUtils ut = new BeanUtils(); String value = ""; try { value = BeanUtils.getProperty(bean, fieldName); } catch (NoSuchMethodException ex) { MiscUtils.getLogger().error("Error", ex); } catch (InvocationTargetException ex) { MiscUtils.getLogger().error("Error", ex); } catch (IllegalAccessException ex) { MiscUtils.getLogger().error("Error", ex); } return value; }