com.davisor.data
Class TextType

java.lang.Object
  extended byjava.text.Format
      extended bycom.davisor.data.Type
          extended bycom.davisor.data.TextType
All Implemented Interfaces:
java.lang.Cloneable, java.util.Comparator, com.davisor.core.Dupable, java.io.Serializable
Direct Known Subclasses:
SQLTextType, URLTextType

public class TextType
extends Type

TextType defines a concrete base class for all string data types. TextType may also impose two formatting restrictions on string values: mandatory prefix string, and a maximum allowed string value length.

Non-positive maximum length values indicate no maximum length restrictions. Non-empty prefixes are removed from read strings, and added to written strings. The length of the prefix is not taken into account when string maximum length restrictions are verified.

Format syntax

TextType constrains may also be specified with type format strings of the form:
[maxLength] | (maxLength " " prefix)

Since:
JDK1.1
See Also:
SQLTextType, TextData, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
static TextType DEFAULT
          Default text type.
static java.lang.String TYPENAME
          Type name ("TEXT").
 
Fields inherited from class com.davisor.data.Type
METADATA_GROUP, METADATA_NAME, METADATA_PARENT, METADATA_SUBCHANNELS
 
Constructor Summary
  TextType()
          Default constructor.
  TextType(java.lang.String dataName)
          Creates a new default type with no identity.
  TextType(java.lang.String dataName, java.lang.String id, java.util.Map metaData, int maxLength, java.lang.String prefix)
          Creates a new type.
  TextType(java.lang.String dataName, java.lang.String id, java.lang.String format)
          Creates a new type.
protected TextType(java.lang.String typeName, java.lang.String dataName, java.lang.String id, java.util.Map metaData, int maxLength, java.lang.String prefix)
          Creates a new type.
  TextType(TextType tt)
          Copy constructor.
 
Method Summary
 java.lang.String check(java.lang.String data)
          Verifies that a text string meets the given constrains, and modifies it if it does not.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 boolean equals(java.lang.Object o)
          Tests if this object is equal with another object.
 float getCompatibility(java.lang.Class type)
          Gets an estimate of how well this type could represent objects of the given class.
 java.lang.String getFormat()
          Gets the current type specification string.
 int getMaxLength()
          Gets the maximum row length.
 java.lang.String getPrefix()
          Gets the row prefix.
 int getSQLCode()
          Gets the default java.sql.Types SQL type code.
 java.lang.Class getValueClass()
          Gets value container class.
 int hashCode()
          Returns a hash code value for the object.
 void setFormat(java.lang.String format)
          Sets text type constraints.
 TextType setMaxLength(int maxLength)
          Sets the maximum row length.
 TextType setPrefix(java.lang.String prefix)
          Sets the row prefix.
 java.lang.String stringValue(java.lang.String value, java.text.ParsePosition status)
          Verifies that a text string meets the given constraints, and modifies it if it does not.
 DataValue toData(java.lang.String stringValue, java.text.ParsePosition status)
          Converts a string to a data value.
 DataValue zero()
          Gets zero data value for this type.
 
Methods inherited from class com.davisor.data.Type
ceil, check, compare, create, create, create, create, create, dup, floor, format, getDataName, getId, getID, getMetaData, getMetaData, getSpecs, getSQLName, getSQLName, getTypeName, isNull, parseObject, register, register, setDataName, setId, setID, setMetaData, setMetaData, setSpecs, toData, toData, toData, toString, toXML, xmlEnd, xmlStart
 
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

DEFAULT

public static final TextType DEFAULT
Default text type.


TYPENAME

public static final java.lang.String TYPENAME
Type name ("TEXT").

See Also:
Constant Field Values
Constructor Detail

TextType

public TextType()
Default constructor.


TextType

public TextType(TextType tt)
Copy constructor.


TextType

public TextType(java.lang.String dataName)
Creates a new default type with no identity.

Parameters:
dataName - data name (may be null)

TextType

public TextType(java.lang.String dataName,
                java.lang.String id,
                java.lang.String format)
Creates a new type.

This is the constructor the SQL type mapper Type.create(Integer,String,String,String) method will call to create a type that matches given SQL type.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
format - type spesification (may be null)
See Also:
setFormat(java.lang.String)

TextType

public TextType(java.lang.String dataName,
                java.lang.String id,
                java.util.Map metaData,
                int maxLength,
                java.lang.String prefix)
Creates a new type.

Parameters:
dataName - data name (may be null)
id - type identity (may be null)
metaData - type meta data map (may be null)
maxLength - maximum text length
prefix - mandatory text prefix (may be null)

TextType

protected TextType(java.lang.String typeName,
                   java.lang.String dataName,
                   java.lang.String id,
                   java.util.Map metaData,
                   int maxLength,
                   java.lang.String prefix)
Creates a new type.

Parameters:
typeName - type name
dataName - data name (may be null)
id - type identity (may be null)
metaData - type meta data map (may be null)
maxLength - maximum text length
prefix - mandatory text prefix (may be null)
Method Detail

dup

public com.davisor.core.Dupable dup()
Makes a deep copy of this object.

Specified by:
dup in interface com.davisor.core.Dupable
Specified by:
dup in class Type

equals

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

Text types are equal if their super-classes, maximum length constraints, and prefixes are.

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

hashCode

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

Overrides:
hashCode in class Type

stringValue

public java.lang.String stringValue(java.lang.String value,
                                    java.text.ParsePosition status)
                             throws InvalidDataException
Verifies that a text string meets the given constraints, and modifies it if it does not. This means that the value is cut to the current maximum length and then padded with the current prefix string.

Parameters:
value - data string
status - parse status (may be null)
Returns:
Data string.
Throws:
InvalidDataException - never thrown.
See Also:
check(java.lang.String)

getMaxLength

public int getMaxLength()
Gets the maximum row length.

Returns:
Maximum row length, if set, or otherwise zero.

setMaxLength

public TextType setMaxLength(int maxLength)
Sets the maximum row length.

Parameters:
maxLength - maximum row length, or zero if not set

getPrefix

public java.lang.String getPrefix()
Gets the row prefix.

Returns:
Mandatory row prefix.

setPrefix

public TextType setPrefix(java.lang.String prefix)
Sets the row prefix.

Parameters:
prefix - mandatory row prefix

check

public java.lang.String check(java.lang.String data)
                       throws InvalidDataException
Verifies that a text string meets the given constrains, and modifies it if it does not. This means that the string first is truncated, if it exceeds maximum length, and then padded with the current prefix, in case the string does not already begin with that.

Overrides:
check in class Type
Parameters:
data - data string
Returns:
Data string.
Throws:
InvalidDataException - never
See Also:
setFormat(java.lang.String), Type.check(java.lang.String)

getFormat

public java.lang.String getFormat()
Gets the current type specification string. The specification string will contain an integer value, specifying the text maximum length and optionally a white space character and text prefix string. If the default settings apply (no length constraint, no prefix), null is returned.

Overrides:
getFormat in class Type
Returns:
type specification string, as described above.
See Also:
getMaxLength(), setFormat(java.lang.String)

getSQLCode

public int getSQLCode()
Gets the default java.sql.Types SQL type code.

Overrides:
getSQLCode in class Type
Returns:
Types.LONGVARCHAR.

setFormat

public void setFormat(java.lang.String format)
Sets text type constraints. The constraints are specified with a string that contains an integer specifying the maximum row length, followed by a single space. Anything else thereafter is considered to be the text type string prefix string. The row length must be a positive integer. Any other value (zero in particular) disables the maximum length constraint.

If the string prefix is missing, "" is assumed. If the row length and prefix both are missing, 0 and "" are assumed.

Overrides:
setFormat in class Type
Parameters:
format - type specification, as specified above (may be null)
See Also:
getFormat(), setMaxLength(int), setPrefix(java.lang.String)

getCompatibility

public float getCompatibility(java.lang.Class type)
Gets an estimate of how well this type could represent objects of the given class.

Overrides:
getCompatibility in class Type
Parameters:
type - type to estimate
Returns:
1.0 if the given type is assignable from String, otherwise 0.1, as all types have at least some string representation.
See Also:
getValueClass()

getValueClass

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

Specified by:
getValueClass in class Type

toData

public DataValue toData(java.lang.String stringValue,
                        java.text.ParsePosition status)
                 throws InvalidDataException
Converts a string to a data value.

TextType type accepts all string values, and returns a corresponding TextData value.

Specified by:
toData in class Type
Parameters:
stringValue - data string
status - parse status (may be null)
Returns:
a data value object corresponding given string value
Throws:
InvalidDataException - if given string value could not be parsed
See Also:
Type.toData(CallableStatement,int), Type.toData(Object), Type.toData(ResultSet,int), TextData

zero

public DataValue zero()
Gets zero data value for this type.

Specified by:
zero in class Type
Returns:
a new zero value TextData object sharing this type
See Also:
DataValue.deinterpolate(com.davisor.data.DataValue, com.davisor.data.DataValue), DataValue.interpolate(double, com.davisor.data.DataValue)


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