List of usage examples for org.apache.commons.beanutils PropertyUtilsBean isReadable
public boolean isReadable(Object bean, String name)
Return true if the specified property name identifies a readable property on the specified bean; otherwise, return false.
From source file:net.firejack.platform.core.store.registry.resource.ResourceVersionStore.java
private void copyResourceVersionProperties(RV dest, RV orig) { PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils(); PropertyDescriptor[] propertyDescriptors = propertyUtils.getPropertyDescriptors(orig); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String name = propertyDescriptor.getName(); if (ArrayUtils.contains(new String[] { "class", "id", "version", "status", "updated", "created" }, name)) {//from w ww . java 2s . co m continue; } if (propertyUtils.isReadable(orig, name) && propertyUtils.isWriteable(dest, name)) { try { Object value = propertyUtils.getSimpleProperty(orig, name); if (value instanceof Timestamp) { value = ConvertUtils.convert(value, Date.class); } BeanUtils.copyProperty(dest, name, value); } catch (Exception e) { // Should not happen } } } }
From source file:nl.nn.adapterframework.monitoring.SenderMonitorAdapter.java
public void addNonDefaultAttribute(XmlBuilder senderXml, ISender sender, String attribute) { try {/*from w w w. ja v a2 s . c o m*/ PropertyUtilsBean pub = new PropertyUtilsBean(); if (pub.isReadable(sender, attribute) && pub.isWriteable(sender, attribute)) { String value = BeanUtils.getProperty(sender, attribute); Object defaultSender; Class[] classParm = null; Object[] objectParm = null; Class cl = sender.getClass(); java.lang.reflect.Constructor co = cl.getConstructor(classParm); defaultSender = co.newInstance(objectParm); String defaultValue = BeanUtils.getProperty(defaultSender, attribute); if (value != null && !value.equals(defaultValue)) { senderXml.addAttribute(attribute, value); } } } catch (Exception e) { log.error("cannot retrieve attribute [" + attribute + "] from sender [" + ClassUtils.nameOf(sender) + "]"); } }
From source file:org.jdbcquery.Statement.java
/** * Sets all of the bean properties into the prepared statement using the bean property name as the parameter * name./*from w w w. j a v a 2s . c o m*/ * * @param aJavaBean * the java bean to use * @return the statement (for method chaining) */ public Statement setBean(Object aJavaBean) { final PropertyUtilsBean propertyUtils = new PropertyUtilsBean(); try { for (int i = 0; i < this.getParameters().size(); i++) { if (propertyUtils.isReadable(aJavaBean, this.getParameters().get(i))) { final Object value = propertyUtils.getNestedProperty(aJavaBean, this.getParameters().get(i)); this.getPreparedStatement().setObject(i + 1, value); } } } catch (final SQLException e) { this.getConnection().cleanUp(); throw new DaoException("Error", e); } catch (final IllegalAccessException e) { throw new DaoException("Error getting bean properties from " + aJavaBean, e); } catch (final InvocationTargetException e) { throw new DaoException("Error getting bean properties from " + aJavaBean, e); } catch (final NoSuchMethodException e) { throw new DaoException("Error getting bean properties from " + aJavaBean, e); } return this; }
From source file:org.opencms.workplace.CmsWidgetDialogParameter.java
/** * Create a new Widget parameter based on a given object's property.<p> * //from ww w . ja va2 s . co m * @param base the base object to map the parameter to / from * @param property the base object property to map the parameter to / from * @param htmlName the form id name to use in the generated HTML * @param defaultValue the default value to use for this parameter * @param dialogPage the dialog page to use the widget on * @param widget the widget used for this paramete * @param minOccurs the required minimum numer of occurences of this parameter * @param maxOccurs the maximum allowed numer of occurences of this parameter */ public CmsWidgetDialogParameter(Object base, String property, String htmlName, String defaultValue, String dialogPage, I_CmsWidget widget, int minOccurs, int maxOccurs) { if (htmlName == null) { htmlName = property; } if ((base instanceof List) || (base instanceof SortedMap)) { // this is a list, use custom list mappings init(null, defaultValue, htmlName, widget, dialogPage, 0, MAX_OCCURENCES, 0); m_baseObject = null; m_baseObjectProperty = null; m_baseCollection = base; } else { // generic object:use reflection to map object properties init(null, defaultValue, htmlName, widget, dialogPage, minOccurs, maxOccurs, 0); m_baseObject = base; m_baseObjectProperty = property; m_baseCollection = null; PropertyUtilsBean bean = new PropertyUtilsBean(); Object value = null; // make sure the base object has the requested property if (!bean.isReadable(m_baseObject, m_baseObjectProperty) || !bean.isWriteable(m_baseObject, m_baseObjectProperty)) { try { // check if this is a mapped property value = bean.getMappedProperty(m_baseObject, m_baseObjectProperty); } catch (Exception e) { throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_NO_PROPERTY_2, base.getClass().getName(), property)); } } try { if (value == null) { // may have been read already as a mapped property value = bean.getNestedProperty(m_baseObject, m_baseObjectProperty); } } catch (Exception e) { throw new CmsRuntimeException( Messages.get().container(Messages.ERR_PROPERTY_READ_2, property, base.getClass().getName()), e); } if (value != null) { if ((value instanceof List) || (value instanceof SortedMap)) { m_baseCollection = value; m_minOccurs = 0; m_maxOccurs = MAX_OCCURENCES; } else { m_defaultValue = String.valueOf(value); m_value = m_defaultValue; if ((m_minOccurs == 0) && !m_value.equals(defaultValue)) { // if value is different from default ensure this widget is displayed m_minOccurs = 1; } } } } }