Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cocoon.forms.datatype
Interface Datatype

All Known Implementing Classes:
  AbstractDatatype

public interface Datatype

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

It provides:

- Methods for converting between String and Object representation of the data
- For validating the data (usually against a set of validation rules)
- optionally a selection list

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.java 587759 2007-10-24 03:00:37Z vgritsenko $

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.
`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

    public 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

    public 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

    public 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

    public 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

    public String getDescriptiveName()

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

### isArrayType

    public 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

    public Convertor getConvertor()

  Returns the convertor used by this datatype.

### getPlainConvertor

    public 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

    public DatatypeBuilder getBuilder()

  Returns the factory that built this datatype.

### generateSaxFragment

    public void generateSaxFragment(ContentHandler contentHandler,
                                    Locale locale)
                             throws SAXException

  Generates a bit of information about this datatype.

  Throws:
    `SAXException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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