diff options
author | Henri Sara <henri.sara@itmill.com> | 2011-04-19 12:48:04 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2011-04-19 12:48:04 +0000 |
commit | 976d097a862c45946cbad9eeabe2079223315fd9 (patch) | |
tree | 5ab92702a4119d24a2fc1d45cd58e94bcd27f7db /src/com/vaadin/data/util | |
parent | b89cf7c9ff4d24d7d22660900fed87ceca2dd168 (diff) | |
download | vaadin-framework-976d097a862c45946cbad9eeabe2079223315fd9.tar.gz vaadin-framework-976d097a862c45946cbad9eeabe2079223315fd9.zip |
#4995 Nested bean property support: no extra property type parameter to addNestedContainerProperty(), NestedMethodProperty takes the bean class instead
svn changeset:18385/svn branch:6.6
Diffstat (limited to 'src/com/vaadin/data/util')
4 files changed, 35 insertions, 20 deletions
diff --git a/src/com/vaadin/data/util/AbstractBeanContainer.java b/src/com/vaadin/data/util/AbstractBeanContainer.java index 1daa4050c5..7ed8e731b9 100644 --- a/src/com/vaadin/data/util/AbstractBeanContainer.java +++ b/src/com/vaadin/data/util/AbstractBeanContainer.java @@ -766,10 +766,9 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends * @param propertyType * @return true if the property was added */ - public boolean addNestedContainerProperty(String propertyId, - Class<?> propertyType) { + public boolean addNestedContainerProperty(String propertyId) { return addContainerProperty(propertyId, new NestedPropertyDescriptor( - propertyId, propertyType)); + propertyId, type)); } @Override diff --git a/src/com/vaadin/data/util/MethodProperty.java b/src/com/vaadin/data/util/MethodProperty.java index 3ae84ac5e6..deb3177094 100644 --- a/src/com/vaadin/data/util/MethodProperty.java +++ b/src/com/vaadin/data/util/MethodProperty.java @@ -515,8 +515,8 @@ public class MethodProperty<T> extends AbstractProperty { * @throws NoSuchMethodException * if no getter found */ - protected static Method initGetterMethod(String propertyName, - final Class<?> beanClass) throws NoSuchMethodException { + static Method initGetterMethod(String propertyName, final Class<?> beanClass) + throws NoSuchMethodException { propertyName = propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); @@ -536,7 +536,7 @@ public class MethodProperty<T> extends AbstractProperty { return getMethod; } - protected static Class<?> convertPrimitiveType(Class<?> type) { + static Class<?> convertPrimitiveType(Class<?> type) { // Gets the return type from get method if (type.isPrimitive()) { if (type.equals(Boolean.TYPE)) { @@ -667,7 +667,7 @@ public class MethodProperty<T> extends AbstractProperty { * type into which the value should be converted * @return converted value */ - protected static Object convertValue(Object value, Class<?> type) { + static Object convertValue(Object value, Class<?> type) { if (null == value || type.isAssignableFrom(value.getClass())) { return value; } diff --git a/src/com/vaadin/data/util/NestedMethodProperty.java b/src/com/vaadin/data/util/NestedMethodProperty.java index 39bd6f7b3a..3d400d7d02 100644 --- a/src/com/vaadin/data/util/NestedMethodProperty.java +++ b/src/com/vaadin/data/util/NestedMethodProperty.java @@ -54,7 +54,7 @@ public class NestedMethodProperty extends AbstractProperty { ClassNotFoundException { in.defaultReadObject(); - initialize(instance, propertyName); + initialize(instance.getClass(), propertyName); } /** @@ -71,30 +71,44 @@ public class NestedMethodProperty extends AbstractProperty { */ public NestedMethodProperty(Object instance, String propertyName) { this.instance = instance; - initialize(instance, propertyName); + initialize(instance.getClass(), propertyName); + } + + /** + * For internal use to deduce property type etc. without a bean instance. + * Calling {@link #setValue(Object)} or {@link #getValue()} on properties + * constructed this way is not supported. + * + * @param instanceClass + * class of the top-level bean + * @param propertyName + */ + NestedMethodProperty(Class<?> instanceClass, String propertyName) { + instance = null; + initialize(instanceClass, propertyName); } /** * Initializes most of the internal fields based on the top-level bean * instance and property name (dot-separated string). * - * @param instance - * top-level bean to which the property applies + * @param beanClass + * class of the top-level bean to which the property applies * @param propertyName * dot separated nested property name * @throws IllegalArgumentException * if the property name is invalid */ - private void initialize(Object instance, String propertyName) + private void initialize(Class<?> beanClass, String propertyName) throws IllegalArgumentException { List<Method> getMethods = new ArrayList<Method>(); String lastSimplePropertyName = propertyName; - Class<?> lastClass = instance.getClass(); + Class<?> lastClass = beanClass; // first top-level property, then go deeper in a loop - Class<?> propertyClass = instance.getClass(); + Class<?> propertyClass = beanClass; String[] simplePropertyNames = propertyName.split("\\."); if (propertyName.endsWith(".") || 0 == simplePropertyNames.length) { throw new IllegalArgumentException("Invalid property name '" diff --git a/src/com/vaadin/data/util/NestedPropertyDescriptor.java b/src/com/vaadin/data/util/NestedPropertyDescriptor.java index 22c92014b6..cbe800dff3 100644 --- a/src/com/vaadin/data/util/NestedPropertyDescriptor.java +++ b/src/com/vaadin/data/util/NestedPropertyDescriptor.java @@ -24,16 +24,18 @@ public class NestedPropertyDescriptor<BT> implements * Creates a property descriptor that can create MethodProperty instances to * access the underlying bean property. * - * The property is only validated when trying to access its value. - * * @param name * of the property in a dotted path format, e.g. "address.street" - * @param propertyType - * type (class) of the property + * @param beanType + * type (class) of the top-level bean + * @throws IllegalArgumentException + * if the property name is invalid */ - public NestedPropertyDescriptor(String name, Class<?> propertyType) { + public NestedPropertyDescriptor(String name, Class<BT> beanType) + throws IllegalArgumentException { this.name = name; - this.propertyType = propertyType; + NestedMethodProperty property = new NestedMethodProperty(beanType, name); + this.propertyType = property.getType(); } public String getName() { |