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.age.back.frame.auth.CollectionUtils.java
/** * ????(Getter), ??List./* ww w.ja v a 2 s .com*/ * * @param collection ???. * @param propertyName ??????. * @param ignoreEmptyValue ?null"" * * @return List */ public static <T> List<T> extractToList(Collection collection, String propertyName, boolean ignoreEmptyValue) { if (collection == null) { return null; } List list = new ArrayList(); try { for (Object obj : collection) { T value = (T) PropertyUtils.getProperty(obj, propertyName); if (ignoreEmptyValue && value == null || value.toString().equals("")) { continue; } list.add(PropertyUtils.getProperty(obj, propertyName)); } } catch (Exception e) { e.printStackTrace(); } return list; }
From source file:com.khubla.cbean.serializer.impl.json.JSONUUIDFieldSerializer.java
@Override public String serialize(Object o, Field field) throws SerializerException { try {//from w w w .j a v a2 s . c o m final UUID uuid = (UUID) PropertyUtils.getProperty(o, field.getName()); return uuid.toString(); } catch (final Exception e) { throw new SerializerException(e); } }
From source file:com.doctusoft.common.core.bean.internal.AttributeImpl.java
@Override public T getValue(final E instance) { if (instance == null) { return null; }/*from w ww . ja v a2 s .c om*/ try { return (T) PropertyUtils.getProperty(instance, name); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } }
From source file:de.dentrassi.osgi.web.form.tags.FormValueTagSupport.java
protected Object getPathValue(final String path) { final Object command = getCommandValue(); if (command == null) { return null; }/*from w w w . j av a 2 s. c om*/ try { return PropertyUtils.getProperty(command, path); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { return null; } }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.commons.AbstractSearchObjects.java
protected Collection<T> process(Collection<T> objects, String value, int limit, Map<String, String> arguments) { List<T> result;/* w ww.j a va2s .c o m*/ String slotName = arguments.get("slot"); if (value == null) { result = (List<T>) objects; } else { result = new ArrayList<T>(); String[] values = StringNormalizer.normalize(value).split("\\p{Space}+"); outter: for (T object : objects) { try { String objectValue = (String) PropertyUtils.getProperty(object, slotName); if (objectValue == null) { continue; } String normalizedValue = StringNormalizer.normalize(objectValue); for (int i = 0; i < values.length; i++) { String part = values[i]; if (!normalizedValue.contains(part)) { continue outter; } } result.add(object); if (result.size() >= limit) { break; } } catch (IllegalAccessException e) { throw new DomainException("searchObject.type.notFound", e); } catch (InvocationTargetException e) { throw new DomainException("searchObject.failed.read", e); } catch (NoSuchMethodException e) { throw new DomainException("searchObject.failed.read", e); } } } Collections.sort(result, new BeanComparator(slotName)); return result; }
From source file:com.esofthead.mycollab.schedule.email.format.I18nFieldFormat.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override/*from ww w. ja v a2 s . com*/ public String formatField(MailContext<?> context) { Object wrappedBean = context.getWrappedBean(); Object value = null; try { value = PropertyUtils.getProperty(wrappedBean, fieldName); if (value == null) { return new Span().write(); } else { Enum valueEnum = Enum.valueOf(enumKey, value.toString()); return new Span().appendText(LocalizationHelper.getMessage(context.getLocale(), valueEnum)).write(); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { log.error("Can not generate of object " + BeanUtility.printBeanObj(wrappedBean) + " field: " + fieldName + " and " + value, e); return new Span().write(); } }
From source file:com.create.validation.MultiDateConstraintValidator.java
@Override public boolean isValid(Object value, ConstraintValidatorContext context) { try {//from w ww . j a va 2s . co m final LocalDate baseDate = (LocalDate) PropertyUtils.getProperty(value, multiDateConstraint.baseDateProperty()); final LocalDate termDate = (LocalDate) PropertyUtils.getProperty(value, multiDateConstraint.termDateProperty()); return baseDate == null || termDate == null || constraintChecker.checkConstraint(baseDate, termDate); } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IllegalArgumentException(e); } }
From source file:jp.co.opentone.bsol.framework.core.util.PropertyGetUtil.java
@SuppressWarnings("unchecked") public static <T> T getProperty(Object bean, String name) { try {// w ww . ja va2 s .co m return (T) PropertyUtils.getProperty(bean, name); } catch (IllegalAccessException e) { throw new ReflectionRuntimeException(e); } catch (InvocationTargetException e) { throw new ReflectionRuntimeException(e); } catch (NoSuchMethodException e) { throw new ReflectionRuntimeException(e); } }
From source file:com.khubla.cbean.serializer.impl.json.JSONDateFieldSerializer.java
@Override public String serialize(Object o, Field field) throws SerializerException { try {/* w w w. j av a 2s . c o m*/ final Date date = (Date) PropertyUtils.getProperty(o, field.getName()); return Long.toString(date.getTime()); } catch (final Exception e) { throw new SerializerException(e); } }
From source file:it.geosolutions.geoserver.jms.impl.utils.BeanUtils.java
/** * This is a 'smart' (perform checks for some special cases) update function which should be used to copy of the properties for objects * of the catalog and configuration./* w w w . j a v a 2 s .c om*/ * * @param <T> the type of the bean to update * @param info the bean instance to update * @param properties the list of string of properties to update * @param values the list of new values to update * * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException */ public static <T> void smartUpdate(final T info, final List<String> properties, final List<Object> values) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Iterator<String> itPropertyName = properties.iterator(); final Iterator<Object> itValue = values.iterator(); while (itPropertyName.hasNext() && itValue.hasNext()) { String propertyName = itPropertyName.next(); final Object value = itValue.next(); PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(info, propertyName); // return null if there is no such descriptor if (pd == null) { // this is a special case used by the NamespaceInfoImpl setURI // the propertyName coming from the ModificationProxy is set to 'uRI' // lets set it to uri propertyName = propertyName.toUpperCase(); pd = PropertyUtils.getPropertyDescriptor(info, propertyName); if (pd == null) { return; } } if (pd.getWriteMethod() != null) { PropertyUtils.setProperty(info, propertyName, value); } else { // T interface do not declare setter method for this property // lets use getter methods to get the property reference final Object property = PropertyUtils.getProperty(info, propertyName); // check type of property to apply new value if (Collection.class.isAssignableFrom(pd.getPropertyType())) { final Collection<?> liveCollection = (Collection<?>) property; liveCollection.clear(); liveCollection.addAll((Collection) value); } else if (Map.class.isAssignableFrom(pd.getPropertyType())) { final Map<?, ?> liveMap = (Map<?, ?>) property; liveMap.clear(); liveMap.putAll((Map) value); } else { if (CatalogUtils.LOGGER.isLoggable(java.util.logging.Level.SEVERE)) CatalogUtils.LOGGER.severe("Skipping unwritable property " + propertyName + " with property type " + pd.getPropertyType()); } } } }