org.mmbase.datatypes
Class DataTypeCollector

java.lang.Object
  extended byorg.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,v 1.11 2006/04/04 22:54:16 michiel Exp $
Author:
Pierre van Rooden

Constructor Summary
DataTypeCollector(Object signature)
          Constructor.
 
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.
 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.
 void finish(DataType dataType)
          Lock a dataType so it can be changed or latered.
 Iterator 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, BasicDataType baseDataType)
          Get a datatype instance through this collector.
 Map getDataTypes()
          Set local datatypes of the collector
 Set getRoots()
          Returns all DataTypes in this Collector which did not have an origina DataType (in this Collector).
 Collection 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 latered.
 void setDataTypes(Map 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
 

Constructor Detail

DataTypeCollector

public DataTypeCollector(Object signature)
Constructor.

Parameters:
signature - the object used to finish a data type for this collector.
Method Detail

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 dataTypes)
Set local datatypes of the collector

Parameters:
dataTypes - a Map containing the datatypes

getDataTypes

public Map 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 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 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 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,
                                         BasicDataType 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 latered. 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 latered. This will likely fail if the datatype is not part of this collector.


toString

public String toString()


MMBase build 1.8.1.20060716