*
* @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
}
}
- /**
- * 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.
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;
*
* @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);
} 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
* @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()) {
// 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.");
}
* 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();
// 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.");
}
* 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()) {
// 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.");
}
}
}
- public void setValue(Object newValue) throws ReadOnlyException,
- ConversionException {
+ public void setValue(Object newValue) throws ReadOnlyException {
if (dataSource == null) {
return;
}
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);
}
}
}
return wrappedProperty.getValue();\r
}\r
\r
- public void setValue(Object newValue) throws ReadOnlyException,\r
- ConversionException {\r
+ public void setValue(Object newValue) throws ReadOnlyException {\r
// Causes a value change to be sent to this listener which in turn fires\r
// a new value change event for this property\r
wrappedProperty.setValue(newValue);\r
*/
package com.vaadin.data.util.sqlcontainer;
-import java.lang.reflect.Constructor;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
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.");
}
}
- /*
- * 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");
}
/*
* @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());
}
* @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())) {
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 "
return valueConverter.convertFromTargetToSource(fieldValue,
getLocale());
} catch (com.vaadin.data.util.converter.Converter.ConversionException e) {
- throw new ConversionException(
+ throw new Converter.ConversionException(
getValueConversionError(valueConverter.getSourceType()));
}
}
// 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());
* @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;
}
*/
@Override
protected void setValue(Object newValue, boolean repaintIsNotNeeded)
- throws Property.ReadOnlyException, Property.ConversionException {
+ throws Property.ReadOnlyException {
if (isMultiSelect()) {
if (newValue == null) {
}
@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
package com.vaadin.ui;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
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;
* 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
* 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 */
*/
@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
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);
}
/**
@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
return null;
}
- public void setValue(Object newValue) throws ReadOnlyException,
- ConversionException {
+ public void setValue(Object newValue) throws ReadOnlyException {
throw new ReadOnlyException();
}
try {\r
tf.setValue(1);\r
fail("setValue(Integer) should throw an exception");\r
- } catch (com.vaadin.data.Property.ConversionException e) {\r
+ } catch (Converter.ConversionException e) {\r
// OK, expected\r
}\r
}\r
}\r
\r
@Override\r
- public void setInternalValue(Address address) throws ReadOnlyException,\r
- ConversionException {\r
+ public void setInternalValue(Address address) throws ReadOnlyException {\r
// create the address if not given\r
if (null == address) {\r
address = new Address();\r
import java.util.Date;\r
\r
import com.vaadin.data.Property;\r
+import com.vaadin.data.util.converter.Converter;\r
import com.vaadin.tests.components.TestBase;\r
import com.vaadin.ui.DateField;\r
\r
addListener(new Property.ValueChangeListener() {\r
public void valueChange(\r
com.vaadin.data.Property.ValueChangeEvent event) {\r
- oldDate = (Date) getValue();\r
+ oldDate = getValue();\r
}\r
});\r
}\r
\r
@Override\r
protected Date handleUnparsableDateString(String dateString)\r
- throws ConversionException {\r
+ throws Converter.ConversionException {\r
return oldDate;\r
}\r
}\r
\r
@Override\r
protected Date handleUnparsableDateString(String dateString)\r
- throws ConversionException {\r
+ throws Converter.ConversionException {\r
return null;\r
}\r
}\r
\r
@Override\r
protected Date handleUnparsableDateString(String dateString)\r
- throws ConversionException {\r
- throw new ConversionException("You should not enter invalid dates!");\r
+ throws Converter.ConversionException {\r
+ throw new Converter.ConversionException(\r
+ "You should not enter invalid dates!");\r
}\r
}\r
\r
\r
@Override\r
protected Date handleUnparsableDateString(String dateString)\r
- throws ConversionException {\r
+ throws Converter.ConversionException {\r
if (dateString != null && dateString.equals("today")) {\r
return new Date();\r
}\r
- throw new ConversionException("You should not enter invalid dates!");\r
+ throw new Converter.ConversionException(\r
+ "You should not enter invalid dates!");\r
}\r
}\r
\r
return value;
}
- public void setValue(Object newValue) throws ReadOnlyException,
- ConversionException {
+ public void setValue(Object newValue) throws ReadOnlyException {
if (newValue == null) {
value = null;
} else if (newValue instanceof BigDecimal) {
value = (BigDecimal) newValue;
} else {
- throw new ConversionException();
+ throw new IllegalArgumentException(
+ "Value must be of type BigDecimal");
}
}