aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2011-12-21 09:10:17 +0200
committerArtur Signell <artur@vaadin.com>2011-12-21 09:10:56 +0200
commit7e594fb40fd2a9ad1759d422a62a5c4045351e6d (patch)
treeebe018f799472e6e533fe46257b0de7967128c00 /src
parentfbfab86bcdde3fbae4df02212e2d100163a30316 (diff)
downloadvaadin-framework-7e594fb40fd2a9ad1759d422a62a5c4045351e6d.tar.gz
vaadin-framework-7e594fb40fd2a9ad1759d422a62a5c4045351e6d.zip
#8125 Removed Property.ConversionException and String constructor based
conversion from Property classes
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/data/Property.java62
-rw-r--r--src/com/vaadin/data/util/IndexedContainer.java22
-rw-r--r--src/com/vaadin/data/util/MethodProperty.java5
-rw-r--r--src/com/vaadin/data/util/NestedMethodProperty.java5
-rw-r--r--src/com/vaadin/data/util/ObjectProperty.java7
-rw-r--r--src/com/vaadin/data/util/PropertyFormatter.java7
-rw-r--r--src/com/vaadin/data/util/TransactionalPropertyWrapper.java3
-rw-r--r--src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java18
-rw-r--r--src/com/vaadin/ui/AbstractField.java11
-rw-r--r--src/com/vaadin/ui/AbstractSelect.java18
-rw-r--r--src/com/vaadin/ui/AbstractTextField.java3
-rw-r--r--src/com/vaadin/ui/DateField.java28
-rw-r--r--src/com/vaadin/ui/Slider.java3
13 files changed, 34 insertions, 158 deletions
diff --git a/src/com/vaadin/data/Property.java b/src/com/vaadin/data/Property.java
index c8499722a2..052a174408 100644
--- a/src/com/vaadin/data/Property.java
+++ b/src/com/vaadin/data/Property.java
@@ -65,12 +65,8 @@ public interface Property<T> extends Serializable {
*
* @throws Property.ReadOnlyException
* if the object is in read-only mode
- * @throws Property.ConversionException
- * if newValue can't be converted into the Property's native
- * type directly or using a converter
*/
- public void setValue(Object newValue) throws Property.ReadOnlyException,
- Property.ConversionException;
+ public void setValue(Object newValue) throws Property.ReadOnlyException;
/**
* Returns the type of the Property. The methods <code>getValue</code> and
@@ -137,62 +133,6 @@ public interface Property<T> extends Serializable {
}
/**
- * An exception that signals that the value passed to the
- * <code>setValue</code> method couldn't be converted to the native type of
- * the Property.
- *
- * @author Vaadin Ltd
- * @version
- * @VERSION@
- * @since 3.0
- */
- @SuppressWarnings("serial")
- public class ConversionException extends RuntimeException {
-
- /**
- * Constructs a new <code>ConversionException</code> without a detail
- * message.
- */
- public ConversionException() {
- }
-
- /**
- * Constructs a new <code>ConversionException</code> with the specified
- * detail message.
- *
- * @param msg
- * the detail message
- */
- public ConversionException(String msg) {
- super(msg);
- }
-
- /**
- * Constructs a new <code>ConversionException</code> from another
- * exception.
- *
- * @param cause
- * The cause of the the conversion failure
- */
- public ConversionException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Constructs a new <code>ConversionException</code> with the specified
- * detail message and cause.
- *
- * @param message
- * the detail message
- * @param cause
- * The cause of the the conversion failure
- */
- public ConversionException(String message, Throwable cause) {
- super(message, cause);
- }
- }
-
- /**
* Interface implemented by the viewer classes capable of using a Property
* as a data source.
*
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");
}
/*
diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java
index daef4c0ddb..182aff05b5 100644
--- a/src/com/vaadin/ui/AbstractField.java
+++ b/src/com/vaadin/ui/AbstractField.java
@@ -557,11 +557,11 @@ public abstract class AbstractField<T> extends AbstractComponent implements
* @throws Property.ConversionException
*/
public void setValue(Object newFieldValue)
- throws Property.ReadOnlyException, Property.ConversionException {
+ throws Property.ReadOnlyException, Converter.ConversionException {
// This check is needed as long as setValue accepts Object instead of T
if (newFieldValue != null) {
if (!getType().isAssignableFrom(newFieldValue.getClass())) {
- throw new ConversionException("Value of type "
+ throw new Converter.ConversionException("Value of type "
+ newFieldValue.getClass() + " cannot be assigned to "
+ getClass().getName());
}
@@ -577,10 +577,9 @@ public abstract class AbstractField<T> extends AbstractComponent implements
* @param repaintIsNotNeeded
* True iff caller is sure that repaint is not needed.
* @throws Property.ReadOnlyException
- * @throws Property.ConversionException
*/
protected void setValue(T newFieldValue, boolean repaintIsNotNeeded)
- throws Property.ReadOnlyException, Property.ConversionException,
+ throws Property.ReadOnlyException, Converter.ConversionException,
InvalidValueException {
if (!equals(newFieldValue, getInternalValue())) {
@@ -826,7 +825,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
if (getType().isAssignableFrom(newValue.getClass())) {
return (T) newValue;
} else {
- throw new ConversionException(
+ throw new Converter.ConversionException(
"Unable to convert value of type "
+ newValue.getClass().getName()
+ " to "
@@ -857,7 +856,7 @@ public abstract class AbstractField<T> extends AbstractComponent implements
return valueConverter.convertFromTargetToSource(fieldValue,
getLocale());
} catch (com.vaadin.data.util.converter.Converter.ConversionException e) {
- throw new ConversionException(
+ throw new Converter.ConversionException(
getValueConversionError(valueConverter.getSourceType()));
}
}
diff --git a/src/com/vaadin/ui/AbstractSelect.java b/src/com/vaadin/ui/AbstractSelect.java
index 8b6def08a6..3e483333ff 100644
--- a/src/com/vaadin/ui/AbstractSelect.java
+++ b/src/com/vaadin/ui/AbstractSelect.java
@@ -516,16 +516,9 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
// Sets the caption property, if used
if (getItemCaptionPropertyId() != null) {
- try {
- getContainerProperty(newItemCaption,
- getItemCaptionPropertyId()).setValue(
- newItemCaption);
- } catch (final Property.ConversionException ignored) {
- /*
- * The conversion exception is safely ignored, the
- * caption is just missing
- */
- }
+ getContainerProperty(newItemCaption,
+ getItemCaptionPropertyId())
+ .setValue(newItemCaption);
}
if (isMultiSelect()) {
Set values = new HashSet((Collection) getValue());
@@ -615,8 +608,7 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
* @see com.vaadin.ui.AbstractField#setValue(java.lang.Object)
*/
@Override
- public void setValue(Object newValue) throws Property.ReadOnlyException,
- Property.ConversionException {
+ public void setValue(Object newValue) throws Property.ReadOnlyException {
if (newValue == getNullSelectionItemId()) {
newValue = null;
}
@@ -642,7 +634,7 @@ public abstract class AbstractSelect extends AbstractField<Object> implements
*/
@Override
protected void setValue(Object newValue, boolean repaintIsNotNeeded)
- throws Property.ReadOnlyException, Property.ConversionException {
+ throws Property.ReadOnlyException {
if (isMultiSelect()) {
if (newValue == null) {
diff --git a/src/com/vaadin/ui/AbstractTextField.java b/src/com/vaadin/ui/AbstractTextField.java
index a958b61c2f..7d2509b978 100644
--- a/src/com/vaadin/ui/AbstractTextField.java
+++ b/src/com/vaadin/ui/AbstractTextField.java
@@ -505,8 +505,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements
}
@Override
- public void setValue(Object newValue) throws ReadOnlyException,
- ConversionException {
+ public void setValue(Object newValue) throws ReadOnlyException {
super.setValue(newValue);
/*
* Make sure w reset lastKnownTextContent field on value change. The
diff --git a/src/com/vaadin/ui/DateField.java b/src/com/vaadin/ui/DateField.java
index c3e068e4c2..085f0b4826 100644
--- a/src/com/vaadin/ui/DateField.java
+++ b/src/com/vaadin/ui/DateField.java
@@ -4,7 +4,6 @@
package com.vaadin.ui;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -19,6 +18,7 @@ import java.util.TimeZone;
import com.vaadin.data.Property;
import com.vaadin.data.Validator;
import com.vaadin.data.Validator.InvalidValueException;
+import com.vaadin.data.util.converter.Converter;
import com.vaadin.event.FieldEvents;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
@@ -424,7 +424,7 @@ public class DateField extends AbstractField<Date> implements
* this case the invalid text remains in the DateField.
*/
requestRepaint();
- } catch (ConversionException e) {
+ } catch (Converter.ConversionException e) {
/*
* Datefield now contains some text that could't be parsed
@@ -504,9 +504,9 @@ public class DateField extends AbstractField<Date> implements
* to keep the old value and indicate an error
*/
protected Date handleUnparsableDateString(String dateString)
- throws Property.ConversionException {
+ throws Converter.ConversionException {
currentParseErrorMessage = null;
- throw new Property.ConversionException(getParseErrorMessage());
+ throw new Converter.ConversionException(getParseErrorMessage());
}
/* Property features */
@@ -527,7 +527,7 @@ public class DateField extends AbstractField<Date> implements
*/
@Override
protected void setValue(Date newValue, boolean repaintIsNotNeeded)
- throws Property.ReadOnlyException, Property.ConversionException {
+ throws Property.ReadOnlyException {
/*
* First handle special case when the client side component have a date
@@ -560,23 +560,7 @@ public class DateField extends AbstractField<Date> implements
return;
}
- if (newValue == null || newValue instanceof Date) {
- super.setValue(newValue, repaintIsNotNeeded);
- } else {
- // Try to parse the given string value to Date
- try {
- final SimpleDateFormat parser = new SimpleDateFormat();
- final TimeZone currentTimeZone = getTimeZone();
- if (currentTimeZone != null) {
- parser.setTimeZone(currentTimeZone);
- }
- final Date val = parser.parse(newValue.toString());
- super.setValue(val, repaintIsNotNeeded);
- } catch (final ParseException e) {
- uiHasValidDateString = false;
- throw new Property.ConversionException(getParseErrorMessage());
- }
- }
+ super.setValue(newValue, repaintIsNotNeeded);
}
/**
diff --git a/src/com/vaadin/ui/Slider.java b/src/com/vaadin/ui/Slider.java
index 3e7b4393a0..f077afb8ff 100644
--- a/src/com/vaadin/ui/Slider.java
+++ b/src/com/vaadin/ui/Slider.java
@@ -269,8 +269,7 @@ public class Slider extends AbstractField<Double> {
@Override
public void setValue(Object newFieldValue)
- throws com.vaadin.data.Property.ReadOnlyException,
- com.vaadin.data.Property.ConversionException {
+ throws com.vaadin.data.Property.ReadOnlyException {
if (newFieldValue != null && newFieldValue instanceof Number
&& !(newFieldValue instanceof Double)) {
// Support setting all types of Numbers