com.davisor.data
Class FormatType

java.lang.Object
  extended byjava.text.Format
      extended bycom.davisor.data.Type
          extended bycom.davisor.data.LocaleType
              extended bycom.davisor.data.FormatType
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator, com.davisor.core.Dupable, java.io.Serializable
Direct Known Subclasses:
DateFormatType, SimpleNumberType, TupleType

public abstract class FormatType
extends LocaleType

FormatType implements an abstract base class for types that wish to use Java Format objects to format and parse strings. This class manages a format object, a format pattern, and a format sample object.

Format object is an instance of standard java.text.Format class that provides interface for formatting and parsing object and string values. Both standard and custom formats may be used, as appropriate to each subclass.

Format pattern is some string that somehow describes the details of the desired formatting and parsing rules. The interpretation of the pattern string depends on subclass and format object implementations.

Format sample is any generic object subclasses may want to use to further describe the details of formatting and parsing. In particular, the sample may provide a context in which the operation is to occur. A represnetative example would be a number format that leaves the desired number unit scale unspecified. With a sample of number value magnitude, a formatter can later produce numbers scaled appropriately for a context the formatter results will be used in.

Format locale management is done by super-class, and format object constructing by sub-classes. In particular, sub-classes are expected to define the createFormatter() method. All methods that modify any format related parameters must then call the createFormatter() method to produce a corresponding format object.

A missing locale indicates system default locale formatting. A missing pattern indicates locale spesific default formatting.

Since:
JDK1.1
See Also:
createFormatter(), Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
protected  java.lang.String M_pattern
          Format pattern (may be null).
protected  java.lang.Object M_sample
          Format sample (may be null).
 
Fields inherited from class com.davisor.data.LocaleType
DEFAULT_LOCALE, M_locale
 
Fields inherited from class com.davisor.data.Type
METADATA_GROUP, METADATA_NAME, METADATA_PARENT, METADATA_SUBCHANNELS, TYPENAME
 
Constructor Summary
protected FormatType(FormatType ft)
          Deep copy constructor.
protected FormatType(java.lang.String typeName, java.lang.String dataName, java.lang.String id, java.util.Map metaData, java.util.Locale locale, java.lang.String pattern, java.lang.Object sample)
          Creates a new format type.
 
Method Summary
 void clearFormatter()
          Clears the current format, if any.
protected abstract  java.text.Format createFormatter()
          Creates a new format instance suitable for the purposes of this class.
 boolean equals(java.lang.Object o)
          Tests if this object is equal with another object.
 java.lang.String getFormat()
          Gets the format specification string.
 java.text.Format getFormatter()
          Gets a reference to the current format instance.
 java.lang.String getPattern()
          Gets the current format pattern.
 java.lang.Object getSample()
          Gets the current format sample.
 java.lang.Class getValueClass()
          Gets value container class.
 int hashCode()
          Returns a hash code value for the object.
 void setFormat(java.util.Locale locale, java.lang.String pattern)
          Sets the current format from given locale and format pattern.
 void setFormat(java.lang.String format)
          Sets the format type specification string.
 void setLocale(java.util.Locale locale)
          Sets the current format with locale.
 void setPattern(java.lang.String pattern)
          Sets the current format with a format pattern.
 void setSample(java.lang.Object sample)
          Sets the current format with a format sample.
 
Methods inherited from class com.davisor.data.LocaleType
getLocale, setLocale
 
Methods inherited from class com.davisor.data.Type
ceil, check, check, compare, create, create, create, create, create, dup, dup, floor, format, getCompatibility, getDataName, getId, getID, getMetaData, getMetaData, getSpecs, getSQLCode, getSQLName, getSQLName, getTypeName, isNull, parseObject, register, register, setDataName, setId, setID, setMetaData, setMetaData, setSpecs, toData, toData, toData, toData, toString, toXML, xmlEnd, xmlStart, zero
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

M_pattern

protected java.lang.String M_pattern
Format pattern (may be null).


M_sample

protected java.lang.Object M_sample
Format sample (may be null).

Constructor Detail

FormatType

protected FormatType(FormatType ft)
Deep copy constructor. The format object is cloned from given format type, is possible. If not, the format object will be initially set to null value.

See Also:
getFormatter()

FormatType

protected FormatType(java.lang.String typeName,
                     java.lang.String dataName,
                     java.lang.String id,
                     java.util.Map metaData,
                     java.util.Locale locale,
                     java.lang.String pattern,
                     java.lang.Object sample)
Creates a new format type. The underlying format will be initially set to null value.

Parameters:
typeName - type name
dataName - data name
id - type identity
metaData - type meta data map (may be null)
locale - type locale (may be null)
pattern - format pattern (may be null)
sample - format sample (may be null)
See Also:
getFormatter(), setLocale(java.util.Locale), setPattern(java.lang.String), setSample(java.lang.Object)
Method Detail

setLocale

public void setLocale(java.util.Locale locale)
Sets the current format with locale.

After setting the locale, this method clears the current format with a call to clearFormatter().

Overrides:
setLocale in class LocaleType
Parameters:
locale - new locale (may be null)
See Also:
createFormatter(), setFormat(Locale,String), setPattern(java.lang.String), LocaleType.setLocale(java.util.Locale)

equals

public boolean equals(java.lang.Object o)
Tests if this object is equal with another object.

Format types are equal if their super-classes and patterns are.

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class LocaleType
See Also:
Compare.equals(Object,Object)

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class LocaleType
See Also:
Compare.hashCode(java.lang.Object)

createFormatter

protected abstract java.text.Format createFormatter()
Creates a new format instance suitable for the purposes of this class.

See Also:
clearFormatter(), getFormatter(), setFormat(Locale,String), setLocale(Locale), setPattern(String)

clearFormatter

public void clearFormatter()
Clears the current format, if any. This will cause getFormatter() to call createFormatter() next time getFormatter() is invoked.

See Also:
createFormatter(), getFormatter()

getFormatter

public java.text.Format getFormatter()
Gets a reference to the current format instance. If the format is currently null, an attempt to create a new format is made by calling the createFormatter() method. The result is then stored and returned.

Depending on sub-class implementation, the result may also be null, in which case the format remains null, and null is also returned. This means also that next the this method is called, a new attempt to creat the format is made again.

Returns:
current format instance (may be null)
See Also:
clearFormatter(), LocaleType.getLocale(), getPattern(), getSample()

getPattern

public java.lang.String getPattern()
Gets the current format pattern.

See Also:
getFormatter(), LocaleType.getLocale(), getSample(), setPattern(java.lang.String)

getSample

public java.lang.Object getSample()
Gets the current format sample.

See Also:
getFormatter(), LocaleType.getLocale(), getPattern(), setSample(java.lang.Object)

setFormat

public void setFormat(java.util.Locale locale,
                      java.lang.String pattern)
Sets the current format from given locale and format pattern.

After setting the locale, this method clears the current format with a call to clearFormatter().

Parameters:
locale - locale instance (may be null)
pattern - format pattern (may be null)
See Also:
clearFormatter(), createFormatter(), getFormatter(), setLocale(java.util.Locale), setPattern(java.lang.String), setSample(java.lang.Object)

setPattern

public void setPattern(java.lang.String pattern)
Sets the current format with a format pattern.

After setting the locale, this method clears the current format with a call to clearFormatter().

Parameters:
pattern - format pattern (may be null)
See Also:
createFormatter(), getPattern(), setSample(java.lang.Object)

setSample

public void setSample(java.lang.Object sample)
Sets the current format with a format sample.

After setting the locale, this method clears the current format with a call to clearFormatter().

Parameters:
sample - format sample (may be null)
See Also:
clearFormatter(), createFormatter(), getSample()

getFormat

public java.lang.String getFormat()
Gets the format specification string. The string is composed of a Java Format keyword and a locale specification string, separated by a ; character. However, if the locale specification string is null, then the specification string will only contain a Format keyword.

Overrides:
getFormat in class LocaleType
See Also:
getFormatter(), LocaleType.getLocale(), getPattern(), getSample(), setFormat(java.util.Locale, java.lang.String), LocaleType.getFormat()

setFormat

public void setFormat(java.lang.String format)
Sets the format type specification string. The given specification string is expected to be composed of a Java Format pattern and a locale specification string, separated by a ; character. Either or both of the two settings may also be missing. The following combinations are therefore supported:

After the spesification string is interpreted, appropriate attribute setter methods are called. They in turn will clear the current format with a call to clearFormatter().

Overrides:
setFormat in class LocaleType
Parameters:
format - type specification string as described above (may be empty or null)
See Also:
getFormat(), setFormat(java.util.Locale, java.lang.String), setLocale(java.util.Locale), setPattern(java.lang.String)

getValueClass

public java.lang.Class getValueClass()
Gets value container class.

Specified by:
getValueClass in class Type


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.