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>, Variable
Direct Known Subclasses:
AbstractSelectionList, AbstractSelectionTree, SearchBox, TableSelectionList, VariableY

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

A lightweight Variable implementation supporting a fixed set of dynamic attributes by default. 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 making the memory footprint smaller.

Version:
$Id: VariableX.java,v 1.150 2010-06-29 18:29:33 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.norther.tammi.core.rt.Variable
ADD_ATTRIBUTE_ELEMENT, ADD_ATTRIBUTE_INFO, ADD_VALIDATED_ELEMENT, ATTRIBUTE_ELEMENT_SEPARATOR, ATTRIBUTE_INFO, ATTRIBUTE_LENGTH, ATTRIBUTE_LIST, ATTRIBUTE_POSITION, ATTRIBUTE_VALUES, CLEAR_ATTRIBUTE_INFO, CLEAR_ATTRIBUTE_VALUES, CONTAINS_ATTRIBUTE, CONTAINS_TRAIT, EXPORT_ATTRIBUTES, GET_ATTRIBUTE_ELEMENT, GET_ATTRIBUTE_VALUE, GET_RECURSIVE_ELEMENT, GET_RECURSIVE_VALUE, GET_VALIDATED_ELEMENT, GET_VALIDATED_VALUE, ID, ID_ATTRIBUTE_LIST, IMPORT_ATTRIBUTES, REMOVE_ATTRIBUTE_ELEMENT, REMOVE_VALIDATED_ELEMENT, REPLACE_ATTRIBUTE_INFO, RESET_VALIDATED_VALUES, SET_ATTRIBUTE_ELEMENT, SET_ATTRIBUTE_VALUE, SET_ATTRIBUTE_VALUES, SET_VALIDATED_ELEMENT, SET_VALIDATED_VALUE, TYPE, VALIDATE_ATTRIBUTE_VALUES, VALIDATED_VALUES, VARIABLE_INFO
 
Fields inherited from interface org.norther.tammi.core.base.ReferableMBean
MBEAN, NS
 
Constructor Summary
  VariableX()
          Constructs a new variable.
protected VariableX(String type)
          Constructs a new variable with a virtual type.
  VariableX(String type, MBeanReference<? extends VariableRegistry> vr)
          Constructs a new variable with a virtual type from the specified registry.
 
Method Summary
 void addAttributeElement(String name, int index, Object value)
          Adds an indexed element to an array attribute without validation.
 void addAttributeElement(String name, Object value)
          Adds an element to an array attribute without validation.
 boolean addAttributeInfo(Collection<? extends MBeanFeatureInfo> attrs, int... position)
          Adds attribute info of new attributes to this variable if they're not already present.
protected  boolean addAttributeInfoIfAbsent(int position, Collection<VariableAttributeInfo> 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, Object... localization)
          Adds an indexed element to a dynamic array attribute with validation.
 void addValidatedElement(String name, Object... localizedValue)
          Adds an element to a dynamic array attribute with validation.
 Collection<VariableAttributeInfo> attributeInfo()
          Returns attribute info of dynamic attributes of this variable.
 VariableAttributeInfo attributeInfo(String name, boolean... modifiable)
          Returns optionally modifiable or recursive attribute info of a named attribute.
protected  void attributeInfoRegistered(int position, VariableAttributeInfo info)
          Callback for a registered attribute info.
 int attributeLength(String name)
          Returns the length of an array attribute.
 List<VariableAttributeInfo> attributeList(boolean... modifiable)
          Returns optionally modifiable attribute info of all attributes in the definition order without internal attributes.
 int attributePosition(String name)
          Returns the position of the named attribute.
 void clearAttributeInfo()
          Clears attribute info of dynamic attributes of this variable.
 void clearAttributeValues()
          Clears attribute values of the current attributes.
 void clearLastModified()
          Clears the timestamp of the last modification of the traced object.
 void clearTraceListeners()
          Clears all listeners from this traceable.
 Object clone()
          Clones this variable.
 boolean containsAttribute(String name)
          Checks whether the named attribute exists.
 boolean containsTrait(VariableAttributeInfo.Trait trait)
          Checks whether the specified trait is permanently on in any of the attributes.
 boolean equals(Object other)
           
 AttributeList exportAttributes(Object target, AttributeFilter... filter)
          Exports filtered attribute values to another object.
 Object getAttribute(String name)
          Gets the value of the named internal or dynamic attribute without access checks and any variable specific validation.
 Object getAttributeElement(String name, int index)
          Gets the indexed element of an array attribute without validation.
 AttributeList getAttributes(String[] names)
          Gets the values of the named internal or dynamic attributes without access checks and any variable specific validation.
protected  Object getAttributeValue(int position, VariableAttributeInfo info, boolean validate)
          Gets the attribute value.
 Object getAttributeValue(String name)
          Gets the value of the named dynamic attribute without access checks and any variable specific validation.
 Map<String,Object> getAttributeValues()
          Gets attribute values as a map of name value bindings without validation.
protected  Map<String,Object> getAttributeValues(boolean validate, AttributeFilter... filter)
          Gets attribute values.
 String getCanonicalName()
          Gets the canonical object name of the MBean as a string.
 Object getId()
          Gets the id of this variable corresponding to its primary attributes.
protected  Object getInternalAttributeValue(int position, VariableAttributeInfo info, boolean reset)
          Gets the internal attribute value.
 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<Variable> getMBean()
          Gets a reference to the MBean.
 MBeanInfo getMBeanInfo()
           
protected  MBeanServer getMBeanServer()
          Gets the MBean server.
protected  ObjectName getObjectName()
          Gets the object name.
 Object getRecursiveElement(String name, int index, String... pattern)
          Gets the first non-recursive indexed element of an recursive dynamic array attribute with validation.
 Object getRecursiveValue(String name, String... pattern)
          Gets the first non-recursive value of a named recursive dynamic attribute with validation.
 String getType()
          Gets the type of this variable.
 Object getValidatedElement(String name, int index)
          Gets the indexed element of a dynamic array attribute with validation.
 Object getValidatedValue(String name)
          Gets the value of a named dynamic attribute with validation.
 List<VariableAttributeInfo> idAttributeList()
          Returns attribute info of id attributes in the definition order.
 AttributeList importAttributes(Object source, AttributeFilter... filter)
          Imports filtered attribute values from another object.
 Object invoke(String name, Object[] params, String[] signature)
           
 boolean isEmpty()
          Checks whether this variable contains any attributes.
 void postDeregister()
           
 void postRegister(Boolean done)
           
 void preDeregister()
           
 ObjectName preRegister(MBeanServer server, ObjectName name)
           
protected  void putAttributeElement(int position, VariableAttributeInfo info, int index, boolean add, Object value, boolean validate, Object... localization)
          Puts the indexed attribute element with optional validation.
protected  Object putAttributeValue(int position, VariableAttributeInfo info, Object value, boolean validate, Object... localization)
          Puts the attribute value with optional validation.
protected  boolean putAttributeValues(Map<?,?> attributes, boolean localize, AttributeFilter af, Object... localization)
          Puts attribute values.
protected  Object putInternalAttributeValue(int position, VariableAttributeInfo info, Object value, boolean reset)
          Puts the internal attribute value.
protected  Object putInternalAttributeValue(int position, VariableAttributeInfo info, Object value, long timestamp, boolean reset)
          Puts the internal attribute value with a modification timestamp.
protected  void registerAttributeInfo(VariableInfo meta)
          Registers attribute info.
protected  Object[] removeAttributeElement(int position, VariableAttributeInfo info, int index, Object value, boolean validate, Object... localization)
          Removes the specified attribute element with optional validation.
 Object removeAttributeElement(String name, int index)
          Removes the indexed element from an array attribute without validation.
 boolean removeAttributeElement(String name, Object value)
          Removes an element from an array attribute without validation.
 void removeTraceListener(TraceListener listener)
          Removes a listener.
 Object removeValidatedElement(String name, int index, Object... localization)
          Removes the indexed element from a dynamic array attribute with validation.
 boolean removeValidatedElement(String name, Object... localizedValue)
          Removes an element from a dynamic array attribute with validation.
 void replaceAttributeInfo(Collection<? extends MBeanFeatureInfo> attrs)
          Replaces attribute info of dynamic attributes of this variable.
 SortedMap<String,Exception> resetValidatedValues(Map<?,?> attributes, Object... localization)
          Resets attribute values in a map of name value bindings with validation.
 void sendNotification(String message, String name, String type, Object... values)
          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(int position, VariableAttributeInfo info, int index, boolean add, Object value, boolean validate, Object... localization)
          Sets the indexed attribute element with optional validation.
 void setAttributeElement(String name, int index, Object value)
          Sets the indexed element of an array attribute without 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 setAttributeValues(Map<?,?> attributes)
          Sets attribute values in a map of name value bindings without validation.
 void setAttributeValues(Map<?,?> attributes, Object... localization)
          Sets attribute values in a map of name value bindings without validation.
 void setCanonicalName(String name)
          Sets the canonical object name of the MBean as a string.
 void setId(Object id)
          Sets the id of this variable corresponding to its primary attributes.
 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, Object... localization)
          Sets the indexed element of a dynamic array attribute with validation.
 void setValidatedValue(String name, Object value, Object... localization)
          Sets the value of an attribute as a name value pair with validation.
 String toString()
           
protected  Object validateAttributeValue(VariableAttributeInfo info, Object value, Object... localization)
          Validates an attribute value by accessors and meta-data with run-time exceptions.
 SortedMap<String,Exception> validateAttributeValues()
          Validates attribute values of the current attributes.
protected  SortedMap<String,Exception> validateAttributeValues(List<Variable> nested, Map<?,?> attributes, OrderedMap<String,Object> validated, Object... localization)
          Validates attribute values in a map of name value bindings.
 SortedMap<String,Exception> validateAttributeValues(Map<?,?> attributes, Object... localization)
          Validates attribute values in a map of name value bindings.
 Map<String,Object> validatedValues(AttributeFilter... filter)
          Returns validated attribute values as a map of name value bindings.
protected  void validateMandatoryValue(VariableAttributeInfo info, int index, Object value)
          Validates a mandatory attribute value with run-time exceptions.
 VariableInfo variableInfo(boolean... modifiable)
          Returns optionally modifiable variable info of this variable.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VariableX

public VariableX()
Constructs a new variable.


VariableX

public VariableX(String type,
                 MBeanReference<? extends VariableRegistry> vr)
Constructs a new variable with a virtual type from the specified registry.

Parameters:
type - the variable type.
vr - the variable registry.

VariableX

protected VariableX(String type)
Constructs a new variable with a virtual type.

Parameters:
type - the variable type.
Method Detail

equals

public boolean equals(Object other)
Overrides:
equals in class Object

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

toString

public String toString()
Overrides:
toString in class Object

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<Variable> getMBean()
Description copied from interface: ReferableMBean
Gets a reference to the MBean.

Specified by:
getMBean in interface ReferableMBean<Variable>
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.

getAttributeValues

public Map<String,Object> getAttributeValues()
Description copied from interface: Variable
Gets attribute values as a map of name value bindings without validation. Only dynamic attributes are included in the map.

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

setAttributeValues

public void setAttributeValues(Map<?,?> attributes)
                        throws InvalidAttributeValueException
Description copied from interface: Variable
Sets attribute values in a map of name value bindings without validation. Only known dynamic attributes are set, others skipped. Indexed attribute elements may be defined by appending the index to the attribute name separated by a hyphen.

This method provides compatibility with bean accessors.

Specified by:
setAttributeValues in interface Variable
Parameters:
attributes - the attributes map.
Throws:
InvalidAttributeValueException - if values are invalid.

setAttributeValues

public void setAttributeValues(Map<?,?> attributes,
                               Object... localization)
                        throws InvalidAttributeValueException
Description copied from interface: Variable
Sets attribute values in a map of name value bindings without validation. Only known dynamic attributes are set, others skipped. Indexed attribute elements may be defined by appending the index to the attribute name separated by a hyphen.

Specified by:
setAttributeValues in interface Variable
Parameters:
attributes - the attributes map.
localization - optional base name, resource bundle and locale.
Throws:
InvalidAttributeValueException - if values are invalid.

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.

getAttributeElement

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

Specified by:
getAttributeElement 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.

setAttributeElement

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

Specified by:
setAttributeElement 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.

addAttributeElement

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

Specified by:
addAttributeElement 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.

addAttributeElement

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

Specified by:
addAttributeElement 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.

removeAttributeElement

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

Specified by:
removeAttributeElement 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.

removeAttributeElement

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

Specified by:
removeAttributeElement 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.

validatedValues

public Map<String,Object> validatedValues(AttributeFilter... filter)
Description copied from interface: Variable
Returns validated attribute values as a map of name value bindings. Only dynamic attributes are included in the map.

Specified by:
validatedValues in interface Variable
Parameters:
filter - an optional filter.
Returns:
a map of attribute values.

resetValidatedValues

public SortedMap<String,Exception> resetValidatedValues(Map<?,?> attributes,
                                                        Object... localization)
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. Indexed attribute elements may be defined by appending the index to the attribute name separated by a hyphen.

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.
localization - optional base name, resource bundle and locale.
Returns:
a map of invalid attributes, an empty map or null.

validateAttributeValues

public SortedMap<String,Exception> validateAttributeValues(Map<?,?> attributes,
                                                           Object... localization)
Description copied from interface: Variable
Validates attribute values in a map of name value bindings. Only known dynamic attributes are validated, others skipped. Indexed attribute elements may be defined by appending the index to the attribute name separated by a hyphen.

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.
localization - optional base name, resource bundle and locale.
Returns:
a map of invalid attributes, an empty map or null.

validateAttributeValues

public SortedMap<String,Exception> 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,
                              Object... localization)
                       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.
localization - optional base name, resource bundle and locale.
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 a dynamic 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,
                                Object... localization)
                         throws AttributeNotFoundException,
                                InvalidAttributeValueException
Description copied from interface: Variable
Sets the indexed element of a dynamic 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.
localization - optional base name, resource bundle and locale.
Throws:
AttributeNotFoundException - if the name is unknown.
InvalidAttributeValueException - if the value is invalid.

addValidatedElement

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

Specified by:
addValidatedElement in interface Variable
Parameters:
name - the attribute name.
localizedValue - the value of the element and optional base name, resource bundle and locale.
Throws:
AttributeNotFoundException - if the name is unknown.
InvalidAttributeValueException - if the value is invalid.

addValidatedElement

public void addValidatedElement(String name,
                                int index,
                                Object value,
                                Object... localization)
                         throws AttributeNotFoundException,
                                InvalidAttributeValueException
Description copied from interface: Variable
Adds an indexed element to a dynamic 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.
localization - optional base name, resource bundle and locale.
Throws:
AttributeNotFoundException - if the name is unknown.
InvalidAttributeValueException - if the value is invalid.

removeValidatedElement

public boolean removeValidatedElement(String name,
                                      Object... localizedValue)
                               throws AttributeNotFoundException
Description copied from interface: Variable
Removes an element from a dynamic array attribute with validation.

Nota that Java things that separate localization would be ambiguous with the indexed alternative to remove elements.

Specified by:
removeValidatedElement in interface Variable
Parameters:
name - the attribute name.
localizedValue - the value of the element and optional base name, resource bundle and locale.
Returns:
true if removed.
Throws:
AttributeNotFoundException - if the name is unknown.

removeValidatedElement

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

Specified by:
removeValidatedElement in interface Variable
Parameters:
name - the attribute name.
index - the element index.
localization - optional base name, resource bundle and locale.
Returns:
the removed value of the element.
Throws:
AttributeNotFoundException - if the name is unknown.

getRecursiveValue

public Object getRecursiveValue(String name,
                                String... pattern)
                         throws AttributeNotFoundException
Description copied from interface: Variable
Gets the first non-recursive value of a named recursive dynamic attribute with validation.

Specified by:
getRecursiveValue in interface Variable
Parameters:
name - the attribute name.
pattern - an optional pattern
Returns:
the attribute value.
Throws:
AttributeNotFoundException - if the name is unknown.

getRecursiveElement

public Object getRecursiveElement(String name,
                                  int index,
                                  String... pattern)
                           throws AttributeNotFoundException
Description copied from interface: Variable
Gets the first non-recursive indexed element of an recursive dynamic array attribute with validation.

Specified by:
getRecursiveElement in interface Variable
Parameters:
name - the attribute name.
index - the element index.
pattern - an optional pattern
Returns:
the 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.

variableInfo

public VariableInfo variableInfo(boolean... modifiable)
Description copied from interface: Variable
Returns optionally modifiable variable info of this variable.

Specified by:
variableInfo in interface Variable
Parameters:
modifiable - true to get modifiable info, false otherwise.
Returns:
the variable info.

attributeInfo

public Collection<VariableAttributeInfo> attributeInfo()
Description copied from interface: Variable
Returns attribute info of dynamic attributes of this variable.

Specified by:
attributeInfo in interface Variable
Returns:
a modifiable collection of VariableAttributeInfo instances.

addAttributeInfo

public boolean addAttributeInfo(Collection<? extends MBeanFeatureInfo> attrs,
                                int... position)
Description copied from interface: Variable
Adds attribute info of new attributes to this variable if they're not already present.

Specified by:
addAttributeInfo in interface Variable
Parameters:
attrs - a collection of MBeanFeatureInfo instances.
position - the attribute position (-1 = at the end).
Returns:
true if new attributes were added, otherwise false.

replaceAttributeInfo

public void replaceAttributeInfo(Collection<? extends MBeanFeatureInfo> attrs)
Description copied from interface: Variable
Replaces attribute info of dynamic attributes of this variable.

Specified by:
replaceAttributeInfo in interface Variable
Parameters:
attrs - a collection of MBeanFeatureInfo instances.

clearAttributeInfo

public void clearAttributeInfo()
Description copied from interface: Variable
Clears attribute info of dynamic attributes of this variable.

Specified by:
clearAttributeInfo in interface Variable

attributeList

public List<VariableAttributeInfo> attributeList(boolean... modifiable)
Description copied from interface: Variable
Returns optionally modifiable attribute info of all attributes in the definition order without internal attributes.

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

attributeInfo

public VariableAttributeInfo attributeInfo(String name,
                                           boolean... modifiable)
Description copied from interface: Variable
Returns optionally modifiable or recursive attribute info of a named attribute.

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

idAttributeList

public List<VariableAttributeInfo> idAttributeList()
Description copied from interface: Variable
Returns attribute info of id attributes in the definition order.

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

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.

containsTrait

public boolean containsTrait(VariableAttributeInfo.Trait trait)
Description copied from interface: Variable
Checks whether the specified trait is permanently on in any of the attributes.

Note that attributs of recursive elements are scanned, too.

Specified by:
containsTrait in interface Variable
Parameters:
trait - the trait to check.
Returns:
true if found, otherwise false.

attributePosition

public int attributePosition(String name)
Description copied from interface: Variable
Returns the position of the named attribute.

Specified by:
attributePosition in interface Variable
Parameters:
name - the attribute name.
Returns:
the position of the atribute or -1 if not found.

getType

public String getType()
Description copied from interface: Variable
Gets the type of this variable.

Specified by:
getType in interface Variable
Returns:
the type.

getId

public Object getId()
Description copied from interface: Variable
Gets the id of this variable corresponding to its primary attributes. The id may be a single value, an object array or null.

Specified by:
getId in interface Variable
Returns:
the id or null if not defined.

setId

public void setId(Object id)
           throws AttributeNotFoundException,
                  InvalidAttributeValueException
Description copied from interface: Variable
Sets the id of this variable corresponding to its primary attributes. The id may be a single value, an object array or null.

Note that ids of recursive elements are nullified, too.

Specified by:
setId in interface Variable
Parameters:
id - the id or null if not defined.
Throws:
AttributeNotFoundException - if the id is unknown.
InvalidAttributeValueException - if the id is invalid.

importAttributes

public AttributeList importAttributes(Object source,
                                      AttributeFilter... filter)
Description copied from interface: Variable
Imports filtered attribute values from another object. The object can be an object name of an MBean, a reference to another variable or any Java object. Attributes not compatible with attributes of this variable are not imported.

Note that attributes of compatible types are accepted directly without validation.

Specified by:
importAttributes in interface Variable
Parameters:
source - the source object.
filter - an optional attribute filter to apply.
Returns:
a list of imported attributes.

exportAttributes

public AttributeList exportAttributes(Object target,
                                      AttributeFilter... filter)
Description copied from interface: Variable
Exports filtered attribute values to another object. The object can be an object name of an MBean, a reference to another variable or any Java object. Attributes not compatible with attributes of this variable are not exported.

Specified by:
exportAttributes in interface Variable
Parameters:
target - the target object.
filter - an optional attribute filter to apply.
Returns:
a list of exported attributes.

invoke

public Object invoke(String name,
                     Object[] params,
                     String[] signature)
              throws MBeanException,
                     ReflectionException
Specified by:
invoke in interface DynamicMBean
Throws:
MBeanException
ReflectionException

getMBeanInfo

public MBeanInfo getMBeanInfo()
Specified by:
getMBeanInfo in interface DynamicMBean

getCanonicalName

public String getCanonicalName()
Description copied from interface: Identifiable
Gets the canonical object name of the MBean as a string.

Specified by:
getCanonicalName in interface Identifiable
Returns:
the canonical object name as a string or null.

setCanonicalName

public void setCanonicalName(String name)
                      throws MalformedObjectNameException
Description copied from interface: Identifiable
Sets the canonical object name of the MBean as a string. The canonical object name can be used by persistence mechanisms to store the identity of the MBean.

Specified by:
setCanonicalName in interface Identifiable
Parameters:
name - the canonical object name as a string.
Throws:
MalformedObjectNameException - for an invalid name.

getLastModified

public long getLastModified()
Description copied from interface: Traceable
Gets the timestamp of the last modification of the traced object.

Specified by:
getLastModified in interface Traceable
Returns:
the modification timestamp.

getLastModified

public long getLastModified(Object key)
Description copied from interface: Traceable
Gets the timestamp of the last modification of the specified resource.

Specified by:
getLastModified in interface Traceable
Parameters:
key - the key of the resource.
Returns:
the modification timestamp.

setLastModified

public void setLastModified(Object key,
                            long timestamp)
Description copied from interface: Traceable
Sets the timestamp of the last modification of the specified resource. This is a clumsy way to maintain original timestamps of resources copied between objects, so implementors are encouraged to provide timestamped setters to be applied instead of this method.

Specified by:
setLastModified in interface Traceable
Parameters:
key - the key of the resource.
timestamp - the modification timestamp.

clearLastModified

public void clearLastModified()
Description copied from interface: Traceable
Clears the timestamp of the last modification of the traced object.

Specified by:
clearLastModified in interface Traceable

addTraceListener

public void addTraceListener(TraceListener listener)
Description copied from interface: Traceable
Adds a listener if not already present.

Specified by:
addTraceListener in interface Traceable
Parameters:
listener - a listener to add.

removeTraceListener

public void removeTraceListener(TraceListener listener)
Description copied from interface: Traceable
Removes a listener.

Specified by:
removeTraceListener in interface Traceable
Parameters:
listener - the listener to remove.

clearTraceListeners

public void clearTraceListeners()
Description copied from interface: Traceable
Clears all listeners from this traceable.

Specified by:
clearTraceListeners in interface Traceable

isEmpty

public boolean isEmpty()
Checks whether this variable contains any attributes.

Returns:
true for an empty variable, false otherwise.

sendNotification

public void sendNotification(String message,
                             String name,
                             String type,
                             Object... values)
Sends a modification notification. Subclasses implementing the NotificationEmitter interface can implement this method also to provide modification notifications.

Parameters:
message - the notification message.
name - the attribute name.
type - the attribute type.
values - the old and new values of the attribute.

getObjectName

protected ObjectName getObjectName()
Gets the object name.

Returns:
the object name.

setObjectName

protected void setObjectName(ObjectName name)
Sets the object name.

Parameters:
name - the object name.
Throws:
IllegalStateException - if already registered.

getMBeanServer

protected MBeanServer getMBeanServer()
Gets the MBean server.

Returns:
the MBean server or null.

getAttributeValues

protected Map<String,Object> getAttributeValues(boolean validate,
                                                AttributeFilter... filter)
Gets attribute values.

Parameters:
validate - true to validate.
filter - an optional filter.
Returns:
a map of attribute values.

putAttributeValues

protected boolean putAttributeValues(Map<?,?> attributes,
                                     boolean localize,
                                     AttributeFilter af,
                                     Object... localization)
                              throws InvalidAttributeValueException
Puts attribute values.

Parameters:
attributes - a map of validated attributes.
localize - true to apply localization.
af - an optional filter.
localization - optional base name, resource bundle and locale.
Returns:
true if modified by a notification.
Throws:
InvalidAttributeValueException - if values are invalid.

getAttributeValue

protected Object getAttributeValue(int position,
                                   VariableAttributeInfo info,
                                   boolean validate)
Gets the attribute value. Array values are copied to prevent modifications from outside.

Parameters:
position - the attribute position.
info - the attribute to get.
validate - true for validation, false otherwise.
Returns:
the attribute value.

putAttributeValue

protected Object putAttributeValue(int position,
                                   VariableAttributeInfo info,
                                   Object value,
                                   boolean validate,
                                   Object... localization)
                            throws InvalidAttributeValueException
Puts the attribute value with optional validation.

Parameters:
position - the attribute position.
info - the attribute to set.
value - the attribute value.
validate - true for full validation, false for meta-data only.
localization - optional base name, resource bundle and locale.
Returns:
the new validated attribute value.
Throws:
InvalidAttributeValueException - if the value is invalid.

setAttributeElement

protected void setAttributeElement(int position,
                                   VariableAttributeInfo info,
                                   int index,
                                   boolean add,
                                   Object value,
                                   boolean validate,
                                   Object... localization)
                            throws InvalidAttributeValueException
Sets the indexed attribute element with optional validation.

Parameters:
position - the attribute position.
info - the attribute to set.
index - the element index.
add - true if to be added.
value - the attribute element.
validate - true for full validation, false for meta-data only.
localization - optional base name, resource bundle and locale.
Throws:
InvalidAttributeValueException - if the value is invalid.

removeAttributeElement

protected Object[] removeAttributeElement(int position,
                                          VariableAttributeInfo info,
                                          int index,
                                          Object value,
                                          boolean validate,
                                          Object... localization)
Removes the specified attribute element with optional validation.

Parameters:
position - the attribute position.
info - the attribute to remove.
index - the element index.
value - the element value.
validate - true for full validation, false for meta-data only.
localization - optional base name, resource bundle and locale.
Returns:
the removed element or null.

putAttributeElement

protected void putAttributeElement(int position,
                                   VariableAttributeInfo info,
                                   int index,
                                   boolean add,
                                   Object value,
                                   boolean validate,
                                   Object... localization)
Puts the indexed attribute element with optional validation.

Parameters:
position - the attribute position.
info - the attribute to put.
index - the value index.
add - true if to be added.
value - the attribute value.
validate - true to validate, false otherwise.
localization - optional base name, resource bundle and locale.

validateAttributeValues

protected SortedMap<String,Exception> validateAttributeValues(List<Variable> nested,
                                                              Map<?,?> attributes,
                                                              OrderedMap<String,Object> validated,
                                                              Object... localization)
Validates attribute values in a map of name value bindings. Only known dynamic attributes are validated, others skipped.

Valid attributes are added to a map binding a valid attribute name to its value.

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.

Parameters:
nested - stack of nested variables.
attributes - the attributes map.
validated - the validated attributes map.
localization - optional base name, resource bundle and locale.
Returns:
a map of invalid attributes, an empty map or null.

validateAttributeValue

protected Object validateAttributeValue(VariableAttributeInfo info,
                                        Object value,
                                        Object... localization)
Validates an attribute value by accessors and meta-data with run-time exceptions.

Parameters:
info - the attribute to validate.
value - the attribute value.
localization - optional base name, resource bundle and locale.
Returns:
the validated value.
Throws:
RuntimeConversionException - if the conversion fails.
NumberFormatException - if the value is an invalid number.
ClassCastException - if the value is of incorrect type.
UnsupportedOperationException - if the value cannot be converted.
ShadowValueException - if the value is a shadow value.
IllegalArgumentException - if the value is invalid.
IndexOutOfBoundsException - if array indices are exceeded.
IllegalStateException - if the attribute is not writable.

validateMandatoryValue

protected void validateMandatoryValue(VariableAttributeInfo info,
                                      int index,
                                      Object value)
Validates a mandatory attribute value with run-time exceptions.

Parameters:
info - the attribute to validate.
index - the index of an element.
value - the attribute value.
Throws:
NullPointerException - if a mandatory attribute is null.

getInternalAttributeValue

protected Object getInternalAttributeValue(int position,
                                           VariableAttributeInfo info,
                                           boolean reset)
Gets the internal attribute value.

Parameters:
position - the attribute position.
info - the attribute to get.
reset - true to reset access rights, false otherwise.
Returns:
the attribute value.

putInternalAttributeValue

protected Object putInternalAttributeValue(int position,
                                           VariableAttributeInfo info,
                                           Object value,
                                           boolean reset)
Puts the internal attribute value.

Parameters:
position - the attribute position.
info - the attribute to put.
value - the attribute value.
reset - true to reset access rights, false otherwise.
Returns:
the previous value.

putInternalAttributeValue

protected Object putInternalAttributeValue(int position,
                                           VariableAttributeInfo info,
                                           Object value,
                                           long timestamp,
                                           boolean reset)
Puts the internal attribute value with a modification timestamp.

Parameters:
position - the attribute position.
info - the attribute to put.
value - the attribute value.
timestamp - the timestamp.
reset - true to reset access rights, false otherwise.
Returns:
the previous value.

registerAttributeInfo

protected void registerAttributeInfo(VariableInfo meta)
Registers attribute info.

Parameters:
meta - the variable info.

addAttributeInfoIfAbsent

protected boolean addAttributeInfoIfAbsent(int position,
                                           Collection<VariableAttributeInfo> c)
Adds a collection of attribute info instances without cloning. Already present attribute info instances are removed from the collection.

Parameters:
position - the position index (-1 = at the end).
c - a collection of VariableAttributeInfo instances.
Returns:
true if attributes were added, false otherwise.
Throws:
UnsupportedOperationException - if immutable.

attributeInfoRegistered

protected void attributeInfoRegistered(int position,
                                       VariableAttributeInfo info)
Callback for a registered attribute info.

Parameters:
position - the attribute position.
info - the registered attribute.


Copyright © 2004 The Norther Organization. All rights reserved.