org.dasein.attributes
Class DataType<V>

java.lang.Object
  extended by org.dasein.attributes.DataType<V>
Type Parameters:
V - the Java data type that this data type operates on
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BooleanFactory.BooleanAttribute, CurrencyFactory.CurrencyAttribute, DateFactory.DateAttribute, DecimalFactory.DecimalAttribute, NameValuePairFactory.NameValuePairAttribute, NumberFactory.NumberAttribute, StringFactory.StringAttribute, TimeFactory.DateAttribute

public abstract class DataType<V>
extends Object
implements Serializable

Represents a data type for the Dasein attributes system. A data type governs what kind of values are valid for any attribute having this data type. To create custom data types, you must extend this class as well as the DataTypeFactory class.

Last modified: $Date: 2009/02/02 19:27:05 $

Version:
$Revision: 1.7 $
Author:
George Reese
See Also:
Serialized Form

Nested Class Summary
static class DataType.InputType
           Represents a type of input field associated with inputting values associated with this attributes system.
 
Constructor Summary
DataType(String nom, String grp, Number idx, boolean ml, boolean mv, boolean req, String... params)
          Constructs a new data type instance.
 
Method Summary
 boolean equals(Object ob)
          Two data type instances are considered identical if everything about them is the same.
abstract  Collection<V> getChoices()
          Provides a list of values considered valid for this data type.
abstract  DataTypeFactory<V> getFactory()
           
 String getGroup()
           
 int getIndex()
           
abstract  DataType.InputType getInputType()
           
 String getName()
           
 Collection<String> getParameters()
          Type parameters tell a data type how to constrain values.
 int getSize()
           
 Translator<V> getTranslatedValue(Object src, Locale loc, Translator<?> curr)
          Provides a Translator instance for the requested value.
abstract  V getValue(Object src)
          Implementors will implement this method to convert a raw value into a valid value of this data type.
 Collection<V> getValues(Object src)
          When a data type is multi-valued, this method is called to convert raw data into a collection of values matching this data type.
 int hashCode()
           
 boolean isMultiLingual()
           
 boolean isMultiValued()
           
 boolean isRequired()
           
abstract  boolean isValidChoice(V arg)
           Checks the specified value to see if it is valid for this data type.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataType

public DataType(String nom,
                String grp,
                Number idx,
                boolean ml,
                boolean mv,
                boolean req,
                String... params)
Constructs a new data type instance. Implementations will generally override this with custom constructors that do something meaningful with the type parameters.

Parameters:
nom - the name of the data type
grp - the group of the data type
idx - the index of the data type
ml - true if the type is multi-lingual
mv - true if the type allows more than one value
req - true if the type requires a value (cannot be null)
params - a list of parameters constraining this type
Method Detail

equals

public boolean equals(Object ob)
Two data type instances are considered identical if everything about them is the same.

Overrides:
equals in class Object
Returns:
true if both data type instances represent the same exact data type

getChoices

public abstract Collection<V> getChoices()
Provides a list of values considered valid for this data type. If any object of the type governed by this data type is allowed, this method will return null.

Returns:
a list of allowed values or null to allow any value

getFactory

public abstract DataTypeFactory<V> getFactory()
Returns:
the factory object that owns this data type

getInputType

public abstract DataType.InputType getInputType()
Returns:
the type of input that a user interface should provide to prompt a user for a value

getName

public final String getName()
Returns:
the name of this data type

getGroup

public final String getGroup()
Returns:
the group of this data type

getIndex

public final int getIndex()
Returns:
the index of this data type

getParameters

public final Collection<String> getParameters()
Type parameters tell a data type how to constrain values. What these parameters are and how they are interpreted are left entirely up to the implementing classes.

Returns:
the constraining parameters for this data type

getSize

public int getSize()
Returns:
the recommended size for an input field

getTranslatedValue

public Translator<V> getTranslatedValue(Object src,
                                        Locale loc,
                                        Translator<?> curr)
Provides a Translator instance for the requested value. This method is generally called to turn an arbitrary object into a multi-lingual instance of of the variable. Basically, when the system is trying to convert arbitrary data—such as user input or values from a persistence engine—into proper values for this type, it will call either this method or getValue(Object). Which method is called is dependent on whether this data type is multi-lingual. If the data type is multi-lingual, this method is called. This method will, in turn, call getValue(Object) and wrap it in a Translator.

Parameters:
src - the raw data to be converted
loc - the locale associated with this value
curr - any current values for other languages
Returns:
a combined multi-lingual value

getValue

public abstract V getValue(Object src)
Implementors will implement this method to convert a raw value into a valid value of this data type. Implementations should throw an InvalidAttributeException if they are unable to interpret the raw value.

Parameters:
src - the raw value, such as user input or a string from a persistent store
Returns:
a converted value of this data type

getValues

public Collection<V> getValues(Object src)
When a data type is multi-valued, this method is called to convert raw data into a collection of values matching this data type. If the raw value is a string, this method assumes that the string represents a comma-delimited, multi-value attribute.

Parameters:
src - the raw source value
Returns:
the converted value

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
a unique hash code for this instance of this class

isMultiLingual

public final boolean isMultiLingual()
Returns:
true if this data type supports multiple values for different languages

isMultiValued

public final boolean isMultiValued()
Returns:
true if this data type allows for multiple values

isRequired

public final boolean isRequired()
Returns:
true if this data type must have a value (cannot be null)

isValidChoice

public abstract boolean isValidChoice(V arg)

Checks the specified value to see if it is valid for this data type. In general, implementing classes will check the following:

Parameters:
arg - the value being validated
Returns:
true if the value is valid for this data type

toString

public String toString()
Overrides:
toString in class Object
Returns:
a string representation of this data type


Copyright © 2011 enStratus Networks LLC. All Rights Reserved.