org.mmbase.datatypes
Class DataTypes

java.lang.Object
  extended by org.mmbase.datatypes.DataTypes

public class DataTypes
extends Object

This class contains various methods for manipulating DataType objects. It contains a static set of named DataType objects, with which it is possible to craete a set of datatypes that are accessable throught the MMBase application. This set contains, at the very least, the basic datatypes (a DataType for every 'MMBase' type, i.e. integer, string, etc). There can be only one DataType in a set with a given name, so it is not possible to have multiple registered datatypes with the same name.

A number of other methods in this class deal with conversion, creating datatypes, and 'finishing' datatypes (locking a datatype to protect it form being changed).

Since:
MMBase-1.8
Version:
$Id: DataTypes.java 42265 2010-05-26 08:21:45Z michiel $
Author:
Pierre van Rooden

Nested Class Summary
static class DataTypes.FieldNotFoundException
           
 
Constructor Summary
DataTypes()
           
 
Method Summary
static DataType addFinalDataType(BasicDataType dataType)
          Add an instance of a DataType to the set of data types that are available thoughout the application.
static
<C> BasicDataType<C>
createDataType(String name, Class<C> classType)
          Create an instance of a DataType based on the class passed.
static BasicDataType getDataType(int type)
          Returns the basic DataType that matches the passed type.
static BasicDataType getDataType(String name)
          Returns a DataType from the the available set of datatypes accessible throughout the application, or null if that type does not exist.
static BasicDataType getDataTypeForFieldAttribute(String fieldAttribute)
          Get the datatype a defined for a certain field of a certain node manager, of a certain cloud context.
static BasicDataType getDataTypeInstance(String name, BasicDataType baseDataType)
          Returns a DataType instance.
static BasicDataType getDataTypeInstance(String name, int type)
          Returns a DataType instance.
static int getEnforceStrength(String enforce)
           
static ListDataType getListDataType(int listItemType)
          Returns the basic ListDataType whose item's DataType matches the passed type.
static ListDataType getListDataTypeInstance(String name, int listItemType)
          Returns a ListDataType instance.
static DataTypeCollector getSystemCollector()
           
static void initialize()
           
static void main(String[] arg)
           
static void reinitialize()
           
static Document toXml(DataType<?> dataType)
          Returns a new XML completely describing the given DataType.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataTypes

public DataTypes()
Method Detail

initialize

public static void initialize()

reinitialize

public static void reinitialize()
Since:
MMBase-1.9.2

createDataType

public static <C> BasicDataType<C> createDataType(String name,
                                                  Class<C> classType)
Create an instance of a DataType based on the class passed. The DataType returned is, if possible, a specialized DataType (such as IntegerDataType) based on the MMBase Type that most closely matches the passed class. Otherwise, it is a generic DataType specific for that class (with generally means that it only supports basic functionality such as autocast).

Parameters:
name - The name of the datatype to create. If null is passed, the class name is used.
classType - The class of the datatype to create. If null is passed, the dataType returned is based on Object.class.

addFinalDataType

public static DataType addFinalDataType(BasicDataType dataType)
Add an instance of a DataType to the set of data types that are available thoughout the application. The datatype should have a proper name, and not occur already in the set. Note that the datatype is finished when added (if it wasn't already), and can thereafter not be changed.

Parameters:
dataType - the datatype to add
Returns:
the dataType added.
Throws:
IllegalArgumentException - if the datatype does not have a name or already occurs in the set

getDataType

public static BasicDataType getDataType(String name)
Returns a DataType from the the available set of datatypes accessible throughout the application, or null if that type does not exist.

Parameters:
name - the name of the DataType to look for
Returns:
A DataType instance or null if none can be found

getDataTypeForFieldAttribute

public static BasicDataType getDataTypeForFieldAttribute(String fieldAttribute)
                                                  throws DataTypes.FieldNotFoundException
Get the datatype a defined for a certain field of a certain node manager, of a certain cloud context. It does this by parsing a string with this format: [[<uri>|]<cloud name>|]<nodemanager>|<field> The point is that the string can be used as the value for an XML attribute of the datatype tag.

Parameters:
fieldAttribute - The string describing the datatype
Throws:
DataTypes.FieldNotFoundException - If the specified field could not be found (yet).
Since:
MMBase-1.9.4

getDataTypeInstance

public static BasicDataType getDataTypeInstance(String name,
                                                BasicDataType baseDataType)
Returns a DataType instance. The system first tries to obtain a data type from the available set of datatypes accessible throughout the application. If a DataType of the passed name exists, a clone of that DataType is returned. Otherwise, a clone of the base DataType passed is returned. if the DataType with the passed name does not exist, and the value passed for the baseDataType is null, the method returns null.

Parameters:
name - the name of the DataType to look for
baseDataType - the dataType to match against. Can be null.
Returns:
A DataType instance or null if none can be instantiated

getDataTypeInstance

public static BasicDataType getDataTypeInstance(String name,
                                                int type)
Returns a DataType instance. The system first tries to obtain a type from the available set of datatypes accessible throughout the application. If a DataType of the passed name exists, a clone of that DataType is returned. Otherwise, an instance of a DataType based on the base type is returned.

Parameters:
name - the name of the DataType to look for
type - the base type to use for a default datatype instance
Returns:
A DataType instance

getListDataTypeInstance

public static ListDataType getListDataTypeInstance(String name,
                                                   int listItemType)
Returns a ListDataType instance. The system first tries to obtain a type from the available set of datatypes accessible throughout the application. If a DataType of the passed name exists, a clone of that DataType is returned. Otherwise, an instance of a ListDataType based on the list item type is returned.

Parameters:
name - the name of the DataType to look for
listItemType - the base type to use for a default listdatatype instance (this type determines the type of the list elements)
Returns:
A ListDataType instance

getDataType

public static BasicDataType getDataType(int type)
Returns the basic DataType that matches the passed type. The datatype is retrieved from the available set of datatypes accessible throughout the application. If this datatype does not (yet) exists, an instance is automatically created and added. The datatype returned by this method is only useful for matching or cloning - it cannot be changed.

Parameters:
type - the base type whose DataType to return
Returns:
the DataType instance

getListDataType

public static ListDataType getListDataType(int listItemType)
Returns the basic ListDataType whose item's DataType matches the passed type. The datatype is retrieved from the available set of datatypes accessible throughout the application. If this datatype does not (yet) exists, an instance is automatically created and added. The datatype returned by this method is only useful for matching or cloning - it cannot be changed.

Parameters:
listItemType - the base type whose ListDataType to return
Returns:
the ListDataType instance

getSystemCollector

public static DataTypeCollector getSystemCollector()

toXml

public static Document toXml(DataType<?> dataType)
Returns a new XML completely describing the given DataType. This means that the XML will not have a base attribute.


getEnforceStrength

public static int getEnforceStrength(String enforce)
Since:
MMBase-1.9.4

main

public static void main(String[] arg)
                 throws Exception
Throws:
Exception


MMBase 2.0-SNAPSHOT - null