javax.beans.binding
Class BindingConverter

java.lang.Object
  extended by javax.beans.binding.BindingConverter

public abstract class BindingConverter
extends java.lang.Object

BindingConverter is used by Binding to convert values between the source and target. Use the setConverter method of Binding to install a converter on a binding. The following example illustrates a trivial String to Integer converter:

 BindingConverter stringToIntegerConverter = new BindingConverter() {
     public Object sourceToTarget(Object value) {
         try {
           return Integer.parseInt((String)value);
         } catch (NumberFormatException nfe) {
             // String isn't a recognized integer, rethrow
             // IllegalArgumentException.
             throw new IllegalArgumentException(nfe);
         }
     }
 };
 binding.setConverter(stringToIntegerConverter);
 
For one-way bindings, it is unnecessary to implement the target to source conversion, as such, the targetToSource method is concrete.


Constructor Summary
BindingConverter()
           
 
Method Summary
abstract  java.lang.Object sourceToTarget(java.lang.Object value)
          Converts a value from the source to the target.
 java.lang.Object targetToSource(java.lang.Object value)
          Converts a value from the target to source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BindingConverter

public BindingConverter()
Method Detail

sourceToTarget

public abstract java.lang.Object sourceToTarget(java.lang.Object value)
Converts a value from the source to the target.

Parameters:
value - the value to convert
Returns:
the converted value
Throws:
java.lang.ClassCastException - if value is not of a type appropriate for this converter
java.lang.IllegalArgumentException - if value can not be converted

targetToSource

public java.lang.Object targetToSource(java.lang.Object value)
Converts a value from the target to source. This implementation returns the supplied value, without any conversion.

Parameters:
value - the value to convert
Returns:
the converted value
Throws:
java.lang.ClassCastException - if value is not of a type appropriate for this converter
java.lang.IllegalArgumentException - if value can not be converted