diff options
author | Artur Signell <artur@vaadin.com> | 2011-12-21 09:10:17 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2011-12-21 09:10:56 +0200 |
commit | 7e594fb40fd2a9ad1759d422a62a5c4045351e6d (patch) | |
tree | ebe018f799472e6e533fe46257b0de7967128c00 /src/com/vaadin/data/util | |
parent | fbfab86bcdde3fbae4df02212e2d100163a30316 (diff) | |
download | vaadin-framework-7e594fb40fd2a9ad1759d422a62a5c4045351e6d.tar.gz vaadin-framework-7e594fb40fd2a9ad1759d422a62a5c4045351e6d.zip |
#8125 Removed Property.ConversionException and String constructor based
conversion from Property classes
Diffstat (limited to 'src/com/vaadin/data/util')
7 files changed, 15 insertions, 52 deletions
diff --git a/src/com/vaadin/data/util/IndexedContainer.java b/src/com/vaadin/data/util/IndexedContainer.java index 56ad2a929f..424fccb1e9 100644 --- a/src/com/vaadin/data/util/IndexedContainer.java +++ b/src/com/vaadin/data/util/IndexedContainer.java @@ -5,7 +5,6 @@ package com.vaadin.data.util; import java.io.Serializable; -import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -865,8 +864,7 @@ public class IndexedContainer extends * * @see com.vaadin.data.Property#setValue(java.lang.Object) */ - public void setValue(Object newValue) - throws Property.ReadOnlyException, Property.ConversionException { + public void setValue(Object newValue) throws Property.ReadOnlyException { // Gets the Property set final Map<Object, Object> propertySet = items.get(itemId); @@ -877,22 +875,8 @@ public class IndexedContainer extends } else if (getType().isAssignableFrom(newValue.getClass())) { propertySet.put(propertyId, newValue); } else { - try { - - // Gets the string constructor - final Constructor<?> constr = getType().getConstructor( - new Class[] { String.class }); - - // Creates new object from the string - propertySet.put(propertyId, constr - .newInstance(new Object[] { newValue.toString() })); - - } catch (final java.lang.Exception e) { - throw new Property.ConversionException( - "Conversion for value '" + newValue + "' of class " - + newValue.getClass().getName() + " to " - + getType().getName() + " failed", e); - } + throw new IllegalArgumentException("Value is of invalid type, " + + getType().getName() + " expected"); } // update the container filtering if this property is being filtered diff --git a/src/com/vaadin/data/util/MethodProperty.java b/src/com/vaadin/data/util/MethodProperty.java index ec9a4e0c0a..bffa2ae94e 100644 --- a/src/com/vaadin/data/util/MethodProperty.java +++ b/src/com/vaadin/data/util/MethodProperty.java @@ -644,8 +644,7 @@ public class MethodProperty<T> extends AbstractProperty<T> { * @see #invokeSetMethod(Object) */ @SuppressWarnings("unchecked") - public void setValue(Object newValue) throws Property.ReadOnlyException, - Property.ConversionException { + public void setValue(Object newValue) throws Property.ReadOnlyException { // Checks the mode if (isReadOnly()) { @@ -654,7 +653,7 @@ public class MethodProperty<T> extends AbstractProperty<T> { // Checks the type of the value if (newValue != null && !type.isAssignableFrom(newValue.getClass())) { - throw new Property.ConversionException( + throw new IllegalArgumentException( "Invalid value type for ObjectProperty."); } diff --git a/src/com/vaadin/data/util/NestedMethodProperty.java b/src/com/vaadin/data/util/NestedMethodProperty.java index b8b6ad7101..9cd83044e9 100644 --- a/src/com/vaadin/data/util/NestedMethodProperty.java +++ b/src/com/vaadin/data/util/NestedMethodProperty.java @@ -206,8 +206,7 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> { * native type directly or through <code>String</code>. * @see #invokeSetMethod(Object) */ - public void setValue(Object newValue) throws ReadOnlyException, - ConversionException { + public void setValue(Object newValue) throws ReadOnlyException { // Checks the mode if (isReadOnly()) { throw new Property.ReadOnlyException(); @@ -215,7 +214,7 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> { // Checks the type of the value if (newValue != null && !type.isAssignableFrom(newValue.getClass())) { - throw new Property.ConversionException( + throw new IllegalArgumentException( "Invalid value type for NestedMethodProperty."); } diff --git a/src/com/vaadin/data/util/ObjectProperty.java b/src/com/vaadin/data/util/ObjectProperty.java index 79e5436cc5..40e25dca89 100644 --- a/src/com/vaadin/data/util/ObjectProperty.java +++ b/src/com/vaadin/data/util/ObjectProperty.java @@ -114,12 +114,9 @@ public class ObjectProperty<T> extends AbstractProperty<T> { * the New value of the property. * @throws <code>Property.ReadOnlyException</code> if the object is in * read-only mode - * @throws <code>Property.ConversionException</code> if the newValue is not - * of a correct type */ @SuppressWarnings("unchecked") - public void setValue(Object newValue) throws Property.ReadOnlyException, - Property.ConversionException { + public void setValue(Object newValue) throws Property.ReadOnlyException { // Checks the mode if (isReadOnly()) { @@ -128,7 +125,7 @@ public class ObjectProperty<T> extends AbstractProperty<T> { // Checks the type of the value if (newValue != null && !type.isAssignableFrom(newValue.getClass())) { - throw new Property.ConversionException( + throw new IllegalArgumentException( "Invalid value type for ObjectProperty."); } diff --git a/src/com/vaadin/data/util/PropertyFormatter.java b/src/com/vaadin/data/util/PropertyFormatter.java index b778028613..1b27513594 100644 --- a/src/com/vaadin/data/util/PropertyFormatter.java +++ b/src/com/vaadin/data/util/PropertyFormatter.java @@ -204,8 +204,7 @@ public abstract class PropertyFormatter<T> extends AbstractProperty<String> } } - public void setValue(Object newValue) throws ReadOnlyException, - ConversionException { + public void setValue(Object newValue) throws ReadOnlyException { if (dataSource == null) { return; } @@ -220,10 +219,8 @@ public abstract class PropertyFormatter<T> extends AbstractProperty<String> if (!newValue.equals(getStringValue())) { fireValueChange(); } - } catch (ConversionException e) { - throw e; } catch (Exception e) { - throw new ConversionException(e); + throw new IllegalArgumentException("Could not parse value", e); } } } diff --git a/src/com/vaadin/data/util/TransactionalPropertyWrapper.java b/src/com/vaadin/data/util/TransactionalPropertyWrapper.java index 2cc0154b22..b593387d71 100644 --- a/src/com/vaadin/data/util/TransactionalPropertyWrapper.java +++ b/src/com/vaadin/data/util/TransactionalPropertyWrapper.java @@ -37,8 +37,7 @@ public class TransactionalPropertyWrapper<T> extends AbstractProperty<T> return wrappedProperty.getValue();
}
- public void setValue(Object newValue) throws ReadOnlyException,
- ConversionException {
+ public void setValue(Object newValue) throws ReadOnlyException {
// Causes a value change to be sent to this listener which in turn fires
// a new value change event for this property
wrappedProperty.setValue(newValue);
diff --git a/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java b/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java index f9b07f8c4c..5e152da79e 100644 --- a/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java +++ b/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java @@ -3,7 +3,6 @@ */ package com.vaadin.data.util.sqlcontainer; -import java.lang.reflect.Constructor; import java.sql.Date; import java.sql.Time; import java.sql.Timestamp; @@ -69,8 +68,7 @@ final public class ColumnProperty implements Property { return value; } - public void setValue(Object newValue) throws ReadOnlyException, - ConversionException { + public void setValue(Object newValue) throws ReadOnlyException { if (newValue == null && !nullable) { throw new NotNullableException( "Null values are not allowed for this property."); @@ -109,19 +107,9 @@ final public class ColumnProperty implements Property { } } - /* - * If the type is not correct, try to generate it through a possibly - * existing String constructor. - */ if (!getType().isAssignableFrom(newValue.getClass())) { - try { - final Constructor<?> constr = getType().getConstructor( - new Class[] { String.class }); - newValue = constr.newInstance(new Object[] { newValue - .toString() }); - } catch (Exception e) { - throw new ConversionException(e); - } + throw new IllegalArgumentException( + "Illegal value type for ColumnProperty"); } /* |