PojoPropertyUtilsBean extends PropertyUtilsBean { @Override public boolean isWriteable(Object bean, String name) { if (bean == null) { throw new IllegalArgumentException("No bean specified"); } if (name == null) { throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'"); } Resolver nestedResolver = getResolver(); while (nestedResolver.hasNested(name)) { String next = nestedResolver.next(name); Object nestedBean = null; try { nestedBean = getProperty(bean, next); if (nestedBean == null) { Class propertyType = getPropertyType(bean, next); if (propertyType != null && !propertyType.isInterface()) { Object newInstance = ObjectUtils.createNewObjectFromClass(propertyType); setSimpleProperty(bean, next, newInstance); nestedBean = getSimpleProperty(bean, next); } else { return false; } } } catch (IllegalAccessException e) { return false; } catch (InvocationTargetException e) { return false; } catch (NoSuchMethodException e) { return false; } bean = nestedBean; name = nestedResolver.remove(name); } name = getResolver().getProperty(name); if (bean instanceof WrapDynaBean) { bean = ((WrapDynaBean)bean).getInstance(); } if (bean instanceof DynaBean) { return (((DynaBean) bean).getDynaClass().getDynaProperty(name) != null); } else { try { PropertyDescriptor desc = getPropertyDescriptor(bean, name); if (desc != null) { Method writeMethod = desc.getWriteMethod(); if (writeMethod == null) { if (desc instanceof IndexedPropertyDescriptor) { writeMethod = ((IndexedPropertyDescriptor) desc).getIndexedWriteMethod(); } else if (desc instanceof MappedPropertyDescriptor) { writeMethod = ((MappedPropertyDescriptor) desc).getMappedWriteMethod(); } writeMethod = MethodUtils.getAccessibleMethod(bean.getClass(), writeMethod); } return (writeMethod != null); } else { return (false); } } catch (IllegalAccessException e) { return (false); } catch (InvocationTargetException e) { return (false); } catch (NoSuchMethodException e) { return (false); } } } PojoPropertyUtilsBean(); Object getProperty(Object bean, String key); Object fastGetNestedProperty(Object obj, String propertyName); @Override boolean isWriteable(Object bean, String name); Object getNestedProperty(Object arg0, String arg1); Object getIndexedProperty(Object bean, String name, int index); void setNestedProperty(Object bean, String name, Object value); PropertyDescriptor getPropertyDescriptor(Object bean, String name); void setSimpleProperty(Object bean,
                                         String name, Object value); Class getPropertyType(Object bean, String name); static final Logger LOG; }
@Test public void testNestedPropertyIsWriteable() { ReadonlyBean testBean = new ReadonlyBean(); ReadonlyWrappingBean readonlyBean = new ReadonlyWrappingBean(testBean); WriteableWrappingBean writeableBean = new WriteableWrappingBean(testBean); assertFalse(PropertyUtils.isWriteable(readonlyBean, "bean.value")); assertFalse(PropertyUtils.isWriteable(writeableBean, "bean.value")); }