org.xins.common.types
Class PatternType

java.lang.Object
  extended byorg.xins.common.types.Type
      extended byorg.xins.common.types.PatternType

public abstract class PatternType
extends Type

Abstract base class for pattern types. A pattern type only accepts values that match a certain regular expression.

Since:
XINS 1.0.0
Version:
$Revision: 1.19 $ $Date: 2006/08/28 09:12:34 $
Author:
Ernst de Haan

Constructor Summary
protected PatternType(String name, String pattern)
          Creates a new PatternType instance.
 
Method Summary
protected  Object fromStringImpl(String value)
          Converts from a String to an instance of the value class for this type (implementation method).
 String getPattern()
          Returns the pattern.
protected  boolean isValidValueImpl(String value)
          Determines if the specified String value is considered valid for this type (implementation method).
 String toString(Object value)
          Generates a string representation of the specified value for this type.
 
Methods inherited from class org.xins.common.types.Type
checkValue, fromString, getName, getValueClass, isValidValue, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PatternType

protected PatternType(String name,
                      String pattern)
               throws IllegalArgumentException,
                      PatternCompileException
Creates a new PatternType instance. The name of the type needs to be specified. The value class (see Type.getValueClass()) is set to String.class.

Parameters:
name - the name of the type, not null.
pattern - the regular expression the values must match, not null.
Throws:
IllegalArgumentException - if name == null || pattern == null.
PatternCompileException - if the specified pattern is considered invalid.
Method Detail

isValidValueImpl

protected final boolean isValidValueImpl(String value)
Description copied from class: Type
Determines if the specified String value is considered valid for this type (implementation method).

This method is called from Type.isValidValue(String). When called from that method, it is guaranteed that the argument is not null.

The implementation of this method in class Type returns true.

Overrides:
isValidValueImpl in class Type
Parameters:
value - the String value that should be checked for validity, never null.
Returns:
true if and only if the specified String value is valid, false otherwise.

fromStringImpl

protected final Object fromStringImpl(String value)
Description copied from class: Type
Converts from a String to an instance of the value class for this type (implementation method).

This method is not required to check the validity of the specified value (since Type.isValidValueImpl(String) should have been called before) but if it does, then it may throw a TypeValueException.

Specified by:
fromStringImpl in class Type
Parameters:
value - the string to convert to an instance of the value class, guaranteed to be not null and guaranteed to have been passed to Type.isValidValueImpl(String) without getting an exception.
Returns:
an instance of the value class, cannot be null.

toString

public final String toString(Object value)
                      throws IllegalArgumentException,
                             ClassCastException,
                             TypeValueException
Description copied from class: Type
Generates a string representation of the specified value for this type. The specified value must be an instance of the value class for this type (see Type.getValueClass()). Also, it may have to fall within a certain range of valid values, depending on the type.

The default implementation of this method in class Type does the following:

Overrides:
toString in class Type
Parameters:
value - the value, cannot be null.
Returns:
the string representation of the specified value for this type, cannot be null.
Throws:
ClassCastException - if getValueClass().isInstance(value) == false.
IllegalArgumentException - if value == null.
TypeValueException - if the specified value is not in the allowed range.

getPattern

public String getPattern()
Returns the pattern.

Returns:
the pattern, not null.


See http://www.xins.org/.