List of usage examples for org.apache.commons.beanutils PropertyUtilsBean isWriteable
public boolean isWriteable(Object bean, String name)
Return true if the specified property name identifies a writeable 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 . j a v a 2s.com 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 ww. j av a2 s. co 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.opencms.workplace.CmsWidgetDialogParameter.java
/** * Create a new Widget parameter based on a given object's property.<p> * /*from w ww. j a va2s .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; } } } } }