org.mmbase.datatypes
Class StringDataType

java.lang.Object
  extended by org.mmbase.core.AbstractDescriptor
      extended by org.mmbase.datatypes.BasicDataType<E>
          extended by org.mmbase.datatypes.ComparableDataType<String>
              extended by org.mmbase.datatypes.StringDataType
All Implemented Interfaces:
Serializable, Cloneable, Comparable<DataType<String>>, Descriptor, DataType<String>, LengthDataType<String>, PublicCloneable<AbstractDescriptor>
Direct Known Subclasses:
BinaryStringDataType, CaptchaDataType, CheckEqualityDataType, ComponentNamesDataType, InternetAddressDataType, LanguageDataType, NodeManagerNamesDataType, SecurityContextDataType, Setting.DataType, UniqueStringDataType

public class StringDataType
extends ComparableDataType<String>
implements LengthDataType<String>

The datatype for String fields. Strings can be constrained by a regular expression, and have a property 'password' which indicates that the contents should not be shown.

Since:
MMBase-1.8
Version:
$Id: StringDataType.java 41987 2010-04-20 16:14:35Z michiel $
Author:
Pierre van Rooden, Michiel Meeuwissen
See Also:
Serialized Form

Nested Class Summary
protected  class StringDataType.PatternRestriction
           
 
Nested classes/interfaces inherited from class org.mmbase.datatypes.ComparableDataType
ComparableDataType.MaxRestriction, ComparableDataType.MinRestriction
 
Nested classes/interfaces inherited from class org.mmbase.datatypes.BasicDataType
BasicDataType.AbstractRestriction<D extends Serializable>, BasicDataType.DataTypeComparator<D>, BasicDataType.EnumerationRestriction, BasicDataType.RequiredRestriction, BasicDataType.RestrictedEnumerationIterator, BasicDataType.StaticAbstractRestriction<D extends Serializable>, BasicDataType.TypeRestriction, BasicDataType.UniqueRestriction
 
Nested classes/interfaces inherited from interface org.mmbase.datatypes.DataType
DataType.Restriction<D extends Serializable>
 
Field Summary
static Pattern BOOLEAN_PATTERN
           
static Pattern DOUBLE_PATTERN
           
static Pattern INTEGER_PATTERN
           
static Pattern LONG_PATTERN
           
protected  AbstractLengthDataType.MaxRestriction maxLengthRestriction
           
protected  AbstractLengthDataType.MinRestriction minLengthRestriction
           
static Pattern NON_NEGATIVE_INTEGER_PATTERN
           
protected  StringDataType.PatternRestriction patternRestriction
           
 
Fields inherited from class org.mmbase.datatypes.ComparableDataType
maxRestriction, minRestriction
 
Fields inherited from class org.mmbase.datatypes.BasicDataType
DATATYPE_BUNDLE, defaultValue, enumerationRestriction, origin, requiredRestriction, typeRestriction, 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, ENFORCE_ONVALIDATE, PROCESS_GET, PROCESS_SET, VALID, XMLNS
 
Constructor Summary
StringDataType(String name)
          Constructor for string data type.
 
Method Summary
protected  String castForPattern(Object v, Node node, Field field)
           
 StringDataType clone(String name)
          Returns a cloned instance of this datatype, inheriting all validation rules.
protected  void cloneRestrictions(BasicDataType origin)
          If a datatype is cloned, the restrictions of it (normally implemented as inner classes), must be reinstantiated.
protected  int compare(String comp1, String comp2)
           
 String first()
          Returns a natural 'first' value.
 Collator getCollator()
          Returns the Collator associated with string with this datatype.
 Comparator<String> getComparator()
           
 int getEnforceStrength()
          The maximum enforce strength of all restrictions on this datatype.
 long getLength(Object value)
          In this method should be implemented how to calculate such a length for a certain value of this datatype.
 long getMaxLength()
          Returns the maximum length of values for this datatype.
 DataType.Restriction<Long> getMaxLengthRestriction()
          Returns the 'maxLength' restriction, containing the value, errormessages, and fixed status of this attribute.
 long getMinLength()
          Returns the minimum length of values for this datatype.
 DataType.Restriction<Long> getMinLengthRestriction()
          Returns the 'minLength' restriction, containing the value, errormessages, and fixed status of this attribute.
 Pattern getPattern()
          Returns the regular expression pattern used to validate values for this datatype.
 DataType.Restriction getPatternRestriction()
          Returns the 'pattern' restriction, containing the value, error messages, and fixed status of this attribute.
protected  void inheritProperties(BasicDataType<String> 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.
 boolean isPassword()
          Whether or not the data represents sensitive information, in which case e.g.
static void main(String[] argv)
           
 void setCollator(Collator col)
           
 void setMaxLength(long value)
          Sets the maximum length of values for this datatype.
 void setMinLength(long value)
          Sets the minimum length of binary values for this datatype.
 void setPassword(boolean pw)
           
 void setPattern(Pattern value)
          Sets the regular expression pattern used to validate values for this datatype.
protected  StringBuilder toStringBuilder()
           
 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).
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)
           
 
Methods inherited from class org.mmbase.datatypes.ComparableDataType
getDefaultValue, getMaxRestriction, getMinRestriction, isMaxInclusive, isMinInclusive, setMax, setMin
 
Methods inherited from class org.mmbase.datatypes.BasicDataType
addErrorDescription, addRestriction, addRestriction, addStyleClass, cast, cast, castAndValidate, castForSearch, castOrException, castToPresent, castToValidate, checkType, clone, compareTo, edit, equals, finish, finish, getBaseType, getBaseTypeIdentifier, getCloud, getCloud, getCommitProcessor, getDefaultProcessor, getDefaultValue, getDeleteProcessor, getElement, getElement, getEnforceString, getEnumerationFactory, getEnumerationRestriction, getEnumerationValue, getEnumerationValues, getHandler, getHandlers, getOrigin, getProcessor, getProcessor, getProcessorWithoutDefault, getRequiredRestriction, getRestrictions, getStyleClasses, getTypeAsClass, getUniqueRestriction, hashCode, inherit, isCorrectType, isFinished, isRequired, isUnique, preCast, preCast, preCast, rewrite, setCommitProcessor, setDefaultProcessor, setDefaultValue, setDeleteProcessor, setProcessor, setProcessor, setRequired, setUnique, setXml, toString, toXml, validate, validate, validateRequired, xmlValue
 
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.datatypes.DataType
cast, castAndValidate, castForSearch, castOrException, checkType, clone, finish, getBaseType, getBaseTypeIdentifier, getCommitProcessor, getDefaultValue, getDefaultValue, getDeleteProcessor, getEnumerationFactory, getEnumerationRestriction, getEnumerationValue, getEnumerationValues, getHandler, getHandlers, getOrigin, getProcessor, getProcessor, getRequiredRestriction, getStyleClasses, getTypeAsClass, getUniqueRestriction, isFinished, isRequired, isUnique, preCast, rewrite, setCommitProcessor, setDefaultValue, setProcessor, setProcessor, setRequired, setUnique, toXml, validate, validate
 
Methods inherited from interface org.mmbase.bridge.Descriptor
getDescription, getDescription, getGUIName, getGUIName, getLocalizedDescription, getLocalizedGUIName, getName, setDescription, setDescription, setGUIName, setGUIName
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

patternRestriction

protected StringDataType.PatternRestriction patternRestriction

minLengthRestriction

protected AbstractLengthDataType.MinRestriction minLengthRestriction

maxLengthRestriction

protected AbstractLengthDataType.MaxRestriction maxLengthRestriction

DOUBLE_PATTERN

public static final Pattern DOUBLE_PATTERN

BOOLEAN_PATTERN

public static final Pattern BOOLEAN_PATTERN

INTEGER_PATTERN

public static final Pattern INTEGER_PATTERN

NON_NEGATIVE_INTEGER_PATTERN

public static final Pattern NON_NEGATIVE_INTEGER_PATTERN

LONG_PATTERN

public static final Pattern LONG_PATTERN
Constructor Detail

StringDataType

public StringDataType(String name)
Constructor for string data type.

Parameters:
name - the name of the data type
Method Detail

inheritProperties

protected void inheritProperties(BasicDataType<String> origin)
Description copied from class: BasicDataType
Properties are members of the datatype that can easily be copied/clones.

Overrides:
inheritProperties in class BasicDataType<String>

inheritRestrictions

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

Overrides:
inheritRestrictions in class ComparableDataType<String>

cloneRestrictions

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

Overrides:
cloneRestrictions in class ComparableDataType<String>

compare

protected int compare(String comp1,
                      String comp2)
Overrides:
compare in class ComparableDataType<String>

getLength

public long getLength(Object value)
Description copied from interface: LengthDataType
In this method should be implemented how to calculate such a length for a certain value of this datatype. There does not exist a generic interface for this, so the implementation will cast to the expected type (String, byte[]..)

Specified by:
getLength in interface LengthDataType<String>

getMinLength

public long getMinLength()
Returns the minimum length of values for this datatype.

Specified by:
getMinLength in interface LengthDataType<String>
Returns:
the minimum length as an int, or 0 if there is no minimum length.

getMinLengthRestriction

public DataType.Restriction<Long> getMinLengthRestriction()
Returns the 'minLength' restriction, containing the value, errormessages, and fixed status of this attribute.

Specified by:
getMinLengthRestriction in interface LengthDataType<String>
Returns:
the restriction as a DataType.Restriction

setMinLength

public void setMinLength(long value)
Sets the minimum length of binary values for this datatype.

Specified by:
setMinLength in interface LengthDataType<String>
Parameters:
value - the minimum length as an long, or 0 if there is no minimum length.

getMaxLength

public long getMaxLength()
Returns the maximum length of values for this datatype.

Specified by:
getMaxLength in interface LengthDataType<String>
Returns:
the maximum length as an long, or a very very big value (Long.MAX_VALUE) if there is no maximum length.

getMaxLengthRestriction

public DataType.Restriction<Long> getMaxLengthRestriction()
Returns the 'maxLength' restriction, containing the value, errormessages, and fixed status of this attribute.

Specified by:
getMaxLengthRestriction in interface LengthDataType<String>
Returns:
the restriction as a DataType.Restriction

setMaxLength

public void setMaxLength(long value)
Sets the maximum length of values for this datatype.

Specified by:
setMaxLength in interface LengthDataType<String>
Parameters:
value - see LengthDataType.getMaxLength()

getPattern

public Pattern getPattern()
Returns the regular expression pattern used to validate values for this datatype.

Returns:
the pattern.

getPatternRestriction

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

Returns:
the restriction as a DataType.Restriction

setPattern

public void setPattern(Pattern value)
Sets the regular expression pattern used to validate values for this datatype.

Parameters:
value - the pattern as a Pattern, or null if no pattern should be applied.
Throws:
UnsupportedOperationException - if this datatype is read-only (i.e. defined by MMBase)

isPassword

public boolean isPassword()
Whether or not the data represents sensitive information, in which case e.g. an input interface may present asterisks in stead of letters.


setPassword

public void setPassword(boolean pw)

setCollator

public void setCollator(Collator col)
Since:
MMBase-1.9.2

getCollator

public Collator getCollator()
Returns the Collator associated with string with this datatype. Collators define how strings should be compared and sorted. This can be language dependent. The DataType XML configuration uses LocaleCollator.getInstance(String) to parse the string present in datatype XML's to a Collator.

Since:
MMBase-1.9.2

getComparator

public Comparator<String> getComparator()
Overrides:
getComparator in class ComparableDataType<String>
Since:
MMBase-1.9.2

first

public String first()
Description copied from class: ComparableDataType
Returns a natural 'first' value. This may return some kind of 0

Specified by:
first in class ComparableDataType<String>

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<String>
Overrides:
toXml in class ComparableDataType<String>
Parameters:
parent - a 'datatype' element.

getEnforceStrength

public int getEnforceStrength()
Description copied from interface: DataType
The maximum enforce strength of all restrictions on this datatype. See DataType.ENFORCE_ALWAYS, DataType.ENFORCE_ONCHANGE, DataType.ENFORCE_NEVER.

Specified by:
getEnforceStrength in interface DataType<String>
Overrides:
getEnforceStrength in class ComparableDataType<String>
Returns:
maximum enforce strength

validateCastValueOrNull

protected Collection<LocalizedString> validateCastValueOrNull(Collection<LocalizedString> errors,
                                                              Object castValue,
                                                              Object value,
                                                              Node node,
                                                              Field field)
Overrides:
validateCastValueOrNull in class BasicDataType<String>

validateCastValue

protected Collection<LocalizedString> validateCastValue(Collection<LocalizedString> errors,
                                                        Object castValue,
                                                        Object value,
                                                        Node node,
                                                        Field field)
Overrides:
validateCastValue in class ComparableDataType<String>

toStringBuilder

protected StringBuilder toStringBuilder()
Overrides:
toStringBuilder in class ComparableDataType<String>

castForPattern

protected String castForPattern(Object v,
                                Node node,
                                Field field)
Since:
MMBase-1.9.1

clone

public StringDataType clone(String name)
Description copied from class: BasicDataType
Returns a cloned instance of this datatype, inheriting all validation rules. Similar to calling clone(), but changes the data type name if one is provided. Besides super.clone, it calls BasicDataType.inheritProperties(BasicDataType) and BasicDataType.cloneRestrictions(BasicDataType). A clone is not finished. See BasicDataType.isFinished().

Specified by:
clone in interface DataType<String>
Overrides:
clone in class ComparableDataType<String>
Parameters:
name - the new name of the copied datatype (can be null, in which case the name is not changed).
Returns:
cloned DataType

main

public static void main(String[] argv)


MMBase 2.0-SNAPSHOT - null