List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty
public static Object getProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:com.mycollab.module.crm.ui.components.DateInfoComp.java
public void displayEntryDateTime(ValuedBean bean) { this.removeAllComponents(); this.withMargin(false); Label dateInfoHeader = new Label( FontAwesome.CALENDAR.getHtml() + " " + UserUIContext.getMessage(CrmCommonI18nEnum.SUB_INFO_DATES), ContentMode.HTML);// w ww . ja v a 2s.co m dateInfoHeader.setStyleName("info-hdr"); this.addComponent(dateInfoHeader); MVerticalLayout layout = new MVerticalLayout().withMargin(new MarginInfo(false, false, false, true)) .withFullWidth(); try { Date createdDate = (Date) PropertyUtils.getProperty(bean, "createdtime"); Label createdDateLbl = new Label(UserUIContext.getMessage(CrmCommonI18nEnum.ITEM_CREATED_DATE, UserUIContext.formatPrettyTime(createdDate))); createdDateLbl.setDescription(UserUIContext.formatDateTime(createdDate)); Date updatedDate = (Date) PropertyUtils.getProperty(bean, "lastupdatedtime"); Label updatedDateLbl = new Label(UserUIContext.getMessage(CrmCommonI18nEnum.ITEM_UPDATED_DATE, UserUIContext.formatPrettyTime(updatedDate))); updatedDateLbl.setDescription(UserUIContext.formatDateTime(updatedDate)); layout.with(createdDateLbl, updatedDateLbl); this.addComponent(layout); } catch (Exception e) { LOG.error("Get date is failed {}", BeanUtility.printBeanObj(bean)); } }
From source file:com.genologics.ri.configuration.FieldLink.java
public FieldLink(Linkable<Field> link) { uri = link.getUri();/*from w w w.j a v a 2 s . c o m*/ try { this.name = (String) PropertyUtils.getProperty(link, "name"); } catch (Exception e) { // Ignore. } }
From source file:com.genologics.ri.processtype.TypeDefinition.java
public TypeDefinition(Linkable<Field> link) { uri = link.getUri();/*from w ww .j ava2s. c o m*/ try { name = (String) PropertyUtils.getProperty(link, "name"); } catch (Exception e) { // Ignore. } }
From source file:com.tonbeller.wcf.expr.ExprUtils.java
public static Object getModelReference(ExprContext context, String expr) { try {/*from ww w. ja v a 2s. c om*/ if (expr == null || expr.length() == 0) return null; // plain string? if (!isExpression(expr)) return context.findBean(expr); if (!expr.endsWith("}")) throw new IllegalArgumentException("expr must end with '}'"); // dotted expression? int pos = expr.indexOf('.'); if (pos < 0) { // no, find attribute in context String name = expr.substring(2, expr.length() - 1); return context.findBean(name); } // yes, evaluate property path String name = expr.substring(2, pos); Object bean = context.findBean(name); if (bean == null) throw new IllegalArgumentException("bean \"" + name + "\" not found"); String path = expr.substring(pos + 1, expr.length() - 1); return PropertyUtils.getProperty(bean, path); } catch (IllegalAccessException e) { logger.error("?", e); throw new SoftException(e); } catch (InvocationTargetException e) { logger.error("?", e); throw new SoftException(e); } catch (NoSuchMethodException e) { logger.error("?", e); throw new SoftException(e); } }
From source file:com.esofthead.mycollab.common.interceptor.aspect.TraceableAspect.java
static ActivityStreamWithBLOBs constructActivity(Class<?> cls, Traceable traceableAnnotation, Object bean, String username, String action) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { ActivityStreamWithBLOBs activity = new ActivityStreamWithBLOBs(); activity.setModule(ClassInfoMap.getModule(cls)); activity.setType(ClassInfoMap.getType(cls)); activity.setTypeid(String.valueOf(PropertyUtils.getProperty(bean, traceableAnnotation.idField()))); activity.setCreatedtime(new GregorianCalendar().getTime()); activity.setAction(action);//w ww .j a v a 2s . co m activity.setSaccountid((Integer) PropertyUtils.getProperty(bean, "saccountid")); activity.setCreateduser(username); Object nameObj = PropertyUtils.getProperty(bean, traceableAnnotation.nameField()); String nameField; if (nameObj instanceof Date) { nameField = DateTimeUtils.formatDate((Date) nameObj, "MM/dd/yyyy"); } else { nameField = nameObj.toString(); } activity.setNamefield(nameField); if (!"".equals(traceableAnnotation.extraFieldName())) { Integer extraTypeId = (Integer) PropertyUtils.getProperty(bean, traceableAnnotation.extraFieldName()); activity.setExtratypeid(extraTypeId); } return activity; }
From source file:com.timesoft.kaitoo.ws.hibernate.AbstractPojo.java
/** * DOCUMENT ME!/*from www . ja v a 2 s. co m*/ * * @return DOCUMENT ME! */ public String toString() { PropertyDescriptor[] pd = PropertyUtils.getPropertyDescriptors(this); StringBuffer buffer = new StringBuffer(); if (((List) callStack.get()).contains(this)) { buffer.append("Cyclic Reference!!!"); } else { ((List) callStack.get()).add(this); for (int index = 0; index < pd.length; ++index) { if ((null != PropertyUtils.getReadMethod(pd[index])) && (pd[index].getPropertyType() != Class.class)) { if (buffer.length() > 0) { buffer.append(", "); } String prop_name = pd[index].getName(); buffer.append(prop_name).append("="); try { buffer.append(PropertyUtils.getProperty(this, prop_name)); } catch (Exception e) { buffer.append(e.getMessage()); } } } ((List) callStack.get()).remove(this); } buffer.insert(0, " { ").insert(0, getClass().getName()).append(" }"); return buffer.toString(); }
From source file:com.esofthead.mycollab.module.crm.ui.components.DateInfoComp.java
public void displayEntryDateTime(ValuedBean bean) { this.removeAllComponents(); this.withMargin(new MarginInfo(true, false, true, true)); Label dateInfoHeader = new Label( FontAwesome.CALENDAR.getHtml() + " " + AppContext.getMessage(CrmCommonI18nEnum.SUB_INFO_DATES), ContentMode.HTML);/*from w ww.ja va2 s .com*/ dateInfoHeader.setStyleName("info-hdr"); this.addComponent(dateInfoHeader); MVerticalLayout layout = new MVerticalLayout().withMargin(new MarginInfo(false, false, false, true)) .withWidth("100%"); try { Date createdDate = (Date) PropertyUtils.getProperty(bean, "createdtime"); Label createdDateLbl = new Label(AppContext.getMessage(CrmCommonI18nEnum.ITEM_CREATED_DATE, AppContext.formatPrettyTime(createdDate))); createdDateLbl.setDescription(AppContext.formatDateTime(createdDate)); Date updatedDate = (Date) PropertyUtils.getProperty(bean, "lastupdatedtime"); Label updatedDateLbl = new Label(AppContext.getMessage(CrmCommonI18nEnum.ITEM_UPDATED_DATE, AppContext.formatPrettyTime(updatedDate))); updatedDateLbl.setDescription(AppContext.formatDateTime(updatedDate)); layout.with(createdDateLbl, updatedDateLbl); this.addComponent(layout); } catch (Exception e) { LOG.error("Get date is failed {}", BeanUtility.printBeanObj(bean)); } }
From source file:com.afeng.common.dao.orm.HibernateWebUtils.java
/** * ?ID?,???.//from www .j a v a 2 s . c o m * <p/> * ??????id,??????id?????. * ???id??,??id??. * ?ID, ??cascade-save-or-update. * * @param srcObjects ??,. * @param checkedIds ?,ID. * @param clazz ? * @param idName ?? */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.hasText(idName, "idName?"); Assert.notNull(clazz, "clazz?"); //?,???. if (checkedIds == null) { srcObjects.clear(); return; } //????,id?ID?,. //?,???id,?id???id. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } }
From source file:io.neocdtv.eclipselink.entitygraph.CopyPartialEntities.java
void copyRecursive(final Object copyFrom, final Object copyTo, final EntityGraphImpl entityGraph) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException {// www .j av a 2 s.co m copyDefaultAttributes(copyFrom, copyTo); final List<AttributeNodeImpl> attributeNodes = entityGraph.getAttributeNodes(); for (int i = 0; i < attributeNodes.size(); i++) { final AttributeNodeImpl node = attributeNodes.get(i); if (node != null) { if (isSimpleNode(node)) { handleSimpleNode(node, copyFrom, copyTo); } else { final String attributeName = node.getAttributeName(); final Object property = PropertyUtils.getProperty(copyFrom, attributeName); final Object newProperty = property.getClass().newInstance(); final Map<Class, Subgraph> subgraphs = node.getSubgraphs(); if (isCollectionProperty(newProperty)) { handleCollectionNode(property, newProperty, subgraphs, copyTo, attributeName); } else { final EntityGraphImpl subgraph = (EntityGraphImpl) subgraphs.get(property.getClass()); copyRecursive(property, newProperty, subgraph); } } } } }
From source file:br.com.sicoob.cro.cop.batch.configuration.ItemProcessorInjector.java
/** * Cria o contexto de dados para o tasklet. * * @return um {@link TaskletContext}.// www .j a v a2 s . c o m */ private ChunkContext createContext() throws Exception { return ConstructorUtils.invokeConstructor(ChunkContext.class, (StepParameters) PropertyUtils.getProperty(this.step, BatchKeys.PARAMETERS.getKey())); }