com.ail.core
Class Attribute

java.lang.Object
  extended by com.ail.core.Type
      extended by com.ail.core.Attribute
All Implemented Interfaces:
Identified, java.io.Serializable, java.lang.Cloneable

public class Attribute
extends Type
implements Identified

An attribute is defined as "One of numerous aspects, as of a subject". Generally, another type will own a (composite) collection of Attributes which help describe it. For example, a Car type might have attributes including colour, engine size, number of seats. A Person type might have height, weight, and hair colour as attributes.

Attribute supports very flexible types (or formats) of value information. The approach to formatting attributes is based on MessageFormat and includes extensions for handling currency, and common choice types. All of MessageFormat's Format Type and Format Style options are supported, so for example you specify the format as "number,percent" as follows:

new Attribute("id", "21", "number,percent");

The following are all valid combinations of Format Type, Format Style, and unit:

Attribute a=new Attribute("id", "23.442", "number,#.##");
Attribute b=new Attribute("id", "£21", "currency", "GBP");
Attribute c=new Attribute("id", "21", "currency", "EUR");
Attribute d=new Attribute("id", "YES", "yesorno");
Attribute e=new Attribute("id", "Female", "choice,1#Male|2#Female");
Attribute e=new Attribute("id", "Hello world", "string");
Attribute e=new Attribute("id", "I'm a long string of text that may wrap over many lines", "note");

Note: The 'note' and a 'string' formats are handled identically. UI components or document renderers may choose to display them differently, but the implementation within this class is identical.

The Attribute class offers four ways to access an attribute's value: getValue(), getObject() and getFormattedValue(). The following table outlines the differences between these methods based on the attributes listed above:

a.getValue()returns "23.442" as a String
a.getObject()returns Double(21.442)
a.getFormattedValue()returns "23.44" as a String
b.getValue()returns "£21" as a String
b.getObject()returns "£21" as a String
b.getFormattedValue()returns "£21" as a String
c.getValue()returns "21" as a String
c.getObject()returns "21" as a String
c.getFormattedValue()returns "€21" as a String
d.getValue()returns "YES" as a String
d.getObject()returns Double(1.0)
d.getFormattedValue()returns "YES" as a String
c.getValue()returns "Female" as a String
c.getObject()returns Double(2.0)
c.getFormattedValue()returns "Female" as a String

Values can only ever be set using setValue(String).

Version:
$Revision: 1.17 $
See Also:
Serialized Form

Field Summary
static java.lang.String YES_OR_NO_FORMAT
           
 
Fields inherited from class com.ail.core.Type
jXPathContext, NOT_PERSISTED
 
Constructor Summary
Attribute()
          Default constructor
Attribute(java.lang.String id, java.lang.String value, java.lang.String format)
          Constructor
Attribute(java.lang.String id, java.lang.String value, java.lang.String format, java.lang.String unit)
          Constructor
 
Method Summary
 boolean compareById(java.lang.Object that)
          If that is an Attribute, and has the same Id as this they are considered equal.
 java.lang.String getChoiceMaster()
          If this is a choice slave (isChoiceMasterType()) then return the name of the master.
 java.lang.String getChoiceSlave()
          If this is a choice master (isChoiceMasterType()) then return the name of the slave.
 java.lang.String getChoiceTypeName()
          If this is a choice which derives it's list of options from a type, return the name of the type.
 java.lang.String getFormat()
          Getter returning the value of the type property.
 java.lang.String getFormatOption(java.lang.String optionName)
           
 java.lang.String getFormattedValue()
          Return the Attribute's value formatted
 java.lang.String getId()
          Getter returning the value of the id property.
 java.lang.Object getObject()
           
static Type getReferenceContext()
           
 java.lang.String getUnit()
          Getter returning the value of the unit property.
 java.lang.String getValue()
          Getter returning the value of the value property.
 boolean isChoiceMasterType()
          Return true if this is a master choice type.
 boolean isChoiceSlaveType()
          See isChoiceMasterType()
 boolean isChoiceType()
          Return true if the type (format) of this attribute is choice.
 boolean isCurrencyType()
          Return true if the type (format) of this attribute is currency.
 boolean isDateType()
          Return true if the type (format) of this attribute is date.
 boolean isFreeChoiceType()
          A 'free choice' attribute is one which is of choice type (format), but whose format does not define the valid option list.
 boolean isInvalid()
          Test if the value of this attribute is invalid.
 boolean isNoteType()
          Return true if the type (format) of this attribute is note.
 boolean isNumberType()
          Return true if the type (format) of this attribute is number.
 boolean isStringType()
          Return true if the type (format) of this attribute is string.
 boolean isUndefined()
          Return true if the value of this attribute is 'undefined'.
 boolean isYesornoType()
          Return true if the type (format) of this attribute is yesorno.
 void setFormat(java.lang.String format)
          Setter to update the value of the type property.
 void setId(java.lang.String id)
          Setter to update the value of the id property.
static void setReferenceContext(Type ctx)
          Set the context against which references within Attributes in this thread will be evaluated.
 void setUnit(java.lang.String unit)
          Setter to update the value of the unit property.
 void setValue(java.lang.String val)
          Setter to update the value of the value property.
 
Methods inherited from class com.ail.core.Type
addAttribute, clone, deleteLock, deleteSerialVersion, fetchJXPathContext, getAttribute, getAttribute, getAttributeCount, getForeignSystemId, getLock, getSerialVersion, getSystemId, hasLock, hasSerialVersion, hasSystemId, isPersisted, markAsNotPersisted, mergeWithDataFrom, removeAttribute, removeAttribute, setAttribute, setForeignSystemId, setLock, setSerialVersion, setSystemId, xpathGet, xpathGet, xpathIterate, xpathSet
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

YES_OR_NO_FORMAT

public static java.lang.String YES_OR_NO_FORMAT
Constructor Detail

Attribute

public Attribute()
Default constructor


Attribute

public Attribute(java.lang.String id,
                 java.lang.String value,
                 java.lang.String format)
Constructor

Parameters:
id - Value for id property
value - Value for val property
format - Value for type property
unit - Value for unit property

Attribute

public Attribute(java.lang.String id,
                 java.lang.String value,
                 java.lang.String format,
                 java.lang.String unit)
Constructor

Parameters:
id - Value for id property
value - Value for val property
format - Value for type property
unit - Value for unit property
Method Detail

getId

public java.lang.String getId()
Getter returning the value of the id property. The id of the facet - generally unique in a collection

Specified by:
getId in interface Identified
Returns:
Value of the name property

setId

public void setId(java.lang.String id)
Setter to update the value of the id property. The id of the facet - generally unique in a collection

Specified by:
setId in interface Identified
Parameters:
name - New value for the name property

getValue

public java.lang.String getValue()
Getter returning the value of the value property. The value of the facet. For a colour facet, this might be "green". For a "height" facet this might be a Double instance with a value of 6.1.

Returns:
Value of the value property

setValue

public void setValue(java.lang.String val)
Setter to update the value of the value property. The value of the facet. For a colour facet, this might be "green". For a "height" facet this might be a Double instance with a value of 6.1.

Parameters:
value - New value for the value property

getFormattedValue

public java.lang.String getFormattedValue()
Return the Attribute's value formatted

Returns:
The formatted attributes value.

getFormat

public java.lang.String getFormat()
Getter returning the value of the type property. The java type of object represented (or accepted). e.g. java.lang.String, etc.

Returns:
Value of the type property

setFormat

public void setFormat(java.lang.String format)
Setter to update the value of the type property. The java type of object represented (or accepted). e.g. java.lang.String, etc.

Parameters:
type - New value for the type property

getUnit

public java.lang.String getUnit()
Getter returning the value of the unit property. An optional attribute descibing the unit of the facet. This can be any standard unit understood by Unit.valueOf(String). E.g. "kg", "m", etc.

Returns:
Value of the unit property

setUnit

public void setUnit(java.lang.String unit)
Setter to update the value of the unit property. An optional attribute descibing the unit of the facet. This can be any standard unit understood by Unit.valueOf(String). E.g. "kg", "m", etc.

Parameters:
unit - New value for the unit property

getFormatOption

public java.lang.String getFormatOption(java.lang.String optionName)

getObject

public java.lang.Object getObject()

getChoiceSlave

public java.lang.String getChoiceSlave()
                                throws java.lang.IllegalStateException
If this is a choice master (isChoiceMasterType()) then return the name of the slave.

Returns:
Return the slave's name
Throws:
java.lang.IllegalStateException - if this is not a choice master.

getChoiceMaster

public java.lang.String getChoiceMaster()
                                 throws java.lang.IllegalStateException
If this is a choice slave (isChoiceMasterType()) then return the name of the master.

Returns:
Return the master's name
Throws:
java.lang.IllegalStateException - if this is not a choice master.

getChoiceTypeName

public java.lang.String getChoiceTypeName()
                                   throws java.lang.IllegalStateException
If this is a choice which derives it's list of options from a type, return the name of the type.

Returns:
Name of the type defining options.
Throws:
java.lang.IllegalStateException - if this is not a choice, or is but does not define a 'type=' option.

isUndefined

public boolean isUndefined()
Return true if the value of this attribute is 'undefined'. For 'note', 'string', 'number' and 'currency' types undefined means "is null or of zero length". In the case of 'choice' undefined means value is '?'.

Returns:

isInvalid

public boolean isInvalid()
Test if the value of this attribute is invalid. Almost any value can be passed into an attribute's setValue() method and the method will not complain (and if getValue() is called the same thing will be returned). However, the format may specify validation criteria. This method will test if the value currently held by the attribute is invalid against those criteria.

Returns:
true if value is invalid, false otherwise.

isNumberType

public boolean isNumberType()
Return true if the type (format) of this attribute is number.

Returns:
true if this is a number, false otherwise.

isChoiceType

public boolean isChoiceType()
Return true if the type (format) of this attribute is choice. This method returns true for both choice and free choice attributes.

Returns:
true if this is a choice, false otherwise.
See Also:
isFreeChoiceType()

isFreeChoiceType

public boolean isFreeChoiceType()
A 'free choice' attribute is one which is of choice type (format), but whose format does not define the valid option list. This is typically used where a choice format is required, but the actual values are determined outside of the attribute's definition - possibly from a lookup table, by the UI, of by parsing some other part of the model.

Returns:
true if this is a choice, false otherwise

isChoiceMasterType

public boolean isChoiceMasterType()
Return true if this is a master choice type. A master is one whose value dictates the value of a slave choice. For example, if two attributes representing the make and model of a vehicle are used, the make would be the master, and the model the slage. When the master's value is changed, the options available in the slave model list are updated.

Returns:
true if this is a master choice attribute, false otherwise.

isChoiceSlaveType

public boolean isChoiceSlaveType()
See isChoiceMasterType()

Returns:
true if this is a slave choice attribute, false otherwuse.

isCurrencyType

public boolean isCurrencyType()
Return true if the type (format) of this attribute is currency.

Returns:
true if this is a currency, false otherwise.

isYesornoType

public boolean isYesornoType()
Return true if the type (format) of this attribute is yesorno.

Returns:
true if this is a yesorno, false otherwise.

isNoteType

public boolean isNoteType()
Return true if the type (format) of this attribute is note.

Returns:
true if this is a note, false otherwise.

isStringType

public boolean isStringType()
Return true if the type (format) of this attribute is string.

Returns:
true if this is a string, false otherwise.

isDateType

public boolean isDateType()
Return true if the type (format) of this attribute is date.

Returns:
true if this is a date, false otherwise.

compareById

public boolean compareById(java.lang.Object that)
If that is an Attribute, and has the same Id as this they are considered equal.

Specified by:
compareById in interface Identified
Parameters:
that - Object to compare with.
Returns:
true if this and that have the same Id.

setReferenceContext

public static void setReferenceContext(Type ctx)
Set the context against which references within Attributes in this thread will be evaluated. Certain properties of an Attribute may be defined outside the Attribute itself, i.e. by reference to another object. Where such a reference is used, the object which those references are evaluated against is taken to be the reference context associated with the current thread - i.e. the object passed into this method.

Parameters:
ctx - Reference context

getReferenceContext

public static Type getReferenceContext()