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.ponysdk.jasper.export.DynamicExportDataSource.java
@Override public Object getFieldValue(final JRField field) throws JRException { try {//from w w w . j a v a 2s. com return PropertyUtils.getProperty(currentItem, field.getName()).toString(); } catch (final Exception e) { throw new JRException("Cannot extract field value # " + field.getName(), e); } }
From source file:com.sqewd.open.dal.core.persistence.query.ConditionMatcher.java
/** * Match the filter value with the Entity attribute of the specified entity * record./*w w w . jav a 2 s. co m*/ * * @param entity * - Entity record to check. * @param column * - Attribute Column name * @param operator * - Condition Operator * @param value * - Value to match. * @return * @throws Exception */ public boolean match(final AbstractEntity entity, final String column, final EnumOperator operator, final Object value) throws Exception { if (column.indexOf('.') < 0) { StructAttributeReflect attr = ReflectionUtils.get().getAttribute(entity.getClass(), column); Object src = PropertyUtils.getProperty(entity, attr.Field.getName()); if (src != null) return ConditionMatchHelper.compare(src, value, operator, attr.Field.getType()); } else { String[] vars = column.split("\\."); Object src = null; Class<?> type = null; StringBuffer coffset = new StringBuffer(); StructEntityReflect enref = ReflectionUtils.get().getEntityMetadata(entity.getClass()); for (String var : vars) { if (src != null) { coffset.append('.'); } coffset.append(var); if (var.compareTo(enref.Entity) == 0) { coffset.append("."); continue; } if (src == null) { StructAttributeReflect attr = ReflectionUtils.get().getAttribute(entity.getClass(), var); src = PropertyUtils.getProperty(entity, attr.Field.getName()); type = attr.Field.getType(); } else { StructAttributeReflect attr = ReflectionUtils.get().getAttribute(src.getClass(), var); src = PropertyUtils.getProperty(src, attr.Field.getName()); type = attr.Field.getType(); } if (src.getClass().isArray()) { if (isArrayEntityType(src)) { String cpart = column.replaceFirst("^" + coffset.toString() + ".", ""); return matchArray(src, cpart, operator, value); } } else if (src instanceof Iterable) { if (isListEntityType(src)) { String cpart = column.replaceFirst("^" + coffset.toString() + ".", ""); return matchList(src, cpart, operator, value); } } } if (src != null) return ConditionMatchHelper.compare(src, value, operator, type); } return false; }
From source file:hermes.Domain.java
public static Domain getDomain(Destination destination) { if (destination instanceof Queue && destination instanceof Topic) { ///*from w ww . j a v a 2 s. c o m*/ // This is an interesting hack to deal with WebLogic as it implements both domains. If we see the object // is somewhere in the WLS JMS packages then see if we can get the "topic" property. We must do this dynamically // as it may be loaded in a different class loader (so instanceof will fail) AND we don't want this part of the // Hermes codebase to be coupled to any provider. if (destination.getClass().getName().startsWith("weblogic.jms")) { try { final Boolean isTopic = (Boolean) PropertyUtils.getProperty(destination, "topic"); return isTopic ? Domain.TOPIC : Domain.QUEUE; } catch (Throwable e) { log.error(e.getMessage(), e); return Domain.UNKNOWN; } } else { return Domain.UNKNOWN; } } else if (destination instanceof Queue) { return Domain.QUEUE; } else { return Domain.TOPIC; } }
From source file:com.thinkmore.framework.orm.hibernate.HibernateWebUtils.java
/** * ?ID?,???.//www . j av a2 s . co m * * ??????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 ReflectionUtil.convertReflectionExceptionToUnchecked(e); } }
From source file:hudson.util.ReflectionUtils.java
public static Object getPublicProperty(Object o, String p) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(o, p); if (pd == null) { // field? try {/* w w w .j ava 2s .com*/ Field f = o.getClass().getField(p); return f.get(o); } catch (NoSuchFieldException e) { throw new IllegalArgumentException("No such property " + p + " on " + o.getClass()); } } else { return PropertyUtils.getProperty(o, p); } }
From source file:com.genologics.ri.configuration.TypeDefinition.java
public TypeDefinition(Linkable<Type> link) { uri = link.getUri();/* w w w . j av a 2s . com*/ try { this.name = (String) PropertyUtils.getProperty(link, "name"); } catch (Exception e) { // Ignore. } }
From source file:com.fengduo.bee.commons.core.lang.CollectionUtils.java
/** * List<T> ---> List<Map<key,?>> *///from w w w.j av a2s .co m public static <T extends Object> List<Map<String, ?>> toMapList(Collection<T> values, String... propertys) { if (Argument.isEmptyArray(propertys) || values == null || values.isEmpty()) { return Collections.<Map<String, ?>>emptyList(); } List<Map<String, ?>> list = new ArrayList<Map<String, ?>>(); for (T value : values) { Map<String, Object> valueMap = new HashMap<String, Object>(propertys.length); for (String property : propertys) { try { Object propertyValue = PropertyUtils.getProperty(value, property); if (propertyValue == null) { valueMap.put(property, null); } Object wapper = valueMap.get(property); if (wapper == null) { valueMap.put(property, propertyValue); } } catch (Exception e) { logger.error(e.getMessage(), e); continue; } } list.add(valueMap); } return list; }
From source file:com.mycollab.module.project.ui.components.DateInfoComp.java
public void displayEntryDateTime(ValuedBean bean) { this.removeAllComponents(); this.withMargin(false); Label dateInfoHeader = ELabel.html(FontAwesome.CALENDAR.getHtml() + " " + UserUIContext.getMessage(ProjectCommonI18nEnum.SUB_INFO_DATES)); dateInfoHeader.setStyleName("info-hdr"); this.addComponent(dateInfoHeader); MVerticalLayout layout = new MVerticalLayout().withMargin(new MarginInfo(false, false, false, true)) .withFullWidth();/* w w w . jav a2 s .com*/ try { Date createdDate = (Date) PropertyUtils.getProperty(bean, "createdtime"); ELabel createdDateLbl = new ELabel(UserUIContext.getMessage(ProjectCommonI18nEnum.ITEM_CREATED_DATE, UserUIContext.formatPrettyTime(createdDate))) .withDescription(UserUIContext.formatDateTime(createdDate)); layout.addComponent(createdDateLbl); Date updatedDate = (Date) PropertyUtils.getProperty(bean, "lastupdatedtime"); ELabel updatedDateLbl = new ELabel(UserUIContext.getMessage(ProjectCommonI18nEnum.ITEM_UPDATED_DATE, UserUIContext.formatPrettyTime(updatedDate))) .withDescription(UserUIContext.formatDateTime(updatedDate)); layout.addComponent(updatedDateLbl); this.addComponent(layout); } catch (Exception e) { LOG.error("Get date is failed {}", BeanUtility.printBeanObj(bean)); } }
From source file:com.assignmentone.util.persondb.AbstractDbManager.java
@SuppressWarnings("unchecked") public synchronized List<T> find(final String field, final Object v) { List<T> list = new ArrayList<>(entityList); CollectionUtils.filter(list, new Predicate() { @Override/*from ww w.j a va2 s . co m*/ public boolean evaluate(Object object) { try { return ObjectUtils.equals(v, PropertyUtils.getProperty(object, field)); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e); } } }); return ListConvertUtil.transform(list, new RowConvertor<T, T>() { @Override public T convert(int rowIndex, T obj) { try { return (T) obj.clone(); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } } }); }
From source file:jp.ac.tokushima_u.is.ll.common.orm.hibernate.HibernateWebUtils.java
/** * ?ID?,???./*from ww w . j av a2s . co m*/ * * ??????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); } }