org.mmbase.datatypes
Class DataTypeCollector

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

public final class DataTypeCollector
extends Object

A DataTypeCollector is a collection of named DataTypes. So, you can add and request DataType objects from this by a String. It also facilitates 'chaining' because you can add other DataTypeCollectors to it. It will delegate searching of a datatype to them, if a certain key is not available.
This object also knowns how to 'lock' its DataType's using it's 'signature'. I have no idea where that is good for.

Since:
MMBase-1.8
Version:
$Id: DataTypeCollector.java 41987 2010-04-20 16:14:35Z michiel $
Author:
Pierre van Rooden

Field Summary
(package private) static DataTypeCollector systemDataTypeCollector
           
 
Constructor Summary
DataTypeCollector(Object signature)
           
 
Method Summary
 void addCollector(DataTypeCollector collector)
          Adds a datatype collector on which this collector depends.
 BasicDataType<?> addDataType(BasicDataType<?> dataType)
          Adds a datatype to this collector.
(package private)  void clear()
           
 boolean contains(DataType<?> dataType)
          Returns whether the dataType is part of the current collection.
 boolean contains(String name)
          Returns whether the dataType with the given name is part of the current collection.
(package private) static DataTypeCollector createSystemDataTypeCollector()
          Creates the DataTypeCollector used to store datatypes accessible throughout the application.
 void finish(DataType<?> dataType)
          Lock a dataType so it can be changed or altered.
 Iterator<DataType<?>> getAllSpecializations(String name)
          Recursively calls getSpecializations(String) so that you can easily iterate also all indirectly specializaed versions of a certain DataType in this collector
 BasicDataType<?> getDataType(String name)
          Get a datatype defined for this collector.
 BasicDataType<?> getDataType(String name, boolean recursive)
          Get a datatype defined for this collector, and possibly any collectors it depends on.
 DataTypeDefinition getDataTypeDefinition()
           
 BasicDataType<?> getDataTypeInstance(String name, DataType<?> baseDataType)
          Get a datatype instance through this collector.
 Map<String,BasicDataType<?>> getDataTypes()
          Set local datatypes of the collector
 Set<DataType<?>> getRoots()
          Returns all DataTypes in this Collector which did not have an origina DataType (in this Collector).
 Collection<DataType<?>> getSpecializations(String name)
          Returns a set of all DataTypes in this collector which are directly inherited from the one with given name
 void rewrite(DataType<?> dataType)
          Unlock a dataType so it can be changed or altered.
 void setDataTypes(Map<String,BasicDataType<?>> dataTypes)
          Set local datatypes of the collector
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

systemDataTypeCollector

static DataTypeCollector systemDataTypeCollector
Constructor Detail

DataTypeCollector

public DataTypeCollector(Object signature)
Parameters:
signature - the object used to finish a data type for this collector.
Method Detail

createSystemDataTypeCollector

static DataTypeCollector createSystemDataTypeCollector()
Creates the DataTypeCollector used to store datatypes accessible throughout the application. Called by the DataTypes class.


getDataTypeDefinition

public DataTypeDefinition getDataTypeDefinition()

addCollector

public void addCollector(DataTypeCollector collector)
Adds a datatype collector on which this collector depends. when trying to obtain a datatype or datatype instance, if the current collector does not contain the datatype, it tries to obtain it from any colelctors it depends on.

Parameters:
collector - the dataType collector to add

setDataTypes

public void setDataTypes(Map<String,BasicDataType<?>> dataTypes)
Set local datatypes of the collector

Parameters:
dataTypes - a Map containing the datatypes

getDataTypes

public Map<String,BasicDataType<?>> getDataTypes()
Set local datatypes of the collector


getDataType

public BasicDataType<?> getDataType(String name)
Get a datatype defined for this collector.

Parameters:
name - the name of the datatype to retrieve
Returns:
a DataType with the given name, as defined for this collector, or null if no datatype is defined.

addDataType

public BasicDataType<?> addDataType(BasicDataType<?> dataType)
Adds a datatype to this collector. The datatype should have a unique id. If it has no id (i.e. getName() returns an empty string), it is not added. If the datatype overrides an existing datatype, a warning is logged.

Parameters:
dataType - the datatype to add
Returns:
if applicable, the old (original) datatype with the same id as the dattype that was being added, null if it is not applicable.

getSpecializations

public Collection<DataType<?>> getSpecializations(String name)
Returns a set of all DataTypes in this collector which are directly inherited from the one with given name


getAllSpecializations

public Iterator<DataType<?>> getAllSpecializations(String name)
Recursively calls getSpecializations(String) so that you can easily iterate also all indirectly specializaed versions of a certain DataType in this collector


getRoots

public Set<DataType<?>> getRoots()
Returns all DataTypes in this Collector which did not have an origina DataType (in this Collector).


getDataType

public BasicDataType<?> getDataType(String name,
                                    boolean recursive)
Get a datatype defined for this collector, and possibly any collectors it depends on. The collector first searches among datatypes defined in its own set. If that fails, it tries ot get it from any of the other collectors it may depend on, and eventually from the main repository.

Parameters:
name - the name of the datatype to retrieve
recursive - if true, the datatype is also searched in collectors it depends on.
Returns:
a DataType with the given name, as defined for this collector, or null if no datatype is defined.

getDataTypeInstance

public BasicDataType<?> getDataTypeInstance(String name,
                                            DataType<?> baseDataType)
Get a datatype instance through this collector. The collector first searches among datatypes defined in its own set. If that fails, it tries to get it from any of the other collectors it may depend on, and eventually from the main repository. If that fails too, it creates one itself based on the passed base datatype (if given).

Parameters:
name - the name of the datatype to retrieve
baseDataType - the datatype to base a new datatype on if it is not yet defined. Can be null.
Returns:
a DataType with the given name, as defined for this collector, or null if no datatype is defined and no base datatype was passed.

contains

public boolean contains(String name)
Returns whether the dataType with the given name is part of the current collection.


contains

public boolean contains(DataType<?> dataType)
Returns whether the dataType is part of the current collection.


rewrite

public void rewrite(DataType<?> dataType)
Unlock a dataType so it can be changed or altered. This will likely fail if the datatype is not part of this collector.


finish

public void finish(DataType<?> dataType)
Lock a dataType so it can be changed or altered. This will likely fail if the datatype is not part of this collector.


clear

void clear()

toString

public String toString()
Overrides:
toString in class Object


MMBase 2.0-SNAPSHOT - null