org.mmbase.datatypes
Class BasicDataType

java.lang.Object
  extended byorg.mmbase.core.AbstractDescriptor
      extended byorg.mmbase.datatypes.BasicDataType
All Implemented Interfaces:
Cloneable, Comparable, DataType, Descriptor, Serializable
Direct Known Subclasses:
AbstractLengthDataType, BooleanDataType, ComparableDataType, NodeDataType

public class BasicDataType
extends AbstractDescriptor
implements DataType, Cloneable, Comparable, Descriptor

Every DataType extends this one. It's extensions can however implement several extensions of the DataType interface (e.g. some datatypes (at least StringDataType) are both LengthDataType and ComparableDataType, and some are only one (BinaryDataType, NumberDataType). In other words, this arrangement is like this, because java does not support Multipible inheritance.

Since:
MMBase-1.8
Version:
$Id: BasicDataType.java,v 1.58 2006/07/09 13:38:15 michiel Exp $
Author:
Pierre van Rooden, Michiel Meeuwissen
See Also:
Serialized Form

Nested Class Summary
protected  class BasicDataType.AbstractRestriction
          Abstract inner class Restriction.
protected  class BasicDataType.EnumerationRestriction
           
protected  class BasicDataType.RequiredRestriction
           
protected  class BasicDataType.RestrictedEnumerationIterator
          Iterates over the collection provided by the EnumerationRestriction, but skips the values which are invalid because of the other restrictions on this DataType.
protected static class BasicDataType.StaticAbstractRestriction
          A Restriction is represented by these kind of objects.
protected  class BasicDataType.TypeRestriction
           
protected  class BasicDataType.UniqueRestriction
           
 
Nested classes inherited from class org.mmbase.datatypes.DataType
DataType.Restriction
 
Field Summary
static String DATATYPE_BUNDLE
          The bundle used by datatype to determine default prompts for error messages when a validation fails.
protected  BasicDataType.EnumerationRestriction enumerationRestriction
           
protected  DataType origin
          The datatype from which this datatype originally inherited it's properties.
protected  BasicDataType.RequiredRestriction requiredRestriction
           
protected  BasicDataType.TypeRestriction typeRestriction
           
protected  BasicDataType.UniqueRestriction uniqueRestriction
           
 
Fields inherited from class org.mmbase.core.AbstractDescriptor
description, guiName, key
 
Fields inherited from interface org.mmbase.datatypes.DataType
ENFORCE_ABSOLUTE, ENFORCE_ALWAYS, ENFORCE_NEVER, ENFORCE_ONCHANGE, ENFORCE_ONCREATE, PROCESS_GET, PROCESS_SET, VALID, XMLNS
 
Constructor Summary
  BasicDataType(String name)
          Create a data type object of unspecified class type
protected BasicDataType(String name, Class classType)
          Create a data type object
 
Method Summary
protected  Object cast(Object value, Cloud cloud, Node node, Field field)
          Utility to avoid repetitive calling of getCloud
 Object cast(Object value, Node node, Field field)
          Tries to 'cast' an object for use with this parameter. E.g. if value is a String, but this parameter is of type Integer, then the string can be parsed to Integer. No need to override this.
protected  Object castToValidate(Object value, Node node, Field field)
          Before validating the value, the value will be 'casted', on default this will be to the 'correct' type, but it can be a more generic type sometimes.
 void checkType(Object value)
          Checks if the passed object is of the correct class (compatible with the type of this data type), and throws an IllegalArgumentException if it doesn't.
 Object clone()
           This method is final, override clone(String) in stead.
 Object clone(String name)
           Besides super.clone, it calls inheritProperties(BasicDataType) and cloneRestrictions(BasicDataType).
protected  void cloneRestrictions(BasicDataType origin)
          If a datatype is cloned, the restrictions of it (normally implemented as inner classes), must be reinstantiated.
 int compareTo(Object o)
           
protected  void edit()
           
 boolean equals(Object o)
          Whether data type equals to other data type.
 void finish()
           
 void finish(Object owner)
           
 int getBaseType()
          Return the datatype's basic (MMBase) type (i.e., STRING, INTEGER, DATETIME) as definied in the Field interface Note that in some cases (i.e.
 String getBaseTypeIdentifier()
          Return an identifier for the basic type (i.e., 'string', 'int', 'datetime') supported by this datatype.
protected  Cloud getCloud(Node node, Field field)
           
 CommitProcessor getCommitProcessor()
           
 Object getDefaultValue()
          Returns the default value of this data type.
protected  Element getElement(Element parent, String name, String path)
           
protected  Element getElement(Element parent, String pattern, String name, String path)
           
 LocalizedEntryListFactory getEnumerationFactory()
          
 DataType.Restriction getEnumerationRestriction()
          The enumeration for this datatype as a DataType.Restriction.
 Object getEnumerationValue(Locale locale, Cloud cloud, Node node, Field field, Object key)
          Returns a (gui) value from a list of retsricted enumerated values, or null if no enumeration restrictions apply or teh value cannot be found.
 Iterator getEnumerationValues(Locale locale, Cloud cloud, Node node, Field field)
          Returns an iterator over all possible values for this datatype, as Map.Entrys, or null if no enumeration restrictions apply. Every Map entry contains as key the 'value' for this datatype and as value it contains the description for this value in the given locale. This Iterator skips all entries which are impossible because of other restrictions on this datatype.
 DataType getOrigin()
          Return the DataType from which this one inherited, or null
 Processor getProcessor(int action)
          Returns the default processor for this action
 Processor getProcessor(int action, int processingType)
          Returns the processor for this action and processing type
 DataType.Restriction getRequiredRestriction()
          Returns the 'required' restriction, containing the value, errormessages, and fixed status of this attribute.
 Class getTypeAsClass()
          Returns the type of values that this data type accepts.
 DataType.Restriction getUniqueRestriction()
          Returns the 'unique' restriction, containing the value, error messages, and fixed status of this attribute.
 int hashCode()
           
 void inherit(BasicDataType origin)
          Inherit properties and processors from the passed datatype. Calls both inheritProperties(org.mmbase.datatypes.BasicDataType) and inheritRestrictions(org.mmbase.datatypes.BasicDataType).
protected  void inheritProperties(BasicDataType origin)
          Properties are members of the datatype that can easily be copied/clones.
protected  void inheritRestrictions(BasicDataType origin)
          If a datatype inherits from another datatype all its restrictions inherit too.
protected  boolean isCorrectType(Object value)
          Checks if the passed object is of the correct class (compatible with the type of this DataType), and throws an IllegalArgumentException if it doesn't.
 boolean isFinished()
           
 boolean isRequired()
          Returns whether this field is required (should have content). Note that the MMBase core does not generally enforce required fields to be filled - If not provided, a default value (generally an empty string or the integer value -1) is filled in by the system.
 boolean isUnique()
          Returns whether this field has a unique restriction. Uniqueness is generally achieved through association of the datatype with one or more sets of fields. This is notably different from other datatype properties. Note that the MMBase core does not generally enforce uniqueness, but the storage layer might.
 Object preCast(Object value, Cloud cloud)
          This method is as yet unused, but can be anticipated
protected  Object preCast(Object value, Cloud cloud, Node node, Field field)
          This method implements 'precasting', which can be seen as a kind of datatype specific casting.
 Object preCast(Object value, Node node, Field field)
          Before actually 'cast' an object to the right type, it may undergo some conversion by the datatype, e.g. enumerations may get resolved (enumerations have the feature that they can e.g. resolve java-constants to their values). This does not garantuee that the value has the 'proper' type, but only that it now can be casted to the right type without further problems. (Casting.toType(java.lang.Class, java.lang.Object) should do). preCast should not change the actual type of value. It is e.g. used in the Node#setStringValue, and the processor may expect a String there. Tries to determin cloud by node and field if possible and wraps preCast(Object, Cloud, Node, Field).
 DataType rewrite(Object owner)
           
 void setCommitProcessor(CommitProcessor cp)
           
 void setDefaultValue(Object def)
          
 void setProcessor(int action, Processor processor)
          Sets the processor for this action
 void setProcessor(int action, Processor processor, int processingType)
          Sets the processor for this action
 void setRequired(boolean required)
          Sets whether the data type requires a value, which means that it may not remain unfilled.
 void setUnique(boolean unique)
          Sets whether the data type requires a value.
 void setXml(Element element)
           
 String toString()
           
protected  StringBuffer toStringBuffer()
           
 Element toXml()
          Returns a DOM element describing this DataType.
 void toXml(Element parent)
          Fills this datatype in another XML (for example in the xml of getOrigin(), to make one XML, fully describing the DataType).
 Collection validate(Object value)
          
 Collection validate(Object value, Node node, Field field)
          Checks if the passed object obeys the restrictions defined for this type.
protected  Collection validateCastedValue(Collection errors, Object castedValue, Object value, Node node, Field field)
           
 
Methods inherited from class org.mmbase.core.AbstractDescriptor
getDefaultLocale, getDescription, getDescription, getGUIName, getGUIName, getLocalizedDescription, getLocalizedGUIName, getName, setDescription, setDescription, setGUIName, setGUIName, setLocalizedDescription, setLocalizedGUIName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mmbase.bridge.Descriptor
getDescription, getDescription, getGUIName, getGUIName, getLocalizedDescription, getLocalizedGUIName, getName, setDescription, setDescription, setGUIName, setGUIName
 

Field Detail

DATATYPE_BUNDLE

public static final String DATATYPE_BUNDLE
The bundle used by datatype to determine default prompts for error messages when a validation fails.

See Also:
Constant Field Values

requiredRestriction

protected BasicDataType.RequiredRestriction requiredRestriction

uniqueRestriction

protected BasicDataType.UniqueRestriction uniqueRestriction

typeRestriction

protected BasicDataType.TypeRestriction typeRestriction

enumerationRestriction

protected BasicDataType.EnumerationRestriction enumerationRestriction

origin

protected DataType origin
The datatype from which this datatype originally inherited it's properties.

Constructor Detail

BasicDataType

public BasicDataType(String name)
Create a data type object of unspecified class type

Parameters:
name - the name of the data type s

BasicDataType

protected BasicDataType(String name,
                        Class classType)
Create a data type object

Parameters:
name - the name of the data type
classType - the class of the data type's possible value
Method Detail

getBaseTypeIdentifier

public String getBaseTypeIdentifier()
Description copied from interface: DataType
Return an identifier for the basic type (i.e., 'string', 'int', 'datetime') supported by this datatype.

Specified by:
getBaseTypeIdentifier in interface DataType

getBaseType

public int getBaseType()
Description copied from interface: DataType
Return the datatype's basic (MMBase) type (i.e., STRING, INTEGER, DATETIME) as definied in the Field interface Note that in some cases (i.e. with older clouds) this may differ from the basic type of the datatype's field, which defines in what format the data is stored.

Specified by:
getBaseType in interface DataType
See Also:
Field.#getType

inherit

public final void inherit(BasicDataType origin)
Inherit properties and processors from the passed datatype. Calls both inheritProperties(org.mmbase.datatypes.BasicDataType) and inheritRestrictions(org.mmbase.datatypes.BasicDataType).

Specified by:
inherit in interface DataType

inheritProperties

protected void inheritProperties(BasicDataType origin)
Properties are members of the datatype that can easily be copied/clones.


cloneRestrictions

protected void cloneRestrictions(BasicDataType origin)
If a datatype is cloned, the restrictions of it (normally implemented as inner classes), must be reinstantiated.


inheritRestrictions

protected void inheritRestrictions(BasicDataType origin)
If a datatype inherits from another datatype all its restrictions inherit too.


getOrigin

public DataType getOrigin()
Return the DataType from which this one inherited, or null

Specified by:
getOrigin in interface DataType

getTypeAsClass

public Class getTypeAsClass()
Returns the type of values that this data type accepts.

Specified by:
getTypeAsClass in interface DataType
Returns:
the type as a Class

isCorrectType

protected boolean isCorrectType(Object value)
Checks if the passed object is of the correct class (compatible with the type of this DataType), and throws an IllegalArgumentException if it doesn't.

Parameters:
value - teh value whose type (class) to check
Throws:
IllegalArgumentException - if the type is not compatible

checkType

public void checkType(Object value)
Checks if the passed object is of the correct class (compatible with the type of this data type), and throws an IllegalArgumentException if it doesn't.

Specified by:
checkType in interface DataType
Parameters:
value - the value whose type (class) to check

preCast

public final Object preCast(Object value,
                            Node node,
                            Field field)
Before actually 'cast' an object to the right type, it may undergo some conversion by the datatype, e.g. enumerations may get resolved (enumerations have the feature that they can e.g. resolve java-constants to their values). This does not garantuee that the value has the 'proper' type, but only that it now can be casted to the right type without further problems. (Casting.toType(java.lang.Class, java.lang.Object) should do). preCast should not change the actual type of value. It is e.g. used in the Node#setStringValue, and the processor may expect a String there. Tries to determin cloud by node and field if possible and wraps preCast(Object, Cloud, Node, Field).

Specified by:
preCast in interface DataType

preCast

public final Object preCast(Object value,
                            Cloud cloud)
This method is as yet unused, but can be anticipated


preCast

protected Object preCast(Object value,
                         Cloud cloud,
                         Node node,
                         Field field)
This method implements 'precasting', which can be seen as a kind of datatype specific casting. It should anticipate that every argument can be null. It should not change the actual type of the value.


cast

public final Object cast(Object value,
                         Node node,
                         Field field)
Tries to 'cast' an object for use with this parameter. E.g. if value is a String, but this parameter is of type Integer, then the string can be parsed to Integer. No need to override this. It is garantueed by javadoc that cast should work out of preCast using Casting.toType. So that is what this final implementation is doing. Override preCast(Object, Cloud, Node, Field)

Specified by:
cast in interface DataType
Parameters:
value - The value to be filled in a value with this DataType.
node - Sometimes a node might be needed.
field - Sometimes a (or 'the') field might be needed.

cast

protected Object cast(Object value,
                      Cloud cloud,
                      Node node,
                      Field field)
               throws CastException
Utility to avoid repetitive calling of getCloud

Throws:
CastException

getCloud

protected final Cloud getCloud(Node node,
                               Field field)

castToValidate

protected Object castToValidate(Object value,
                                Node node,
                                Field field)
                         throws CastException
Before validating the value, the value will be 'casted', on default this will be to the 'correct' type, but it can be a more generic type sometimes. E.g. for numbers this wil simply cast to Number.

Throws:
CastException

getDefaultValue

public Object getDefaultValue()
Returns the default value of this data type.

Specified by:
getDefaultValue in interface DataType
Returns:
the default value

setDefaultValue

public void setDefaultValue(Object def)

Specified by:
setDefaultValue in interface DataType

getElement

protected Element getElement(Element parent,
                             String name,
                             String path)

getElement

protected Element getElement(Element parent,
                             String pattern,
                             String name,
                             String path)

toXml

public void toXml(Element parent)
Description copied from interface: DataType
Fills this datatype in another XML (for example in the xml of DataType.getOrigin(), to make one XML, fully describing the DataType). The implementation of this method is unfinished!

Specified by:
toXml in interface DataType
Parameters:
parent - a 'datatype' element.

isFinished

public boolean isFinished()
Specified by:
isFinished in interface DataType

finish

public void finish()
Warning: No Java Documentation Available.

finish

public void finish(Object owner)
Specified by:
finish in interface DataType
Warning: No Java Documentation Available.

rewrite

public DataType rewrite(Object owner)
Specified by:
rewrite in interface DataType
Warning: No Java Documentation Available.

edit

protected void edit()
Warning: No Java Documentation Available.

validate

public final Collection validate(Object value)

Specified by:
validate in interface DataType
Parameters:
value - the value to be validated
Returns:
The error message(s) if the value is not compatible. An empty collection if valid.
See Also:
DataType.validate(Object, Node, Field)

validate

public final Collection validate(Object value,
                                 Node node,
                                 Field field)
Description copied from interface: DataType
Checks if the passed object obeys the restrictions defined for this type.

Specified by:
validate in interface DataType
Parameters:
value - the value to validate
node - the node for which the datatype is checked. If not null, and the datatype is determined as unique, than uniquness is checked for this value using the passed field.
field - the field for which the datatype is checked.
Returns:
The error message(s) if the value is not compatible. An empty collection if the value is valid.

validateCastedValue

protected Collection validateCastedValue(Collection errors,
                                         Object castedValue,
                                         Object value,
                                         Node node,
                                         Field field)

toStringBuffer

protected StringBuffer toStringBuffer()

toString

public final String toString()
Overrides:
toString in class AbstractDescriptor

clone

public final Object clone()
This method is final, override clone(String) in stead.

Specified by:
clone in interface DataType
Overrides:
clone in class AbstractDescriptor

clone

public Object clone(String name)
Besides super.clone, it calls inheritProperties(BasicDataType) and cloneRestrictions(BasicDataType). A clone is not finished. See isFinished().

Specified by:
clone in interface DataType
Overrides:
clone in class AbstractDescriptor

toXml

public Element toXml()
Description copied from interface: DataType
Returns a DOM element describing this DataType.

Specified by:
toXml in interface DataType

setXml

public void setXml(Element element)

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable

equals

public boolean equals(Object o)
Whether data type equals to other data type. Only key and type are consided. DefaultValue and required properties are only 'utilities'.

Returns:
true if o is a DataType of which key and type equal to this' key and type.

hashCode

public int hashCode()

isRequired

public boolean isRequired()
Returns whether this field is required (should have content). Note that the MMBase core does not generally enforce required fields to be filled - If not provided, a default value (generally an empty string or the integer value -1) is filled in by the system.

Specified by:
isRequired in interface DataType
Returns:
true if the field is required

getRequiredRestriction

public DataType.Restriction getRequiredRestriction()
Returns the 'required' restriction, containing the value, errormessages, and fixed status of this attribute.

Specified by:
getRequiredRestriction in interface DataType
Returns:
the restriction as a DataType.Restriction

setRequired

public void setRequired(boolean required)
Sets whether the data type requires a value, which means that it may not remain unfilled.

Specified by:
setRequired in interface DataType
Parameters:
required - true if a value is required

isUnique

public boolean isUnique()
Returns whether this field has a unique restriction. Uniqueness is generally achieved through association of the datatype with one or more sets of fields. This is notably different from other datatype properties. Note that the MMBase core does not generally enforce uniqueness, but the storage layer might.

Specified by:
isUnique in interface DataType
Returns:
true if the field is unique

getUniqueRestriction

public DataType.Restriction getUniqueRestriction()
Returns the 'unique' restriction, containing the value, error messages, and fixed status of this attribute.

Specified by:
getUniqueRestriction in interface DataType
Returns:
the restriction as a DataType.Restriction

setUnique

public void setUnique(boolean unique)
Sets whether the data type requires a value.

Specified by:
setUnique in interface DataType
Parameters:
unique - true if a value is unique

getEnumerationValue

public Object getEnumerationValue(Locale locale,
                                  Cloud cloud,
                                  Node node,
                                  Field field,
                                  Object key)
Returns a (gui) value from a list of retsricted enumerated values, or null if no enumeration restrictions apply or teh value cannot be found.

Specified by:
getEnumerationValue in interface DataType
Parameters:
locale - for which to produce
cloud - Possibly the possible values depend on a cloud (security)
node - Possibly the possible values depend on an actual node (this may be, and in the default implementation is, ignored)
field - Possibly the possible values depend on an actual field (this may be, and in the default implementation is, ignored)
key - the key for which to look up the (gui) value

getEnumerationValues

public Iterator getEnumerationValues(Locale locale,
                                     Cloud cloud,
                                     Node node,
                                     Field field)
Returns an iterator over all possible values for this datatype, as Map.Entrys, or null if no enumeration restrictions apply. Every Map entry contains as key the 'value' for this datatype and as value it contains the description for this value in the given locale. This Iterator skips all entries which are impossible because of other restrictions on this datatype.

Specified by:
getEnumerationValues in interface DataType
Parameters:
locale - for which to produce
cloud - Possibly the possible values depend on a cloud (security)
node - Possibly the possible values depend on an actual node (this may be, and in the default implementation is, ignored)
field - Possibly the possible values depend on an actual field (this may be, and in the default implementation is, ignored)

getEnumerationFactory

public LocalizedEntryListFactory getEnumerationFactory()

Specified by:
getEnumerationFactory in interface DataType
Returns:
the LocalizedEntryListFactory which will be used to produce the result of DataType.getEnumerationValues(java.util.Locale, org.mmbase.bridge.Cloud, org.mmbase.bridge.Node, org.mmbase.bridge.Field). Never null. This can be used to add more possible values.

getEnumerationRestriction

public DataType.Restriction getEnumerationRestriction()
The enumeration for this datatype as a DataType.Restriction.

Specified by:
getEnumerationRestriction in interface DataType

getCommitProcessor

public CommitProcessor getCommitProcessor()
Specified by:
getCommitProcessor in interface DataType

setCommitProcessor

public void setCommitProcessor(CommitProcessor cp)
Specified by:
setCommitProcessor in interface DataType

getProcessor

public Processor getProcessor(int action)
Returns the default processor for this action

Specified by:
getProcessor in interface DataType
Parameters:
action - either DataType.PROCESS_GET, or DataType.PROCESS_SET XXX What exactly would be against getGetProcesor(), getSetProcessor() ?

getProcessor

public Processor getProcessor(int action,
                              int processingType)
Returns the processor for this action and processing type

Specified by:
getProcessor in interface DataType
Parameters:
action - either DataType.PROCESS_GET, or DataType.PROCESS_SET
processingType - the MMBase type defining the type of value to process

setProcessor

public void setProcessor(int action,
                         Processor processor)
Sets the processor for this action

Specified by:
setProcessor in interface DataType
Parameters:
action - either DataType.PROCESS_GET, or DataType.PROCESS_SET

setProcessor

public void setProcessor(int action,
                         Processor processor,
                         int processingType)
Sets the processor for this action

Specified by:
setProcessor in interface DataType
Parameters:
action - either DataType.PROCESS_GET, or DataType.PROCESS_SET
processingType - the MMBase type defining the type of value to process


MMBase build 1.8.1.20060716