|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ail.core.Type
com.ail.core.Attribute
public class Attribute
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).
| 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 |
|---|
public static java.lang.String YES_OR_NO_FORMAT
| Constructor Detail |
|---|
public Attribute()
public Attribute(java.lang.String id,
java.lang.String value,
java.lang.String format)
id - Value for id propertyvalue - Value for val propertyformat - Value for type propertyunit - Value for unit property
public Attribute(java.lang.String id,
java.lang.String value,
java.lang.String format,
java.lang.String unit)
id - Value for id propertyvalue - Value for val propertyformat - Value for type propertyunit - Value for unit property| Method Detail |
|---|
public java.lang.String getId()
getId in interface Identifiedpublic void setId(java.lang.String id)
setId in interface Identifiedname - New value for the name propertypublic java.lang.String getValue()
public void setValue(java.lang.String val)
value - New value for the value propertypublic java.lang.String getFormattedValue()
public java.lang.String getFormat()
public void setFormat(java.lang.String format)
type - New value for the type propertypublic java.lang.String getUnit()
public void setUnit(java.lang.String unit)
unit - New value for the unit propertypublic java.lang.String getFormatOption(java.lang.String optionName)
public java.lang.Object getObject()
public java.lang.String getChoiceSlave()
throws java.lang.IllegalStateException
isChoiceMasterType()) then return the name of
the slave.
java.lang.IllegalStateException - if this is not a choice master.
public java.lang.String getChoiceMaster()
throws java.lang.IllegalStateException
isChoiceMasterType()) then return the name of
the master.
java.lang.IllegalStateException - if this is not a choice master.
public java.lang.String getChoiceTypeName()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if this is not a choice, or is but does not define a 'type=' option.public boolean isUndefined()
public boolean isInvalid()
public boolean isNumberType()
public boolean isChoiceType()
isFreeChoiceType()public boolean isFreeChoiceType()
public boolean isChoiceMasterType()
public boolean isChoiceSlaveType()
isChoiceMasterType()
public boolean isCurrencyType()
public boolean isYesornoType()
public boolean isNoteType()
public boolean isStringType()
public boolean isDateType()
public boolean compareById(java.lang.Object that)
compareById in interface Identifiedthat - Object to compare with.
public static void setReferenceContext(Type ctx)
ctx - Reference contextpublic static Type getReferenceContext()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||