org.mmbase.datatypes
Class DecimalDataType

java.lang.Object
  extended by org.mmbase.core.AbstractDescriptor
      extended by org.mmbase.datatypes.BasicDataType<E>
          extended by org.mmbase.datatypes.ComparableDataType<E>
              extended by org.mmbase.datatypes.NumberDataType<BigDecimal>
                  extended by org.mmbase.datatypes.DecimalDataType
All Implemented Interfaces:
Serializable, Cloneable, Comparable<DataType<BigDecimal>>, Descriptor, DataType<BigDecimal>, LengthDataType<BigDecimal>, PublicCloneable<AbstractDescriptor>

public class DecimalDataType
extends NumberDataType<BigDecimal>
implements LengthDataType<BigDecimal>

DataType associated with BigDecimal, a NumberDataType. Decimals are naturally restricted on BigDecimal.precision() and BigDecimal.scale(). The precision of a decimal can be identified with its length, because it is simply the number of stored digits. Therefore this class does, in contradication to other NumberDataTypes implement LengthDataType. getPrecision() and getMaxLength() are synonymous though. The precision and scale properties correspond with the xsd-tags xsd:precision and xsd:scale, indicating maximal values for those concepts. They can be set with dt:precision (dt:maxLength should work too) and dt:scale elements in datatypes-XML's. The rounding mode is used, and must be relaxed (since it is default RoundingMode.UNNECESSARY), if the scale restriction is not enforced. In this case the values can be rounded before validation and storage, but we need to know how precisely this must happen.

Since:
MMBase-1.9.1
Version:
$Id: DecimalDataType.java 41983 2010-04-20 15:27:34Z michiel $
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Nested Class Summary
 class DecimalDataType.PrecisionRestriction
           
 class DecimalDataType.ScaleRestriction
           
 
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
protected  AbstractLengthDataType.MinRestriction decimalMinRestriction
           
protected  DecimalDataType.PrecisionRestriction precisionRestriction
           
protected  DecimalDataType.ScaleRestriction scaleRestriction
           
 
Fields inherited from class org.mmbase.datatypes.NumberDataType
allowSpecialNumbers
 
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
DecimalDataType(String name)
           
 
Method Summary
protected  BigDecimal castString(Object preCast, Cloud cloud)
           
protected  void cloneRestrictions(BasicDataType origin)
          If a datatype is cloned, the restrictions of it (normally implemented as inner classes), must be reinstantiated.
 BigDecimal first()
          Returns a natural 'first' value.
 long getLength(Object o)
          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.
 int getPrecision()
          The maximal value for BigDecimal.precision().
 DecimalDataType.PrecisionRestriction getPrecisionRestriction()
           
 RoundingMode getRoundingMode()
           
 int getScale()
          The maximal value for BigDecimal.scale().
 DecimalDataType.ScaleRestriction getScaleRestriction()
           
protected  void inheritRestrictions(BasicDataType origin)
          If a datatype inherits from another datatype all its restrictions inherit too.
 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 setPrecision(int p)
           
 void setRoundingMode(String mode)
           
protected  Number toNumber(String s)
           
protected  Collection<LocalizedString> validateCastValue(Collection<LocalizedString> errors, Object castValue, Object value, Node node, Field field)
           
 
Methods inherited from class org.mmbase.datatypes.NumberDataType
cast, castToValidate, setAllowSpecialNumbers
 
Methods inherited from class org.mmbase.datatypes.ComparableDataType
clone, compare, getComparator, getDefaultValue, getEnforceStrength, getMaxRestriction, getMinRestriction, isMaxInclusive, isMinInclusive, setMax, setMin, toStringBuilder, toXml
 
Methods inherited from class org.mmbase.datatypes.BasicDataType
addErrorDescription, addRestriction, addRestriction, addStyleClass, cast, castAndValidate, castForSearch, castOrException, castToPresent, 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, inheritProperties, isCorrectType, isFinished, isRequired, isUnique, preCast, preCast, preCast, rewrite, setCommitProcessor, setDefaultProcessor, setDefaultValue, setDeleteProcessor, setProcessor, setProcessor, setRequired, setUnique, setXml, toString, toXml, validate, validate, validateCastValueOrNull, 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, clone, finish, getBaseType, getBaseTypeIdentifier, getCommitProcessor, getDefaultValue, getDefaultValue, getDeleteProcessor, getEnforceStrength, 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, 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

precisionRestriction

protected DecimalDataType.PrecisionRestriction precisionRestriction

decimalMinRestriction

protected AbstractLengthDataType.MinRestriction decimalMinRestriction

scaleRestriction

protected DecimalDataType.ScaleRestriction scaleRestriction
Constructor Detail

DecimalDataType

public DecimalDataType(String name)
Method Detail

getLength

public long getLength(Object o)
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<BigDecimal>

getMinLength

public long getMinLength()
Description copied from interface: LengthDataType
Returns the minimum length of values for this datatype.

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

getMinLengthRestriction

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

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

setMinLength

public void setMinLength(long value)
Description copied from interface: LengthDataType
Sets the minimum length of binary values for this datatype.

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

getMaxLength

public long getMaxLength()
Description copied from interface: LengthDataType
Returns the maximum length of values for this datatype.

Specified by:
getMaxLength in interface LengthDataType<BigDecimal>
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()
Description copied from interface: LengthDataType
Returns the 'maxLength' restriction, containing the value, errormessages, and fixed status of this attribute.

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

setMaxLength

public void setMaxLength(long value)
Description copied from interface: LengthDataType
Sets the maximum length of values for this datatype.

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

toNumber

protected Number toNumber(String s)
                   throws CastException
Overrides:
toNumber in class NumberDataType<BigDecimal>
Throws:
CastException

castString

protected BigDecimal castString(Object preCast,
                                Cloud cloud)
                         throws CastException
Overrides:
castString in class NumberDataType<BigDecimal>
Throws:
CastException

getRoundingMode

public RoundingMode getRoundingMode()

setRoundingMode

public void setRoundingMode(String mode)

setPrecision

public void setPrecision(int p)
See Also:
getPrecision()

getPrecision

public int getPrecision()
The maximal value for BigDecimal.precision().


getScale

public int getScale()
The maximal value for BigDecimal.scale().


getPrecisionRestriction

public DecimalDataType.PrecisionRestriction getPrecisionRestriction()

getScaleRestriction

public DecimalDataType.ScaleRestriction getScaleRestriction()

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<BigDecimal>

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<BigDecimal>

validateCastValue

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

first

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

Specified by:
first in class ComparableDataType<BigDecimal>


MMBase 2.0-SNAPSHOT - null