/** * Return the PropertyUtils bean instance. * @return The PropertyUtils bean instance */ protected static PropertyUtilsBean getInstance() { return BeanUtilsBean.getInstance().getPropertyUtils(); }
/** * Return the PropertyUtils bean instance. * @return The PropertyUtils bean instance */ protected static PropertyUtilsBean getInstance() { return BeanUtilsBean.getInstance().getPropertyUtils(); }
protected void setObjectPropertyNull(Object obj, Set<String> fields) { if (null == obj) { return; } for (String field : fields) { try { BeanUtilsBean.getInstance().getPropertyUtils().setProperty(obj, field, null); } catch (Exception ignore) { } } } }
public static <P> P setProperties(P bean, Properties properties) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { synchronized (beanUtils) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { String value = properties.getProperty(descriptor.getName()); if (value != null) { beanUtils.setProperty(bean, descriptor.getName(), value); } } } } return bean; }
public BeanTypeListener() { // SHIRO-619 beanUtilsBean = new BeanUtilsBean(); beanUtilsBean.getPropertyUtils().addBeanIntrospector( SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS); }
private void setIndexedProperty(Object object, String propertyPath, int index, Object value) { try { beanUtilsBean.getPropertyUtils().setIndexedProperty(object, propertyPath, index, value); } catch (Exception e) { throw new ConfigurationException("Unable to set array property '" + propertyPath + "'", e); } }
public static <P> Properties getProperties(P bean, Properties properties) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { synchronized (beanUtils) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { String value = beanUtils.getProperty(bean, descriptor.getName()); if (value != null) { properties.put(descriptor.getName(), value); } } } } return properties; }
private Object getProperty(Object object, String propertyPath) { try { return beanUtilsBean.getPropertyUtils().getProperty(object, propertyPath); } catch (Exception e) { throw new ConfigurationException("Unable to access property '" + propertyPath + "'", e); } }
private Object getIndexedProperty(Object object, String propertyPath, int index) { try { return beanUtilsBean.getPropertyUtils().getIndexedProperty(object, propertyPath, index); } catch (Exception e) { throw new ConfigurationException("Unable to acquire array property '" + propertyPath + "'", e); } }
protected void applyGlobalProperty(Map objects, String property, String value) { for (Object instance : objects.values()) { try { PropertyDescriptor pd = beanUtilsBean.getPropertyUtils().getPropertyDescriptor(instance, property); if (pd != null) { applyProperty(instance, property, value); } } catch (Exception e) { String msg = "Error retrieving property descriptor for instance " + "of type [" + instance.getClass().getName() + "] " + "while setting property [" + property + "]"; throw new ConfigurationException(msg, e); } } }
protected boolean isTypedProperty(Object object, String propertyName, Class clazz) { if (clazz == null) { throw new NullPointerException("type (class) argument cannot be null."); } try { PropertyDescriptor descriptor = beanUtilsBean.getPropertyUtils().getPropertyDescriptor(object, propertyName); if (descriptor == null) { String msg = "Property '" + propertyName + "' does not exist for object of " + "type " + object.getClass().getName() + "."; throw new ConfigurationException(msg); } Class propertyClazz = descriptor.getPropertyType(); return clazz.isAssignableFrom(propertyClazz); } catch (ConfigurationException ce) { //let it propagate: throw ce; } catch (Exception e) { String msg = "Unable to determine if property [" + propertyName + "] represents a " + clazz.getName(); throw new ConfigurationException(msg, e); } }
.getPropertyUtils() .setProperty(supportParam, field, null); } catch (Exception e) {
public static String getData(List<String> ignored, Object... beans) throws Exception { StringBuilder sb = new StringBuilder(); boolean empty = true; synchronized (beanUtils) { for (Object bean : beans) { if (bean != null) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, ignored)) { String value = beanUtils.getProperty(bean, descriptor.getName()); if (value != null) { if (!empty) { sb.append("&"); } empty = false; sb.append(descriptor.getName()).append("=").append(encodeURI(value)); } } } } } } return sb.toString(); }
/** * Return the value of the specified simple property of the specified * bean, converted to a String. * * @param bean Bean whose property is to be extracted * @param name Name of the property to be extracted * @return The property's value, converted to a String * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws InvocationTargetException if the property accessor method * throws an exception * @throws NoSuchMethodException if an accessor method for this * property cannot be found */ public String getSimpleProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object value = getPropertyUtils().getSimpleProperty(bean, name); return (getConvertUtils().convert(value)); }
public ReflectionBuilder(Map<String, ?> defaults) { // SHIRO-619 beanUtilsBean = new BeanUtilsBean(); beanUtilsBean.getPropertyUtils().addBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS); this.interpolator = createInterpolator(); this.objects = createDefaultObjectMap(); this.registeredEventSubscribers = new LinkedHashMap<String,Object>(); apply(defaults); }
/** * Return the value of the specified simple property of the specified * bean, converted to a String. * * @param bean Bean whose property is to be extracted * @param name Name of the property to be extracted * @return The property's value, converted to a String * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws InvocationTargetException if the property accessor method * throws an exception * @throws NoSuchMethodException if an accessor method for this * property cannot be found */ public String getSimpleProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object value = getPropertyUtils().getSimpleProperty(bean, name); return (getConvertUtils().convert(value)); }
/** * Return the value of the specified mapped property of the specified * bean, as a String. The key is specified as a method parameter and * must *not* be included in the property name expression * * @param bean Bean whose property is to be extracted * @param name Simple property name of the property value to be extracted * @param key Lookup key of the property value to be extracted * @return The mapped property's value, converted to a String * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws InvocationTargetException if the property accessor method * throws an exception * @throws NoSuchMethodException if an accessor method for this * property cannot be found */ public String getMappedProperty(final Object bean, final String name, final String key) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object value = getPropertyUtils().getMappedProperty(bean, name, key); return (getConvertUtils().convert(value)); }
/** * Return the value of the (possibly nested) property of the specified * name, for the specified bean, as a String. * * @param bean Bean whose property is to be extracted * @param name Possibly nested name of the property to be extracted * @return The nested property's value, converted to a String * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws IllegalArgumentException if a nested reference to a * property returns null * @throws InvocationTargetException if the property accessor method * throws an exception * @throws NoSuchMethodException if an accessor method for this * property cannot be found */ public String getNestedProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object value = getPropertyUtils().getNestedProperty(bean, name); return (getConvertUtils().convert(value)); }
/** * Return the value of the specified indexed property of the specified * bean, as a String. The index is specified as a method parameter and * must *not* be included in the property name expression * * @param bean Bean whose property is to be extracted * @param name Simple property name of the property value to be extracted * @param index Index of the property value to be extracted * @return The indexed property's value, converted to a String * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws InvocationTargetException if the property accessor method * throws an exception * @throws NoSuchMethodException if an accessor method for this * property cannot be found */ public String getIndexedProperty(final Object bean, final String name, final int index) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object value = getPropertyUtils().getIndexedProperty(bean, name, index); return (getConvertUtils().convert(value)); }
/** * Return the value of the specified indexed property of the specified * bean, as a String. The String-valued key of the required value * must be included (in parentheses) as a suffix to * the property name, or <code>IllegalArgumentException</code> will be * thrown. * * @param bean Bean whose property is to be extracted * @param name <code>propertyname(index)</code> of the property value * to be extracted * @return The mapped property's value, converted to a String * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws InvocationTargetException if the property accessor method * throws an exception * @throws NoSuchMethodException if an accessor method for this * property cannot be found */ public String getMappedProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Object value = getPropertyUtils().getMappedProperty(bean, name); return (getConvertUtils().convert(value)); }