org.norther.tammi.core.rt
Class VariableX

java.lang.Object
  extended by org.norther.tammi.core.rt.VariableX
All Implemented Interfaces:
Serializable, Cloneable, DynamicMBean, MBeanRegistration, Traceable, Identifiable, ReferableMBean, Variable
Direct Known Subclasses:
Account, MultiSelectionList, MultiSelectionTree, SearchBox, SingleSelectionList, SingleSelectionTree, VariableY

public class VariableX
extends Object
implements Variable, Identifiable, MBeanRegistration, Traceable, Serializable

A lightweight Variable implementation supporting a fixed set of dynamic attributes only. VariableX doesn't implement NotificationBroadcaster, which prevents its use with handles. The meta-data of the attribute set is locked and shared with other instances of the same virtual type by default making the memory footprint smaller.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
static String MBEAN_CONST_DESCRIPTION
          Constructor description.
static MBeanAttributeInfo[] VARIABLE_ATTRIBUTES
          Variable attributes.
static MBeanConstructorInfo[] VARIABLE_CONSTRUCTORS
          Variable constructors.
static MBeanNotificationInfo[] VARIABLE_NOTIFICATIONS
          Variable notifications.
static MBeanOperationInfo[] VARIABLE_OPERATIONS
          Variable operations.
 
Fields inherited from interface org.norther.tammi.core.rt.Variable
ADD_VALIDATED_ELEMENT, ADD_VALIDATED_ELEMENT_DESCRIPTION, APPLY_ATTRIBUTE_EXPORTER, APPLY_ATTRIBUTE_EXPORTER_DESCRIPTION, APPLY_ATTRIBUTE_IMPORTER, APPLY_ATTRIBUTE_IMPORTER_DESCRIPTION, APPLY_ATTRIBUTE_VALIDATOR, APPLY_ATTRIBUTE_VALIDATOR_DESCRIPTION, ATTRIBUTE_INFO, ATTRIBUTE_INFO_DESCRIPTION, ATTRIBUTE_LENGTH, ATTRIBUTE_LENGTH_DESCRIPTION, ATTRIBUTE_LIST, ATTRIBUTE_LIST_DESCRIPTION, CLEAR_ATTRIBUTE_VALUES, CLEAR_ATTRIBUTE_VALUES_DESCRIPTION, CONTAINS_ATTRIBUTE, CONTAINS_ATTRIBUTE_DESCRIPTION, EXPORT_ATTRIBUTES, EXPORT_ATTRIBUTES_DESCRIPTION, GET_ATTRIBUTE_VALUE, GET_ATTRIBUTE_VALUE_DESCRIPTION, GET_VALIDATED_ELEMENT, GET_VALIDATED_ELEMENT_DESCRIPTION, GET_VALIDATED_VALUE, GET_VALIDATED_VALUE_DESCRIPTION, IMPORT_ATTRIBUTES, IMPORT_ATTRIBUTES_DESCRIPTION, REMOVE_VALIDATED_ELEMENT, REMOVE_VALIDATED_ELEMENT_DESCRIPTION, RESET_VALIDATED_VALUES, RESET_VALIDATED_VALUES_DESCRIPTION, SET_ATTRIBUTE_VALUE, SET_ATTRIBUTE_VALUE_DESCRIPTION, SET_VALIDATED_ELEMENT, SET_VALIDATED_ELEMENT_DESCRIPTION, SET_VALIDATED_VALUE, SET_VALIDATED_VALUE_DESCRIPTION, VALIDATE_ATTRIBUTE_VALUES, VALIDATE_ATTRIBUTE_VALUES_DESCRIPTION, VALIDATED_VALUES, VALIDATED_VALUES_DESCRIPTION, VARIABLE_ID, VARIABLE_ID_DESCRIPTION, VARIABLE_TYPE, VARIABLE_TYPE_DESCRIPTION
 
Fields inherited from interface org.norther.tammi.core.base.ReferableMBean
DEFAULT_ID, ID, MBEAN, MBEAN_DESCRIPTION, TYPE
 
Constructor Summary
VariableX()
          Constructs a new variable.
VariableX(String type)
          Constructs a new variable with a type.
 
Method Summary
 boolean addAttributeInfo(Collection attrs)
          Adds attribute info of new attributes to this variable if they're not already present.
protected  boolean addAttributeInfoIfAbsent(Collection c)
          Adds a collection of attribute info instances without cloning.
 void addTraceListener(TraceListener listener)
          Adds a listener if not already present.
 void addValidatedElement(String name, int index, Object value)
          Adds an indexed element to an array attribute with validation.
 void addValidatedElement(String name, Object value)
          Adds an element to an array attribute with validation.
 void applyAttributeExporter(AttributeExporter exporter)
          Applies an attribute exporter.
 void applyAttributeImporter(AttributeImporter importer)
          Applies an attribute importer.
 void applyAttributeValidator(AttributeValidator validator)
          Applies an attribute validator.
 Collection attributeInfo()
          Returns attribute info of dynamic attributes of this variable.
 VariableAttributeInfo attributeInfo(String name)
          Returns attribute info for a named attribute.
 VariableAttributeInfo attributeInfo(String name, boolean unlocked)
          Returns optionally unlocked attribute info for a named attribute.
protected  void attributeInfoRegistered(VariableAttributeInfo info)
          Callback for a registered attribute info.
 int attributeLength(String name)
          Returns the length of an array attribute.
 List attributeList()
          Returns attribute info for all attributes in the definition order without internal attributes.
 List attributeList(boolean unlocked)
          Returns optionally unlocked attribute info for all attributes in the definition order without internal attributes.
 List attributeList(String group)
          Returns attribute info for attributes of the specified group in the definition order without internal attributes.
 List attributeList(String group, boolean unlocked)
          Returns optionally unlocked attribute info for attributes of the specified group in the definition order without internal attributes.
 AttributeList attributesToStrings()
          Returns values of all attributes as strings.
 void clearAttributeInfo()
          Clears attribute info of dynamic attributes of this variable.
 void clearAttributeValues()
          Clears attribute values of the current attributes.
 void clearTraceListeners()
          Clears all listeners from this traceable.
 Object clone()
          Clones this variable.
 boolean containsAttribute(String name)
          Checks whether the named attribute exists.
 AttributeList exportAttributes(Identity id, Object source, boolean foreign)
          Exports attribute values to another variable identified by the specified Identity and obtained from an external source by applying the exporter of this variable.
 AttributeList exportAttributes(Object target)
          Exports attribute values to another object.
 AttributeList exportAttributes(Object target, AttributeFilter filter)
          Exports filtered attribute values to another object.
 AttributeList exportAttributes(Variable other, Object source, boolean foreign)
          Exports attribute values to another variable obtained from an external source by applying the exporter of this variable.
 Object getAttribute(String name)
          Gets the value of the named internal or dynamic attribute without access checks and any variable specific validation.
 AttributeList getAttributes(String[] names)
          Gets the values of the named internal or dynamic attributes without access checks and any variable specific validation.
 Object getAttributeValue(String name)
          Gets the value of the named dynamic attribute without access checks and any variable specific validation.
protected  Object getAttributeValue(VariableAttributeInfo info, boolean validate)
          Gets the attribute value.
 String getCanonicalName()
          Gets the canonical object name of the MBean as a string.
protected  Object getInternalAttributeValue(VariableAttributeInfo info, boolean reset)
          Gets the internal attribute value.
 long getLastInitialized()
          Gets the timestamp of the last initialization of the traced object.
 long getLastModified()
          Gets the timestamp of the last modification of the traced object.
 long getLastModified(Object key)
          Gets the timestamp of the last modification of the specified resource.
 MBeanReference getMBean()
          Gets a reference to the MBean.
 MBeanInfo getMBeanInfo()
           
protected  MBeanServer getMBeanServer()
          Gets the MBean server.
protected  ObjectName getObjectName()
          Gets the object name.
 Object getValidatedElement(String name, int index)
          Gets the indexed element of an array attribute with validation.
 Object getValidatedValue(String name)
          Gets the value of a named dynamic attribute with validation.
 Map getValidatedValues()
          Gets attribute values as a map of name value bindings with validation.
 Object getVariableId()
          Gets the id of this variable corresponding its primary attributes.
 String getVariableType()
          Gets the type of this variable in the variable registry.
 AttributeList importAttributes(Identity id, Object source, boolean foreign)
          Imports attribute values from another variable identified by the specified Identity and obtained from an external source by applying the importer of this variable.
 AttributeList importAttributes(Object source)
          Imports attribute values from another object.
 AttributeList importAttributes(Object source, AttributeFilter filter)
          Imports filtered attribute values from another object.
 AttributeList importAttributes(Variable other, Object source, boolean foreign)
          Imports attribute values from another variable obtained from an external source by applying the importer of this variable.
 Object invoke(String name, Object[] params, String[] signature)
           
 boolean isEmpty()
          Checks whether this variable contains any attributes.
 boolean isModifiable()
          Checks whether attribute definitions can be modified during run-time.
 void postDeregister()
           
 void postRegister(Boolean done)
           
 void preDeregister()
           
 ObjectName preRegister(MBeanServer server, ObjectName name)
           
protected  Object putAttributeValue(VariableAttributeInfo info, Object value, boolean validate)
          Sets the attribute value with validation.
protected  Object putInternalAttributeValue(VariableAttributeInfo info, Object value, boolean reset)
          Puts the internal attribute value.
protected  Object putInternalAttributeValue(VariableAttributeInfo info, Object value, long timestamp, boolean reset)
          Puts the internal attribute value with a modification timestamp.
protected  void registerAttributeInfo(OrderedMap map)
          Sets the attribute info map.
protected  void registerVariable(String type)
          Registers the type of the variable in the variable registry.
 void removeTraceListener(TraceListener listener)
          Removes a listener.
 Object removeValidatedElement(String name, int index)
          Removes the indexed element from an array attribute.
 boolean removeValidatedElement(String name, Object value)
          Removes an element from an array attribute.
 void replaceAttributeInfo(Collection attrs)
          Replaces attribute info of dynamic attributes of this variable.
 Map resetValidatedValues(Map attributes)
          Resets attribute values in a map of name value bindings with validation.
 void sendNotification(String message, String name, String type, Object oldValue, Object newValue)
          Sends a modification notification.
 void setAttribute(Attribute attr)
          Sets the value of the given internal or dynamic attribute without access checks and any variable specific validation.
protected  void setAttributeElement(VariableAttributeInfo info, int index, boolean add, Object value)
          Sets the indexed attribute value with full validation.
 AttributeList setAttributes(AttributeList attrs)
          Sets the values of the listed internal or dynamic attributes without access checks and any variable specific validation.
 void setAttributeValue(String name, Object value)
          Sets the value of the named dynamic attribute without access checks and any variable specific validation.
 void setCanonicalName(String name)
          Sets the canonical object name of the MBean as a string.
protected  void setInternalAttributeElement(VariableAttributeInfo info, int index, boolean add, Object value)
          Sets the indexed internal attribute value.
 void setLastModified(Object key, long timestamp)
          Sets the timestamp of the last modification of the specified resource.
protected  void setObjectName(ObjectName name)
          Sets the object name.
 void setValidatedElement(String name, int index, Object value)
          Sets the indexed element of an array attribute with validation.
 void setValidatedValue(String name, Object value)
          Sets the value of an attribute as a name value pair with validation.
 void setValidatedValues(Map attributes)
          Sets attribute values in a map of name value bindings with validation.
 void setVariableId(Object id)
          Sets the id of this variable corresponding its primary attributes.
protected  Map validateAttributes(Map attributes, OrderedMap valid)
          Validates attribute values in a map of name value bindings.
protected  Object validateAttributeValue(VariableAttributeInfo info, Object value)
          Validates the attribute value by meta-data with run-time exceptions.
 Map validateAttributeValues()
          Validates attribute values of the current attributes.
 Map validateAttributeValues(Map attributes)
          Validates attribute values in a map of name value bindings.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MBEAN_CONST_DESCRIPTION

public static final String MBEAN_CONST_DESCRIPTION
Constructor description.

See Also:
Constant Field Values

VARIABLE_CONSTRUCTORS

public static final MBeanConstructorInfo[] VARIABLE_CONSTRUCTORS
Variable constructors.


VARIABLE_ATTRIBUTES

public static final MBeanAttributeInfo[] VARIABLE_ATTRIBUTES
Variable attributes.


VARIABLE_OPERATIONS

public static final MBeanOperationInfo[] VARIABLE_OPERATIONS
Variable operations.


VARIABLE_NOTIFICATIONS

public static final MBeanNotificationInfo[] VARIABLE_NOTIFICATIONS
Variable notifications.

Constructor Detail

VariableX

public VariableX()
Constructs a new variable.


VariableX

public VariableX(String type)
Constructs a new variable with a type.

Parameters:
type - the variable type.
Method Detail

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws Exception
Specified by:
preRegister in interface MBeanRegistration
Throws:
Exception

postRegister

public void postRegister(Boolean done)
Specified by:
postRegister in interface MBeanRegistration

preDeregister

public void preDeregister()
                   throws Exception
Specified by:
preDeregister in interface MBeanRegistration
Throws:
Exception

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface MBeanRegistration

clone

public Object clone()
Description copied from interface: Variable
Clones this variable. The new variable contains the same attributes as the original one. The attribute values themselves are not cloned.

Specified by:
clone in interface Variable
Overrides:
clone in class Object
Returns:
a clone of this variable.

getMBean

public MBeanReference getMBean()
Description copied from interface: ReferableMBean
Gets a reference to the MBean.

Specified by:
getMBean in interface ReferableMBean
Returns:
a reference to the MBean.

getAttribute

public Object getAttribute(String name)
                    throws AttributeNotFoundException,
                           ReflectionException,
                           MBeanException
Description copied from interface: Variable
Gets the value of the named internal or dynamic attribute without access checks and any variable specific validation.

Specified by:
getAttribute in interface DynamicMBean
Specified by:
getAttribute in interface Variable
Parameters:
name - the attribute name.
Returns:
the attribute value.
Throws:
AttributeNotFoundException - if the name is unknown.
ReflectionException - if a getter is not found.
MBeanException - if getting of the value fails.

setAttribute

public void setAttribute(Attribute attr)
                  throws AttributeNotFoundException,
                         InvalidAttributeValueException,
                         ReflectionException,
                         MBeanException
Description copied from interface: Variable
Sets the value of the given internal or dynamic attribute without access checks and any variable specific validation.

Specified by:
setAttribute in interface DynamicMBean
Specified by:
setAttribute in interface Variable
Parameters:
attr - the attribute to set.
Throws:
AttributeNotFoundException - if the name is unknown.
InvalidAttributeValueException - if the value is invalid.
ReflectionException - if a getter is not found.
MBeanException - if getting of the value fails.

getAttributes

public AttributeList getAttributes(String[] names)
Description copied from interface: Variable
Gets the values of the named internal or dynamic attributes without access checks and any variable specific validation.

Specified by:
getAttributes in interface DynamicMBean
Specified by:
getAttributes in interface Variable
Parameters:
names - an array of attribute names.
Returns:
a list of name-value pairs.

setAttributes

public AttributeList setAttributes(AttributeList attrs)
Description copied from interface: Variable
Sets the values of the listed internal or dynamic attributes without access checks and any variable specific validation.

Specified by:
setAttributes in interface DynamicMBean
Specified by:
setAttributes in interface Variable
Parameters:
attrs - the attributes to set.
Returns:
a list of set name-value pairs.

getAttributeValue

public Object getAttributeValue(String name)
                         throws AttributeNotFoundException
Description copied from interface: Variable
Gets the value of the named dynamic attribute without access checks and any variable specific validation.

Specified by:
getAttributeValue in interface Variable
Parameters:
name - the attribute name.
Returns:
the attribute value.
Throws:
AttributeNotFoundException - if the name is unknown.

setAttributeValue

public void setAttributeValue(String name,
                              Object value)
                       throws AttributeNotFoundException,
                              InvalidAttributeValueException
Description copied from interface: Variable
Sets the value of the named dynamic attribute without access checks and any variable specific validation.

Specified by:
setAttributeValue in interface Variable
Parameters:
name - the attribute name.
value - the attribute value.
Throws:
AttributeNotFoundException - if the name is unknown.
InvalidAttributeValueException - if the value is invalid.

getValidatedValues

public Map getValidatedValues()
Description copied from interface: Variable
Gets attribute values as a map of name value bindings with validation. Only dynamic attributes are included in the map.

Specified by:
getValidatedValues in interface Variable
Returns:
a map of attribute values.

setValidatedValues

public void setValidatedValues(Map attributes)
Description copied from interface: Variable
Sets attribute values in a map of name value bindings with validation. Only known dynamic attributes are set, others skipped.

Specified by:
setValidatedValues in interface Variable
Parameters:
attributes - the attributes map.

resetValidatedValues

public Map resetValidatedValues(Map attributes)
Description copied from interface: Variable
Resets attribute values in a map of name value bindings with validation. Only known dynamic attributes are set, others skipped.

Invalid attributes are returned in a map binding an invalid attribute name to a validation exception. An empty map indicates that all attributes were valid.

Note that if the attributes map does not contain any settable values, null is returned.

Specified by:
resetValidatedValues in interface Variable
Parameters:
attributes - the attributes map.
Returns:
a map of invalid attributes, an empty map or null.

validateAttributeValues

public Map validateAttributeValues(Map attributes)
Description copied from interface: Variable
Validates attribute values in a map of name value bindings. Only known dynamic attributes are validated, others skipped.

Invalid attributes are returned in a map binding an invalid attribute name to a validation exception. An empty map indicates that all attributes were valid.

Note that if the attributes map does not contain any settable values, null is returned.

Specified by:
validateAttributeValues in interface Variable
Parameters:
attributes - the attributes map.
Returns:
a map of invalid attributes, an empty map or null.

validateAttributeValues

public Map validateAttributeValues()
Description copied from interface: Variable
Validates attribute values of the current attributes. Only dynamic writable attributes are validated, others skipped.

Invalid attributes are returned in a map binding an invalid attribute name to a validation exception. An empty map indicates that all attributes were valid.

Specified by:
validateAttributeValues in interface Variable
Returns:
a map of invalid attributes or an empty map.

clearAttributeValues

public void clearAttributeValues()
Description copied from interface: Variable
Clears attribute values of the current attributes. Only dynamic writable attributes are cleared, others skipped.

Specified by:
clearAttributeValues in interface Variable

getValidatedValue

public Object getValidatedValue(String name)
                         throws AttributeNotFoundException
Description copied from interface: Variable
Gets the value of a named dynamic attribute with validation.

Specified by:
getValidatedValue in interface Variable
Parameters:
name - the attribute name.
Returns:
the attribute value.
Throws:
AttributeNotFoundException - if the name is unknown.

setValidatedValue

public void setValidatedValue(String name,
                              Object value)
                       throws AttributeNotFoundException,
                              InvalidAttributeValueException
Description copied from interface: Variable
Sets the value of an attribute as a name value pair with validation. Only dynamic attributes can be set as a name value pair.

Specified by:
setValidatedValue in interface Variable
Parameters:
name - the attribute name.
value - the attribute value.
Throws:
AttributeNotFoundException - if the name is unknown.
InvalidAttributeValueException - if the value is invalid.

getValidatedElement

public Object getValidatedElement(String name,
                                  int index)
                           throws AttributeNotFoundException
Description copied from interface: Variable
Gets the indexed element of an array attribute with validation.

Specified by:
getValidatedElement in interface Variable
Parameters:
name - the attribute name.
index - the element index.
Returns:
the value of the element.
Throws:
AttributeNotFoundException - if the name is unknown.

setValidatedElement

public void setValidatedElement(String name,
                                int index,
                                Object value)
                         throws AttributeNotFoundException,
                                InvalidAttributeValueException
Description copied from interface: Variable
Sets the indexed element of an array attribute with validation.

Specified by:
setValidatedElement in interface Variable
Parameters:
name - the attribute name.
index - the element index.
value - the value of the element.
Throws:
AttributeNotFoundException - if the name is unknown.
InvalidAttributeValueException - if the value is invalid.

addValidatedElement

public void addValidatedElement(String name,
                                Object value)
                         throws AttributeNotFoundException,
                                InvalidAttributeValueException
Description copied from interface: Variable
Adds an element to an array attribute with validation.

Specified by:
addValidatedElement in interface Variable
Parameters:
name - the attribute name.
value - the value of the element.
Throws:
AttributeNotFoundException - if the name is unknown.
InvalidAttributeValueException - if the value is invalid.

addValidatedElement

public void addValidatedElement(String name,
                                int index,
                                Object value)
                         throws AttributeNotFoundException,
                                InvalidAttributeValueException
Description copied from interface: Variable
Adds an indexed element to an array attribute with validation.

Specified by:
addValidatedElement in interface Variable
Parameters:
name - the attribute name.
index - the element index.
value - the value of the element.
Throws:
AttributeNotFoundException - if the name is unknown.
InvalidAttributeValueException - if the value is invalid.

removeValidatedElement

public boolean removeValidatedElement(String name,
                                      Object value)
                               throws AttributeNotFoundException
Description copied from interface: Variable
Removes an element from an array attribute.

Specified by:
removeValidatedElement in interface Variable
Parameters:
name - the attribute name.
value - the value of the element.
Returns:
true if removed.
Throws:
AttributeNotFoundException - if the name is unknown.

removeValidatedElement

public Object removeValidatedElement(String name,
                                     int index)
                              throws AttributeNotFoundException
Description copied from interface: Variable
Removes the indexed element from an array attribute.

Specified by:
removeValidatedElement in interface Variable
Parameters:
name - the attribute name.
index - the element index.
Returns:
the removed value of the element.
Throws:
AttributeNotFoundException - if the name is unknown.

attributeLength

public int attributeLength(String name)
                    throws AttributeNotFoundException
Description copied from interface: Variable
Returns the length of an array attribute.

Specified by:
attributeLength in interface Variable
Parameters:
name - the attribute name.
Returns:
the attribute array length.
Throws:
AttributeNotFoundException - if the name is unknown.

containsAttribute

public boolean containsAttribute(String name)
Description copied from interface: Variable
Checks whether the named attribute exists.

Specified by:
containsAttribute in interface Variable
Parameters:
name - the name of the attribute.
Returns:
true if found, otherwise false.

attributeInfo

public VariableAttributeInfo attributeInfo(String name)
Description copied from interface: Variable
Returns attribute info for a named attribute.

Specified by:
attributeInfo in interface Variable
Parameters:
name - the name of the attribute.
Returns:
the attribute info or null if not found.

attributeInfo

public VariableAttributeInfo attributeInfo(String name,
                                           boolean unlocked)
Description copied from interface: Variable
Returns optionally unlocked attribute info for a named attribute.

Specified by:
attributeInfo in interface Variable
Parameters:
name - the name of the attribute.
unlocked - true for unlocked, false otherwise.
Returns:
the attribute info or null if not found.

attributeList

public List attributeList()
Description copied from interface: Variable
Returns attribute info for all attributes in the definition order without internal attributes.

Specified by:
attributeList in interface Variable
Returns:
a read-only list of VariableAttributeInfo instances.

attributeList

public List attributeList(boolean unlocked)
Description copied from interface: Variable
Returns optionally unlocked attribute info for all attributes in the definition order without internal attributes.

Specified by:
attributeList in interface Variable
Parameters:
unlocked - true for unlocked, false otherwise.
Returns:
a read-only list of VariableAttributeInfo instances.

attributeList

public List attributeList(String group)
Description copied from interface: Variable
Returns attribute info for attributes of the specified group in the definition order without internal attributes.

Specified by:
attributeList in interface Variable
Parameters:
group - the group.
Returns:
a list of VariableAttributeInfo instances.

attributeList

public List attributeList(