org.dasein.attributes
Class DataTypeFactory<V>

java.lang.Object
  extended by org.dasein.attributes.DataTypeFactory<V>
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BooleanFactory, CurrencyFactory, DateFactory, DecimalFactory, NameValuePairFactory, NumberFactory, StringFactory, TimeFactory

public abstract class DataTypeFactory<V>
extends Object
implements Serializable

Manages attribute data types and access to custom data types.

Last modified: $Date: 2009/01/30 23:01:50 $

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

Nested Class Summary
static class DataTypeFactory.Constraint
           A constraint helps narrow down the set of possible values associated with the underlying data type.
 
Constructor Summary
DataTypeFactory()
          Constructs a new data type factory instance.
 
Method Summary
 DataTypeFactory.Constraint getConstraint(String... typeInfo)
           Provides the next constrain on this data type based on provided type info.
 Collection<DataTypeFactory.Constraint> getConstraints()
          Implementing classes should override this method to define any governing constraints.
abstract  Translator<String> getDisplayName()
          Provides a multi-lingual display name for this data type.
 String getDisplayValue(Locale loc, Object ob)
          Provides a display version of the specified value translated for the target locale.
 String getDisplayValue(Object ob)
          Provides a display value for an instance of this data type.
static DataTypeFactory<?> getInstance(String tname)
          Provides access to the data type factory associated with the specified type name.
 String getStringValue(Object ob)
          Converts the specified value to a string representation for storage.
abstract  DataType<V> getType(boolean ml, boolean mv, boolean req, String... typeArgs)
          Provides access to the underlying data type object that governs this data type.
abstract  DataType<V> getType(String grp, Number idx, boolean ml, boolean mv, boolean req, String... typeArgs)
          Provides access to the underlying data type object that governs this data type.
abstract  String getTypeName()
           
static Collection<DataTypeFactory<?>> getTypes()
          Lists all types known to the system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataTypeFactory

public DataTypeFactory()
Constructs a new data type factory instance.

Method Detail

getInstance

public static DataTypeFactory<?> getInstance(String tname)
Provides access to the data type factory associated with the specified type name.

Parameters:
tname - the name of the data type for the desired factory
Returns:
the factory representing the specified type name
Throws:
InvalidAttributeException - when an unknown type is sought out

getTypes

public static Collection<DataTypeFactory<?>> getTypes()
Lists all types known to the system.

Returns:
a collection of all type factories

getConstraint

public DataTypeFactory.Constraint getConstraint(String... typeInfo)

Provides the next constrain on this data type based on provided type info. If no further constraints exist, it should return null. A user interface will repeatedly make calls to this method to help narrow down a type definition. The first call will pass in no type info and should be identitical to getConstraints().iterator().next(). Subsequent calls will pass in selections based on the previous constraint.

You may override this method to customize its functionality (such as, offer conditional constraints based on prior input). For example of overriding with conditional constraints, see StringFactory.getConstraint(String[]).

An example from Simplicis CMS is a media data type. It has as constraints a media type (such as an image, video, document, etc.) and a media group (a user defined categorization for media assets that holds the type information for media objects). In the CMS, when a page has an attribute of type media, only media assets matching the type and group of the attribute are presented in the choice box for the content owner. The UI can do this because of the constraints.

When the programmer designs the page type, they need to identify which type and group should be included in the choice box. Simplicis has a UI that enables the programmer to manually specify data types (as a result, Simplicis programmers can add new data types without having to alter the Simplicis UI). To accomplish this, the UI needs to prompt for first the media type, and then only those media groups matching the selected media type.

  1. It calls this method first with null to get the first constraint.
  2. Using the data type from that constraint, it prompts the user for all media types.
  3. When the user selects a type from the choice box, the UI then calls this method again with the getStringValue(Object) of the selected type
  4. This method should then return a constraint with the data type for media group with the specified type info as a type parameter.
  5. The user interface prompts the user for a media group of the specified type.
  6. Parameters:
    typeInfo - the string values from previous constraints
    Returns:
    the next constraint in the list of constraints with the data type modified to reflect the specified type info

getConstraints

public Collection<DataTypeFactory.Constraint> getConstraints()
Implementing classes should override this method to define any governing constraints. A constraint is simply another data type that will govern values of this type. Imagine, for example, a MediaAttribute data type that had values of a specific media type. For one attribute, "images", only Media objects that are images are allowed. For another attribute, "documents", only documents are allowed. You would thus have a MediaTypeAttribute data type that allowed media types (image, document, etc). That data type, in turn, would be a constraint on your MediaAttribute data type.

Returns:
a list of constraints on this data type

getDisplayName

public abstract Translator<String> getDisplayName()
Provides a multi-lingual display name for this data type.

Returns:
the display name for the data type

getDisplayValue

public String getDisplayValue(Object ob)
Provides a display value for an instance of this data type. If the value is a multi-lingual Translator, then this method will provide the display value for the default system locale as defined in Locale.getDefault().

Parameters:
ob - the value for which a display value is being sought
Returns:
the display value for the specified value

getDisplayValue

public String getDisplayValue(Locale loc,
                              Object ob)
Provides a display version of the specified value translated for the target locale.

Parameters:
loc - the locale for which the display should be translated
ob - the target value
Returns:
a display version of the specified value

getStringValue

public String getStringValue(Object ob)
Converts the specified value to a string representation for storage.

Parameters:
ob - the object to be converted
Returns:
a string representation for storage

getTypeName

public abstract String getTypeName()
Returns:
the name of this data type

getType

public abstract DataType<V> getType(boolean ml,
                                    boolean mv,
                                    boolean req,
                                    String... typeArgs)
Provides access to the underlying data type object that governs this data type. The configurable rules for the data type are provided as parameters.

Parameters:
ml - is the data type multi-lingual?
mv - is the data type multi-valued?
req - is a value for the data type required?
typeArgs - arbitrary parameters with meaning dependent on the underlying type
Returns:
a data type object for the specified type

getType

public abstract DataType<V> getType(String grp,
                                    Number idx,
                                    boolean ml,
                                    boolean mv,
                                    boolean req,
                                    String... typeArgs)
Provides access to the underlying data type object that governs this data type. The configurable rules for the data type are provided as parameters.

Parameters:
grp - the group of the data type.
idx - the index of the data type.
ml - is the data type multi-lingual?
mv - is the data type multi-valued?
req - is a value for the data type required?
typeArgs - arbitrary parameters with meaning dependent on the underlying type
Returns:
a data type object for the specified type


Copyright © 2011 enStratus Networks LLC. All Rights Reserved.