public class BasicDataType<C> extends AbstractDescriptor implements DataType<C>, Comparable<DataType<C>>, Descriptor
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.| Modifier and Type | Class and Description |
|---|---|
protected class |
BasicDataType.AbstractRestriction<D extends Serializable>
Abstract inner class Restriction.
|
protected static class |
BasicDataType.DataTypeComparator<D> |
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<D extends Serializable>
A Restriction is represented by these kind of objects.
|
protected class |
BasicDataType.TypeRestriction |
protected class |
BasicDataType.UniqueRestriction |
DataType.Restriction<D extends Serializable>| Modifier and Type | Field and Description |
|---|---|
static String |
DATATYPE_BUNDLE
The bundle used by datatype to determine default prompts for error messages when a
validation fails.
|
protected Object |
defaultValue |
protected BasicDataType.EnumerationRestriction |
enumerationRestriction |
protected BasicDataType<?> |
origin
The datatype from which this datatype originally inherited it's properties.
|
protected BasicDataType.RequiredRestriction |
requiredRestriction |
protected BasicDataType.TypeRestriction |
typeRestriction |
protected BasicDataType.UniqueRestriction |
uniqueRestriction |
description, guiName, keyENFORCE_ABSOLUTE, ENFORCE_ALWAYS, ENFORCE_NEVER, ENFORCE_ONCHANGE, ENFORCE_ONCREATE, ENFORCE_ONVALIDATE, PROCESS_GET, PROCESS_SET, VALID, XMLNS| Modifier | Constructor and Description |
|---|---|
|
BasicDataType(String name)
Create a data type object of unspecified class type
|
protected |
BasicDataType(String name,
Class<C> classType)
Create a data type object
|
| Modifier and Type | Method and Description |
|---|---|
protected Element |
addErrorDescription(Element el,
DataType.Restriction<?> r) |
protected Element |
addRestriction(Element parent,
String name,
String path,
DataType.Restriction<?> restriction) |
protected Element |
addRestriction(Element parent,
String pattern,
String name,
String path,
DataType.Restriction<?> restriction) |
void |
addStyleClass(String styleClass) |
protected C |
cast(Object value,
Cloud cloud,
Node node,
Field field)
Utility to avoid repetitive calling of getCloud
|
C |
cast(Object value,
Node node,
Field field)
Tries to 'cast' an object for use with this parameter.
|
Collection<LocalizedString> |
castAndValidate(Object value,
Node node,
Field field)
Validates a value without knowing its type yet.
|
Object |
castForSearch(Object value,
Node node,
Field field)
Sometimes the the representation of the value is a bit different in the database, or has a
different type.
|
protected String |
castToPresent(Object value,
Node node,
Field field)
If the value must be shown, e.g.
|
protected Object |
castToValidate(Object value,
Node node,
Field field)
Before validating the value, the value will be 'cast', 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.
|
BasicDataType<C> |
clone()
Returns a cloned instance of this datatype, inheriting all validation rules.
|
BasicDataType<C> |
clone(String name)
Returns a cloned instance of this datatype, inheriting all validation rules.
|
protected void |
cloneRestrictions(BasicDataType<C> origin)
If a datatype is cloned, the restrictions of it (normally implemented as inner classes), must be reinstantiated.
|
int |
compareTo(DataType<C> a) |
protected void |
edit() |
boolean |
equals(Object o)
Whether data type equals to other data type.
|
void |
finish() |
void |
finish(Object owner)
Lock a dataType so it can be changed or altered.
|
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(Cloud cloud)
Returns a cloud object if argument is
null. |
protected Cloud |
getCloud(Node node,
Field field) |
CommitProcessor |
getCommitProcessor()
Return the Commit processor of this datatype
|
Comparator<C> |
getComparator() |
Processor |
getDefaultProcessor() |
C |
getDefaultValue()
Returns the default value of this data type.
|
C |
getDefaultValue(Locale locale,
Cloud cloud,
Field field)
Returns the (locale dependent) default value of this data type,
|
CommitProcessor |
getDeleteProcessor()
Return the Delete processor of this datatype
|
protected Element |
getElement(Element parent,
String name,
String path) |
protected Element |
getElement(Element parent,
String pattern,
String name,
String path) |
int |
getEnforceStrength()
The maximum enforce strength of all restrictions on this datatype.
|
protected String |
getEnforceString(int enforce) |
LocalizedEntryListFactory<C> |
getEnumerationFactory() |
DataType.Restriction<LocalizedEntryListFactory<C>> |
getEnumerationRestriction()
The enumeration for this datatype as a
DataType.Restriction. |
String |
getEnumerationValue(Locale locale,
Cloud cloud,
Node node,
Field field,
Object key)
Returns a (gui) value from a list of restricted enumerated values, or
null if no enumeration restrictions apply or the value cannot be found. |
Iterator<Map.Entry<C,String>> |
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. |
Handler<?> |
getHandler(String mimeType)
Returns a handler for given mimetype for this DataType.
|
Map<String,Handler<?>> |
getHandlers() |
BasicDataType<?> |
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
|
Processor |
getProcessorWithoutDefault(int action,
int processingType) |
DataType.Restriction<Boolean> |
getRequiredRestriction()
Returns the 'required' restriction, containing the value, error messages, and fixed status of this attribute.
|
Collection<DataType.Restriction<?>> |
getRestrictions() |
String[] |
getStyleClasses() |
Class<C> |
getTypeAsClass()
Returns the type of values that this data type accepts.
|
DataType.Restriction<Boolean> |
getUniqueRestriction()
Returns the 'unique' restriction, containing the value, error messages, and fixed status of this attribute.
|
int |
hashCode() |
void |
inherit(BasicDataType<C> origin)
|
protected void |
inheritProperties(BasicDataType<C> origin)
Properties are members of the datatype that can easily be copied/clones.
|
protected void |
inheritRestrictions(BasicDataType<C> 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()
Is datatype locked
|
boolean |
isRequired()
Returns whether this field is required (may not be
null, or otherwise empty). |
boolean |
isUnique()
Returns whether this field has a unique restriction.
|
protected <D> D |
preCast(D value,
Cloud cloud,
Node node,
Field field)
This method implements 'precasting', which can be seen as a kind of datatype specific
casting.
|
<D> D |
preCast(D value,
Node node,
Field field)
Before actually 'cast' an object to the right type, it may undergo some conversion by the
datatype, e.g.
|
Object |
preCast(Object value,
Cloud cloud)
This method is as yet unused, but can be anticipated
|
DataType<C> |
rewrite(Object owner)
Unlock a DataType so it can be changed or altered.
|
void |
setCommitProcessor(CommitProcessor cp)
Set the Commit processor of this datatype
|
void |
setDefaultProcessor(Processor dp) |
void |
setDefaultValue(Object def)
Set the default value for this DataType
|
void |
setDeleteProcessor(CommitProcessor cp) |
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 StringBuilder |
toStringBuilder() |
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
DataType.getOrigin(), to make one
XML, fully describing the DataType). |
Collection<LocalizedString> |
validate(C value) |
Collection<LocalizedString> |
validate(C value,
Node node,
Field field)
Checks if the passed object obeys the restrictions defined for this type.
|
protected Collection<LocalizedString> |
validateCastValue(Collection<LocalizedString> errors,
Object castValue,
Object value,
Node node,
Field field) |
protected Collection<LocalizedString> |
validateCastValueOrNull(Collection<LocalizedString> errors,
Object castValue,
Object value,
Node node,
Field field) |
protected Collection<LocalizedString> |
validateRequired(Collection<LocalizedString> errors,
Object castValue,
Object value,
Node node,
Field field) |
protected void |
xmlValue(Element el,
Object value) |
getDefaultLocale, getDescription, getDescription, getGUIName, getGUIName, getLocalizedDescription, getLocalizedGUIName, getName, setDescription, setDescription, setGUIName, setGUIName, setLocalizedDescription, setLocalizedGUINamefinalize, getClass, notify, notifyAll, wait, wait, waitgetDescription, getDescription, getGUIName, getGUIName, getLocalizedDescription, getLocalizedGUIName, getName, setDescription, setDescription, setGUIName, setGUINamepublic static final String DATATYPE_BUNDLE
protected BasicDataType.RequiredRestriction requiredRestriction
protected BasicDataType.UniqueRestriction uniqueRestriction
protected BasicDataType.TypeRestriction typeRestriction
protected BasicDataType.EnumerationRestriction enumerationRestriction
protected BasicDataType<?> origin
protected Object defaultValue
public BasicDataType(String name)
name - the name of the data typespublic String getBaseTypeIdentifier()
DataTypegetBaseTypeIdentifier in interface DataType<C>public int getBaseType()
DataTypegetBaseType in interface DataType<C>Field.getType()public final void inherit(BasicDataType<C> origin)
inheritProperties(org.mmbase.datatypes.BasicDataType<C>) and inheritRestrictions(org.mmbase.datatypes.BasicDataType<C>).origin - inherit properties and restrictions from this DataTypeprotected void inheritProperties(BasicDataType<C> origin)
protected void cloneRestrictions(BasicDataType<C> origin)
protected void inheritRestrictions(BasicDataType<C> origin)
public BasicDataType<?> getOrigin()
nullpublic Class<C> getTypeAsClass()
getTypeAsClass in interface DataType<C>protected boolean isCorrectType(Object value)
value - teh value whose type (class) to checkIllegalArgumentException - if the type is not compatiblepublic void checkType(Object value)
public final <D> D preCast(D value,
Node node,
Field field)
Casting.toType(Class, 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).public final Object preCast(Object value, Cloud cloud)
protected <D> D preCast(D value,
Cloud cloud,
Node node,
Field field)
null. It should not
change the actual type of the value.public final C cast(Object value, Node node, Field field)
cast(Object, Cloud, Node, Field)protected C cast(Object value, Cloud cloud, Node node, Field field) throws CastException
CastExceptionprotected Cloud getCloud(Cloud cloud)
null. Otherwise the argument.protected Object castToValidate(Object value, Node node, Field field) throws CastException
CastExceptionprotected String castToPresent(Object value, Node node, Field field)
public final C getDefaultValue()
getDefaultValue in interface DataType<C>public C getDefaultValue(Locale locale, Cloud cloud, Field field)
getDefaultValue in interface DataType<C>public void setDefaultValue(Object def)
setDefaultValue in interface DataType<C>def - default valueprotected String getEnforceString(int enforce)
protected Element addRestriction(Element parent, String name, String path, DataType.Restriction<?> restriction)
protected Element addRestriction(Element parent, String pattern, String name, String path, DataType.Restriction<?> restriction)
protected Element addErrorDescription(Element el, DataType.Restriction<?> r)
public boolean isFinished()
DataTypeisFinished in interface DataType<C>true when datatype is lockedpublic void finish()
finish()public void finish(Object owner)
protected void edit()
public final Collection<LocalizedString> validate(C value)
validate in interface DataType<C>value - the value to be validatedDataType.validate(Object, Node, Field)public final Collection<LocalizedString> validate(C value, Node node, Field field)
DataTypevalidate in interface DataType<C>value - the value to validatenode - 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.DataType.VALID)if the value is valid.public final Collection<LocalizedString> castAndValidate(Object value, Node node, Field field)
DataTypecastAndValidate in interface DataType<C>public int getEnforceStrength()
DataTypeDataType.ENFORCE_ALWAYS, DataType.ENFORCE_ONCHANGE, DataType.ENFORCE_NEVER.getEnforceStrength in interface DataType<C>protected Collection<LocalizedString> validateCastValue(Collection<LocalizedString> errors, Object castValue, Object value, Node node, Field field)
protected Collection<LocalizedString> validateCastValueOrNull(Collection<LocalizedString> errors, Object castValue, Object value, Node node, Field field)
protected Collection<LocalizedString> validateRequired(Collection<LocalizedString> errors, Object castValue, Object value, Node node, Field field)
public Object castForSearch(Object value, Node node, Field field)
DataTypeDataType.cast(Object, Node, Field).castForSearch in interface DataType<C>protected StringBuilder toStringBuilder()
public final String toString()
toString in class AbstractDescriptorpublic final BasicDataType<C> clone()
clone(String) in stead.clone in interface DataType<C>clone in interface PublicCloneable<AbstractDescriptor>clone in class AbstractDescriptorpublic BasicDataType<C> clone(String name)
inheritProperties(BasicDataType) and cloneRestrictions(BasicDataType). A clone is not finished. See isFinished().clone in interface DataType<C>clone in class AbstractDescriptorname - the new name of the copied datatype (can be null, in which case the name is not changed).public Element toXml()
DataTypepublic void setXml(Element element)
public void toXml(Element parent)
DataTypeDataType.getOrigin(), to make one
XML, fully describing the DataType). The implementation of this method is
unfinished!public Handler<?> getHandler(String mimeType)
DataTypegetHandler in interface DataType<C>public Map<String,Handler<?>> getHandlers()
getHandlers in interface DataType<C>public Collection<DataType.Restriction<?>> getRestrictions()
public int compareTo(DataType<C> a)
compareTo in interface Comparable<DataType<C>>public boolean equals(Object o)
public boolean isRequired()
null, or otherwise empty).isRequired in interface DataType<C>true if the field is requiredpublic DataType.Restriction<Boolean> getRequiredRestriction()
getRequiredRestriction in interface DataType<C>DataType.Restrictionpublic void setRequired(boolean required)
setRequired in interface DataType<C>required - true if a value is requiredpublic boolean isUnique()
public DataType.Restriction<Boolean> getUniqueRestriction()
getUniqueRestriction in interface DataType<C>DataType.Restrictionpublic void setUnique(boolean unique)
public String getEnumerationValue(Locale locale, Cloud cloud, Node node, Field field, Object key)
null if no enumeration restrictions apply or the value cannot be found.getEnumerationValue in interface DataType<C>locale - for which to producecloud - 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) valuepublic Iterator<Map.Entry<C,String>> getEnumerationValues(Locale locale, Cloud cloud, Node node, Field field)
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.getEnumerationValues in interface DataType<C>locale - for which to producecloud - 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)public LocalizedEntryListFactory<C> getEnumerationFactory()
getEnumerationFactory in interface DataType<C>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.public DataType.Restriction<LocalizedEntryListFactory<C>> getEnumerationRestriction()
DataType.Restriction.getEnumerationRestriction in interface DataType<C>public Processor getDefaultProcessor()
public void setDefaultProcessor(Processor dp)
public CommitProcessor getCommitProcessor()
DataTypegetCommitProcessor in interface DataType<C>public void setCommitProcessor(CommitProcessor cp)
DataTypesetCommitProcessor in interface DataType<C>cp - Commit processorpublic CommitProcessor getDeleteProcessor()
DataTypegetDeleteProcessor in interface DataType<C>public void setDeleteProcessor(CommitProcessor cp)
public Processor getProcessor(int action)
getProcessor in interface DataType<C>action - either DataType.PROCESS_GET, or DataType.PROCESS_SET
XXX What exactly would be against getGetProcesor(), getSetProcessor() ?public Processor getProcessor(int action, int processingType)
getProcessor in interface DataType<C>action - either DataType.PROCESS_GET, or DataType.PROCESS_SETprocessingType - the MMBase type defining the type of value to processpublic Processor getProcessorWithoutDefault(int action, int processingType)
public void setProcessor(int action,
Processor processor)
setProcessor in interface DataType<C>action - either DataType.PROCESS_GET, or DataType.PROCESS_SETprocessor - the processor for this actionpublic void setProcessor(int action,
Processor processor,
int processingType)
setProcessor in interface DataType<C>action - either DataType.PROCESS_GET, or DataType.PROCESS_SETprocessor - the processor for this action and processing typeprocessingType - the MMBase type defining the type of value to processpublic String[] getStyleClasses()
getStyleClasses in interface DataType<C>public void addStyleClass(String styleClass)
public Comparator<C> getComparator()
MMBase 1.9-SNAPSHOT - ${javadoctimestamp}