|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.text.Format
com.davisor.data.Type
Type provides a base class for parametrized data types. Type objects are useful whenever data needs to be accepted and interpreted from strings or other data sources, or written and stored as strings or into other data objects. Typical example cases would be interpreting parameters received over a HTTP -protocol, from different user interface input forms, XML -documents and databases.
Types define the following names that can be used to group and identify type instances:
Type identity defines an unique key that may be used to place types
into maps or other similar structures. A typical example would be
channel5. Data name describes the data the data
objects of this type contain. A typical example would be
temperature. Type name describes the type itself. A
typical example would be integer. Type identity and
data name may be typically freely assigned, but the type name is
defined by the type class, and it can not be changed.
Applications are encouraged to pay special attention to type meta
data copying. In particular, only Dupable type meta data is
deep copied when types are, while other kind of meta data is only
shallow copied. Any mutable but not Dupable meta data may
therefore cause unexpected meta data value behaviour.
types.properties
resource file, located in the com.davisor.data package.
This property file is expected to enumerate a set of initial type
classes that should be made available for type name mapping. The names
the types are to be bound to are queried from the type object
getTypeName() methods (see register(Type)).
SQL type mapping is based on XOPEN type names and
java.sql.Types integer codes. The mapping of which SQL
type code is mapped to which type is controlled by sqltypes.properties
resource file, located again in the com.davisor.data
package. The property file is expected to enumerate XOPEN type
names, each with a value that tells to what class that type is to
be mapped to (see create(Integer,String,String,String)).
Type constraints and formatting details can be tuned with type specification strings. Encapsulating type parameters into a single string makes polymorphic type configuration mechanisms possible. Exactly what parameters these specification strings support then obviously depends on each type implementation.
All sub-classes are also assumed to provide at least the following public constructors:
Implementing these constructors is not strictly mandatory, but failing to provide them will make some polymorphic type services that rely on a Java reflection unavailable.
To ensure smooth expandability, all Type subclasses should also provide one protected constructor that just accepts values for all class parameter member variables. This constructor should then assign the given parameters to the member variables that it manages, and transparently forward the rest. The constructor should particularly not do any computing or method invocations.
getDataName(),
getID(),
getTypeName(),
BooleanType,
CountType,
DateInputType,
DateOutputType,
DateType,
DoubleType,
EnumType,
FloatType,
IntegerRangeType,
IntegerType,
LocaleType,
SQLTextType,
TextType,
TimestampInputType,
TimestampOutputType,
TimestampType,
TupleType,
URLType,
Serialized Form| Nested Class Summary |
| Nested classes inherited from class java.text.Format |
java.text.Format.Field |
| Field Summary | |
static java.lang.String |
METADATA_GROUP
Meta data key for type group. |
static java.lang.String |
METADATA_NAME
Meta data key for type name. |
static java.lang.String |
METADATA_PARENT
Meta data key for type parent. |
static java.lang.String |
METADATA_SUBCHANNELS
Meta data key for type subchannels. |
static java.lang.String |
TYPENAME
Default type name ("TEXT"). |
| Constructor Summary | |
protected |
Type(java.lang.String typeName,
java.lang.String dataName,
java.lang.String id,
java.util.Map metaData)
Creates a new type. |
protected |
Type(Type type)
Deep copy constructor. |
| Method Summary | |
static DataValue |
ceil(DataValue zero,
DataValue step,
DataValue value)
Quantizes a value up so that the range from given zero value to the given value will be an even multiply of given steps. |
java.lang.String |
check(java.lang.String value)
Checks and reformats a data string. |
java.lang.String[] |
check(java.lang.String[] values)
Checks and reformats data strings. |
int |
compare(java.lang.Object o1,
java.lang.Object o2)
Compares two arguments. |
static Type |
create(java.lang.Class typeClass,
java.lang.String dataName,
java.lang.String id,
java.lang.String format)
Creates a new type instance best suited for data elements represented as instances of of given Java class. |
static Type |
create(java.lang.Integer sqlType,
java.lang.String dataName,
java.lang.String id,
java.lang.String format)
Creates a new type instance from the given SQL type code. |
static Type |
create(int sqlType,
java.lang.String dataName,
java.lang.String id,
java.lang.String format)
Creates a new type instance from the given SQL type code. |
static Type |
create(java.lang.Object object)
Resolves the object type, creating a new one if neccessary. |
static Type |
create(java.lang.String typeName,
java.lang.String dataName,
java.lang.String id,
java.lang.String format)
Creates a new type instance from the type family name. |
abstract com.davisor.core.Dupable |
dup()
Makes a deep copy of this object. |
Type |
dup(java.lang.String dataName,
java.lang.String id,
java.lang.String format)
Creates a new type instance from this type. |
boolean |
equals(java.lang.Object o)
Tests if this object is equal with another object. |
static DataValue |
floor(DataValue zero,
DataValue step,
DataValue value)
Quantizes a value down so that the range from given zero value to the given value will be an even multiply of given steps. |
java.lang.StringBuffer |
format(java.lang.Object obj,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
Formats an object to produce a string. |
float |
getCompatibility(java.lang.Class type)
Gets an estimate of how well this type could represent objects of the given class. |
java.lang.String |
getDataName()
Gets type instance data name. |
java.lang.String |
getFormat()
Gets the type specification string. |
java.lang.String |
getId()
Deprecated. replaced with getID() |
java.lang.String |
getID()
Gets type instance identity. |
java.util.Map |
getMetaData()
Gets type meta data map. |
java.lang.Object |
getMetaData(java.lang.Object key)
Gets type meta data value. |
java.lang.String |
getSpecs()
Deprecated. replaced with getFormat() |
int |
getSQLCode()
Gets the default java.sqlTypes SQL type code. |
java.lang.String |
getSQLName()
Get the SQL type name for default database settings. |
java.lang.String |
getSQLName(java.lang.String dbtype)
Get the SQL type name for specific database. |
java.lang.String |
getTypeName()
Gets the type name. |
abstract java.lang.Class |
getValueClass()
Gets value container class. |
int |
hashCode()
Returns a hash code value for the object. |
static boolean |
isNull(SerializableData data)
Tests if a given data is null, or has a null value. |
java.lang.Object |
parseObject(java.lang.String source,
java.text.ParsePosition status)
Parses a string to produce an object. |
void |
register(java.sql.CallableStatement call,
int column)
Register a callable statement output parameter type. |
static void |
register(Type type)
Registers a type among known types. |
void |
setDataName(java.lang.String dataName)
Sets the type instance data name. |
void |
setFormat(java.lang.String format)
Sets the type specification string. |
void |
setId(java.lang.String id)
Deprecated. replaced with setID(String) |
void |
setID(java.lang.String id)
Sets type identity. |
void |
setMetaData(java.util.Map metaData)
Sets type meta data map. |
void |
setMetaData(java.lang.Object key,
java.lang.Object value)
Sets type meta data map value. |
void |
setSpecs(java.lang.String specs)
Deprecated. replaced with setFormat(String) |
DataValue |
toData(java.sql.CallableStatement statement,
int column)
Converts a callable statement variable to a data value. |
DataValue |
toData(java.lang.Object objectValue)
Converts an object to a data value. |
DataValue |
toData(java.sql.ResultSet resultSet,
int column)
Converts a result set column value to a data value. |
abstract DataValue |
toData(java.lang.String stringValue,
java.text.ParsePosition status)
Converts a string to a data value. |
java.lang.String |
toString()
Gets type string representation. |
static java.lang.String |
toXML(DataValue dataValue)
Converts a data value to a XML string. |
java.lang.String |
xmlEnd()
Creates a XML end element for data elements of this type. |
java.lang.String |
xmlStart()
Creates a XML start element for data elements of this type. |
abstract DataValue |
zero()
Gets zero data value for this type. |
| 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 |
public static final java.lang.String METADATA_NAME
public static final java.lang.String METADATA_GROUP
public static final java.lang.String METADATA_PARENT
public static final java.lang.String METADATA_SUBCHANNELS
public static final java.lang.String TYPENAME
| Constructor Detail |
protected Type(Type type)
Dupable keys and values are deep
copied into it with Dupable.dup() method. However, all keys
and values that are not Dupable are only shallow copied.
type - source type
protected Type(java.lang.String typeName,
java.lang.String dataName,
java.lang.String id,
java.util.Map metaData)
typeName - type namedataName - data name (may be null)id - type identity (may be null)metaData - type meta data map (may be null)| Method Detail |
public abstract java.lang.Class getValueClass()
public abstract DataValue toData(java.lang.String stringValue,
java.text.ParsePosition status)
throws InvalidDataException
Subclasses are expected to implement this method with string parsers that interprets the given string in the most lenient way possible, and create corresponding new object of this type.
stringValue - data stringstatus - parse status (may be null)
InvalidDataException - if given string value could not be parsedtoData(CallableStatement,int),
toData(Object),
toData(ResultSet,int),
DataValue.toString()public abstract DataValue zero()
DataValue.deinterpolate(com.davisor.data.DataValue, com.davisor.data.DataValue),
DataValue.interpolate(double, com.davisor.data.DataValue)
public int compare(java.lang.Object o1,
java.lang.Object o2)
DataValue, they are first converted to this type with the toData(Object) method. If then either of the resulting objects
is Comparable, comparation is delegated to it.
Otherwise the compration fails. Comparation fails also if the
object the comparation was delegated to fails to compare itself
to the other object.
compare in interface java.util.Comparatorjava.lang.ClassCastException - if the arguments' types prevent them
from being compared by this Comparatorpublic abstract com.davisor.core.Dupable dup()
dup in interface com.davisor.core.Dupable
public java.lang.StringBuffer format(java.lang.Object obj,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
DataValue with the help of the toData(Object) method. The data value value is then converted
to a string with DataValue.toString() method. The
resulting string is then appended to given string buffer.
Depending on underlying implementations, the resulting chain of
conversion and formatting steps may be very complex and
elaborate. For more efficient processing, consider using the
DataValue.toString() directly when possible.
null objects or string buffers will generate no
output. null field position objects are ignored and
not written to.
obj - the object to format with this formatter (may be null)toAppendTo - the string buffer to append the result to (may be null)pos - the field position record to update (may be null)
java.lang.IllegalArgumentException - if formatting failstoData(Object),
DataValue,
DataValue.toString()
public java.lang.Object parseObject(java.lang.String source,
java.text.ParsePosition status)
public boolean equals(java.lang.Object o)
Types are by default equal if their type identities and data names are equal.
Subclasses are expected to extend this equality test. In
particular, subclass implementations are encouraged to first
test object instance equality with the == operator,
then their super-class unequality with
super.equals(Object) method, and finally perform
their own class -specific equality tests if necessary. A typical
test sequence should therefore look something like this:
public boolean equals(Object o)
{
if(this == o) return true;
if(!super.equals(o) || !(o instanceof TypeSubClass)) return false;
:
}
equals in interface java.util.ComparatorCompare.equals(Object,Object),
VoidData.equals(Object)public int hashCode()
public java.lang.String toString()
Subclasses are expected to concatenate their own attributes to this string.
xmlEnd(),
xmlStart(),
Strings.toXML(String,Object)
public java.lang.String check(java.lang.String value)
throws InvalidDataException
The default checking procedure is to first parse the data string as a data object, and then turn the resulting object back to a data string. Parsing checks the validity of the data string, while formatting reformats it. Therefore, in addition to validating the input value, the resulting string may also have been changed in some way.
The returned string should be such that if checked with this method again, the operation should be completed without exceptions or new changes to the string.
value - data string value
InvalidDataException - if the value is invalidcheck(String[]),
toData(java.lang.String, java.text.ParsePosition),
DataValue.toString()
public java.lang.String[] check(java.lang.String[] values)
throws InvalidDataException
Parsing checks the validity of the data strings, formatting reformats them. The resulting strings may be identical to the original ones, or they may have been changed in some way.
values - data strings
InvalidDataException - if some value is invalidcheck(String)
public static DataValue ceil(DataValue zero,
DataValue step,
DataValue value)
throws InvalidDataException
zero - range limit valuestep - quantization factorvalue - value to be rounded up
InvalidDataExceptionfloor(com.davisor.data.DataValue, com.davisor.data.DataValue, com.davisor.data.DataValue)
public static Type create(java.lang.Object object)
throws InvalidDataException
object - the object of which the type is to be resolved (may be null)
InvalidDataException - if object can not be converted
NullDataException - if object was nullcreate(Class,String,String,String),
create(Integer,String,String,String),
create(String,String,String,String),
create(int,String,String,String),
toData(Object)
public static Type create(int sqlType,
java.lang.String dataName,
java.lang.String id,
java.lang.String format)
throws NoSuchTypeException
sqlType - SQL type codedataName - data name for the new type instanceid - type identityformat - specifications for the new type
NoSuchTypeException - 'sqlType' was not supportedcreate(Class,String,String,String),
create(Integer,String,String,String),
create(Object),
create(String,String,String,String)
public static Type create(java.lang.Integer sqlType,
java.lang.String dataName,
java.lang.String id,
java.lang.String format)
throws NoSuchTypeException
Type instances are created by calling their constructor with the following signature:
SomeType(String dataName,String id,String format)
The arguments are expected to have the same significance as
corresponding arguments to this method. See IntegerType.IntegerType(String,String,String) for an example.
sqlType - sql type codedataName - data name for the new type instanceid - type identityformat - specifications for the new type
NoSuchTypeException - if no type was mapped to sqlTypecreate(Class,String,String,String),
create(Object),
create(String,String,String,String),
create(int,String,String,String)
public static Type create(java.lang.Class typeClass,
java.lang.String dataName,
java.lang.String id,
java.lang.String format)
throws NoSuchTypeException
typeClass - desired element type classdataName - data name for the new type instanceid - type identityformat - specifications for the new type
NoSuchTypeException - 'type' was not compatible with any
known types.create(Integer,String,String,String),
create(Object),
create(String,String,String,String),
create(int,String,String,String)
public static Type create(java.lang.String typeName,
java.lang.String dataName,
java.lang.String id,
java.lang.String format)
throws NoSuchTypeException
typeName - case insensitive type namedataName - data name for the new type instanceid - type identityformat - specifications for the new type
NoSuchTypeException - if type name did not refer to any known typecreate(Class,String,String,String),
create(Integer,String,String,String),
create(Object),
create(int,String,String,String)
public Type dup(java.lang.String dataName,
java.lang.String id,
java.lang.String format)
dataName - data name of the new type instanceid - type identityformat - specification string for the new type
dup(),
setDataName(java.lang.String),
setID(java.lang.String),
setFormat(java.lang.String)
public static DataValue floor(DataValue zero,
DataValue step,
DataValue value)
throws InvalidDataException
zero - range limit valuestep - quantization factorvalue - value to be rounded down
InvalidDataExceptionceil(com.davisor.data.DataValue, com.davisor.data.DataValue, com.davisor.data.DataValue)public float getCompatibility(java.lang.Class type)
type - type to estimate
getValueClass()public java.lang.String getDataName()
setDataName(java.lang.String)public java.lang.String getId()
getID()
public java.lang.String getID()
setID(java.lang.String)public java.lang.String getFormat()
This particular default method implementation always returns a
null specification string. Subclasses are, however,
expected to override this.
null specification stringsetFormat(java.lang.String),
DataValue.getFormat()public java.util.Map getMetaData()
getMetaData(Object)public java.lang.Object getMetaData(java.lang.Object key)
null if current meta data map does not recognize
given key, or if there is currently no meta data map.
key - meta data key
getMetaData(),
setMetaData(Object,Object)public java.lang.String getSpecs()
getFormat()
public java.lang.String getSQLName()
public java.lang.String getSQLName(java.lang.String dbtype)
dbtype - database type name.
public int getSQLCode()
public java.lang.String getTypeName()
setName method, as a type
name is an immutable type property.
public static boolean isNull(SerializableData data)
null, or has a null value.
data - data value to be tested
true if data is null, or has
a null valueSerializableData.isNull()public static void register(Type type)
getTypeName()
method. After registration, the new type will be available for
the various create methods.
type - type to be registeredcreate(Class,String,String,String),
create(Integer,String,String,String),
create(Object),
create(String,String,String,String),
create(int,String,String,String)
public void register(java.sql.CallableStatement call,
int column)
throws java.sql.SQLException
getSQLCode method.
call - statement to register out parameter tocolumn - column to register out parameter to
java.sql.SQLException - if a SQL error occurspublic void setDataName(java.lang.String dataName)
dataName - new type instance data name (may be null)getDataName()public void setId(java.lang.String id)
setID(String)
id - new type instance identitypublic void setID(java.lang.String id)
id - new type instance identitygetID()public void setFormat(java.lang.String format)
The type specification string can also be set to null,
which selects type default behaviour. In this case, the
corresponding getFormat is also required to return
null.
This particular default method implementation ignores any specification string given to it. Subclasses are, however, expected to override this.
format - type specification string (may be null)getFormat(),
DataValue.getFormat()public void setMetaData(java.util.Map metaData)
metaData - an application spesific meta data object map
public void setMetaData(java.lang.Object key,
java.lang.Object value)
HashMap is created.
key - meta data keyvalue - meta data valuegetMetaData(Object),
setMetaData(Map)public void setSpecs(java.lang.String specs)
setFormat(String)
specs - type specification string (may be null)
public DataValue toData(java.lang.Object objectValue)
throws InvalidDataException
Subclasses are encouraged to implement this method with custom object parsers that interprete given object in the most lenient way possible, and create corresponding new object of this type. It is also acceptable to return the given object as it was, if the object meet subclass criteria for this type.
This default implementation first tests if the given object is a
data value of this type. If it is, it is returned as it was. If
it is not, the object string representation is delegated to the
toData(String,ParsePosition) method for
interpretation. If the object value is null, a VoidValue object is created and returned.
objectValue - data object
InvalidDataException - if given object value could not be parsedtoData(CallableStatement,int),
toData(ResultSet,int),
toData(String,ParsePosition),
DataValue.toString()
public DataValue toData(java.sql.CallableStatement statement,
int column)
throws InvalidDataException,
java.sql.SQLException
This detault implementation gets statement variable string value,
and delegates it to toData(String,ParsePosition)
method for intepretations.
statement - statement holding the data value to be convertedcolumn - SQL column index for the data value to be converted
InvalidDataException - if given object value could not be parsed
java.sql.SQLException - if a SQL error occurstoData(Object),
toData(ResultSet,int),
toData(String,ParsePosition),
DataValue.toString()
public DataValue toData(java.sql.ResultSet resultSet,
int column)
throws InvalidDataException,
java.sql.SQLException
This detault implementation gets result set column string value,
and delegates it to toData(String,ParsePosition)
method for intepretations.
resultSet - resultSet holding the data value to be convertedcolumn - SQL column index for the data value to be converted
InvalidDataException - if given object value could not be parsed
java.sql.SQLException - if a SQL error occurstoData(CallableStatement,int),
toData(Object),
toData(String,ParsePosition),
DataValue.toString()public static java.lang.String toXML(DataValue dataValue)
null, and if
so, it invokes the DataValue.toXML() method of given
value object. If the data value is null,
null is also returned.
dataValue - data value to convert to a XML string
public java.lang.String xmlEnd()
xmlStart()public java.lang.String xmlStart()
toString(),
xmlEnd(),
Strings.toXML(String,Object)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||