org.netbeans.validation.api.conversion
Class Converter<From,To>

java.lang.Object
  extended by org.netbeans.validation.api.conversion.Converter<From,To>

public abstract class Converter<From,To>
extends java.lang.Object

Converts a validator of one type to a validator that works against a different type. In this way, it is possible to write only validators for Strings, but use them against javax.swing.text.Documents, etc.

Author:
Tim Boudreau

Constructor Summary
Constructor and Description
Converter()
           
 
Method Summary
Modifier and Type Method and Description
 Validator<To> convert(Validator<From>... froms)
           
abstract  Validator<To> convert(Validator<From> from)
          Create a validator for type To by wrapping a validator for type From.
static
<From,To> Converter<From,To>
find(java.lang.Class<From> from, java.lang.Class<To> to)
          Find a converter to create validators for one type from validators for another type.
static
<From,To> void
register(java.lang.Class<From> from, java.lang.Class<To> to, Converter<From,To> converter)
          Register a converter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Converter

public Converter()
Method Detail

convert

public abstract Validator<To> convert(Validator<From> from)
Create a validator for type To by wrapping a validator for type From. For example, a converter that is a factory for Validators of javax.swing.text.Documents may be created from a validator that only handles Strings. Convert would simply return a Validator that first calls Document.getText(), and passes the result to the Validator.

Parameters:
from - The original validator.
Returns:
A validator of the type requested

convert

public final Validator<To> convert(Validator<From>... froms)

register

public static <From,To> void register(java.lang.Class<From> from,
                                      java.lang.Class<To> to,
                                      Converter<From,To> converter)
Register a converter

Type Parameters:
From -
To -
Parameters:
from -
to -
converter -

find

public static <From,To> Converter<From,To> find(java.lang.Class<From> from,
                                                java.lang.Class<To> to)
Find a converter to create validators for one type from validators for another type.

Type Parameters:
From - The type of object we get from a component, such as a javax.swing.text.Document
To - The type of object we want to process, such as a java.lang.String
Parameters:
from - A class, such as Document.class
to - A class such as String.class
Returns:
An object which can take validators for type From and produce validators for type To