org.apache.cocoon.forms.datatype
Interface Datatype

All Known Implementing Classes:
AbstractDatatype, BeanType, BooleanType, CharType, DateType, DecimalType, DoubleType, EnumType, FloatType, IntegerType, LongType, StringType

public interface Datatype

A Datatype encapsulates the functionality for working with specific kinds of data like integers, decimals or dates.

It provides:

Each datatype can be marked as an "arraytype". Currently, this only has an influence on the validate(Object, ExpressionContext) method, which should in that case be passed an array of objects. See also isArrayType().

Version:
$Id: Datatype.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Method Summary
 ConversionResult convertFromString(String value, Locale locale)
          Converts a string to an object of this datatype.
 String convertToString(Object value, Locale locale)
          Converts an object of this datatype to a string representation.
 void generateSaxFragment(ContentHandler contentHandler, Locale locale)
          Generates a bit of information about this datatype.
 DatatypeBuilder getBuilder()
          Returns the factory that built this datatype.
 Convertor getConvertor()
          Returns the convertor used by this datatype.
 String getDescriptiveName()
          Returns a descriptive name for the base type of this datatype, i.e. something like 'string', 'long', 'decimal', ...
 Convertor getPlainConvertor()
          Returns the "plain convertor".
 Class getTypeClass()
          Gets the class object for the type represented by this datatype.
 boolean isArrayType()
          Indicates wether this datatype represents an array type.
 ValidationError validate(Object value, org.outerj.expression.ExpressionContext expressionContext)
          Returns null if validation is successful, otherwise returns a ValidationError instance.
 

Method Detail

convertFromString

ConversionResult convertFromString(String value,
                                   Locale locale)
Converts a string to an object of this datatype. This method uses the same Convertor as returned by the getConvertor() method.


convertToString

String convertToString(Object value,
                       Locale locale)
Converts an object of this datatype to a string representation. This method uses the same Convertor as returned by the getConvertor() method.


validate

ValidationError validate(Object value,
                         org.outerj.expression.ExpressionContext expressionContext)
Returns null if validation is successful, otherwise returns a ValidationError instance.

Parameters:
value - an Object of the correct type for this datatype (see getTypeClass(), or if isArrayType() returns true, an array of objects of that type.

getTypeClass

Class getTypeClass()
Gets the class object for the type represented by this datatype. E.g. Long, String, ... The objects returned from the convertFromString* methods are of this type, and the object passed to the convertToString* or validate methods should be of this type.


getDescriptiveName

String getDescriptiveName()
Returns a descriptive name for the base type of this datatype, i.e. something like 'string', 'long', 'decimal', ...


isArrayType

boolean isArrayType()
Indicates wether this datatype represents an array type. This approach has been chosen instead of creating a seperate ArrayDatatype interface (and corresponding implementations), since almost all functionality is the same between the scalar and array types. The main difference is that the validate() method will be passed arrays instead of single values, and hence different validation rules will be required.


getConvertor

Convertor getConvertor()
Returns the convertor used by this datatype.


getPlainConvertor

Convertor getPlainConvertor()
Returns the "plain convertor". This is convertor that should have a locale-independent string encoding, and guarantees perfect roundtripping. It is used if a value of this datatype needs to be stored but not displayed to the user.


getBuilder

DatatypeBuilder getBuilder()
Returns the factory that built this datatype.


generateSaxFragment

void generateSaxFragment(ContentHandler contentHandler,
                         Locale locale)
                         throws SAXException
Generates a bit of information about this datatype.

Throws:
SAXException


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.