package com.vaadin.data.util;
+import static com.vaadin.util.ReflectTools.convertPrimitiveType;
+
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
return getMethod;
}
- static Class<?> convertPrimitiveType(Class<?> type) {
- // Gets the return type from get method
- if (type.isPrimitive()) {
- if (type.equals(Boolean.TYPE)) {
- type = Boolean.class;
- } else if (type.equals(Integer.TYPE)) {
- type = Integer.class;
- } else if (type.equals(Float.TYPE)) {
- type = Float.class;
- } else if (type.equals(Double.TYPE)) {
- type = Double.class;
- } else if (type.equals(Byte.TYPE)) {
- type = Byte.class;
- } else if (type.equals(Character.TYPE)) {
- type = Character.class;
- } else if (type.equals(Short.TYPE)) {
- type = Short.class;
- } else if (type.equals(Long.TYPE)) {
- type = Long.class;
- }
- }
- return type;
- }
-
/**
* Returns the type of the Property. The methods <code>getValue</code> and
* <code>setValue</code> must be compatible with this type: one must be able
import java.util.logging.Logger;
import com.vaadin.data.Property;
+import com.vaadin.util.ReflectTools;
import com.vaadin.util.SerializerHelper;
/**
public MethodPropertyDescriptor(String name, Class<?> propertyType,
Method readMethod, Method writeMethod) {
this.name = name;
- this.propertyType = propertyType;
+ this.propertyType = ReflectTools.convertPrimitiveType(propertyType);
this.readMethod = readMethod;
this.writeMethod = writeMethod;
}
@SuppressWarnings("unchecked")
// business assumption; type parameters not checked at runtime
Class<BT> class1 = (Class<BT>) SerializerHelper.readClass(in);
- propertyType = class1;
+ propertyType = ReflectTools.convertPrimitiveType(class1);
String name = (String) in.readObject();
Class<?> writeMethodClass = SerializerHelper.readClass(in);
*/
package com.vaadin.data.util;
+import static com.vaadin.util.ReflectTools.convertPrimitiveType;
+
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
} catch (final NoSuchMethodException skipped) {
}
- this.type = (Class<? extends T>) MethodProperty
- .convertPrimitiveType(type);
+ this.type = (Class<? extends T>) convertPrimitiveType(type);
this.propertyName = propertyName;
this.getMethods = getMethods;
this.setMethod = setMethod;
}
field.set(object, value);
}
+
+ public static Class<?> convertPrimitiveType(Class<?> type) {
+ // Gets the return type from get method
+ if (type.isPrimitive()) {
+ if (type.equals(Boolean.TYPE)) {
+ type = Boolean.class;
+ } else if (type.equals(Integer.TYPE)) {
+ type = Integer.class;
+ } else if (type.equals(Float.TYPE)) {
+ type = Float.class;
+ } else if (type.equals(Double.TYPE)) {
+ type = Double.class;
+ } else if (type.equals(Byte.TYPE)) {
+ type = Byte.class;
+ } else if (type.equals(Character.TYPE)) {
+ type = Character.class;
+ } else if (type.equals(Short.TYPE)) {
+ type = Short.class;
+ } else if (type.equals(Long.TYPE)) {
+ type = Long.class;
+ }
+ }
+ return type;
+ }
}
public static class Person implements Serializable {
private String name;
private Address address;
+ private int age;
public Person(String name, Address address) {
this.name = name;
this.address = address;
}
+ public Person(String name, Address address, int age) {
+ this.name = name;
+ this.address = address;
+ this.age = age;
+ }
+
public void setName(String name) {
this.name = name;
}
public Address getAddress() {
return address;
}
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
}
public static class Team implements Serializable {
Assert.assertNull(property.getValue());
}
+ public void testMethodPropertyDescriptorWithPrimitivePropertyType()
+ throws Exception {
+ MethodPropertyDescriptor<Person> pd = new MethodPropertyDescriptor<Person>(
+ "age", int.class, Person.class.getMethod("getAge"),
+ Person.class.getMethod("setAge", int.class));
+
+ Assert.assertEquals(Integer.class, pd.getPropertyType());
+ }
}