org.norther.tammi.core.rt
Class Introspector

java.lang.Object
  extended by org.norther.tammi.core.rt.Introspector
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BeanTool

public class Introspector
extends Object
implements Serializable

An introspector for Variables.

Note that the instrospector is not thread-safe.

Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
Introspector()
          Constructs a new introspector.
Introspector(MBeanServer server)
          Constructs a new introspector for a specific server.
 
Method Summary
 void addValue(Variable variable, String name, int index, Object value)
          Adds the indexed element to the named array attribute of the specified variable.
 void addValue(Variable variable, String name, Object value)
          Adds an element to the named array attribute of the specified variable.
protected  void clearResourceCache()
          Clears the resource cache.
 boolean contains(Variable variable, String name)
          Checks whether the specified variable contains the named attribute.
 Variable create()
          Creates an empty variable MBean instance.
 Variable create(Object source)
          Creates a variable MBean instance with imported attributes.
 Variable create(String type)
          Creates a typed variable MBean instance.
 Variable create(String type, Object source)
          Creates a typed variable MBean instance with imported attributes.
protected  Variable createVariable(String type)
          Creates a variable MBean instance.
 boolean exportTo(Variable variable, Object target)
          Exports the specified variable to another object.
 boolean exportTo(Variable variable, Object target, AttributeFilter filter)
          Exports the specified variable to another object by applying a filter.
 Comparator getComparator(MBeanAttributeInfo attribute)
          Gets the comparator of the specified attribute.
protected  Converter getConverter()
          Gets the referent of the converter MBean.
 Locale getDefaultLocale()
          Gets the default locale.
 String getDescription(Variable variable, MBeanAttributeInfo attribute)
          Gets the specified attribute description.
 String getDetail(Variable variable, MBeanAttributeInfo attribute)
          Gets the specified attribute detail.
 EnumeratedList getEnumeration(Variable variable, MBeanAttributeInfo attribute)
          Gets the specified attribute value enumeration as a list of localized enumeration attributes.
 String getGroup(Variable variable, MBeanAttributeInfo attribute)
          Gets the specified attribute group.
 VariableAttributeInfo getInfo(Variable variable, String name)
          Gets the named attribute info of the specified variable.
 VariableAttributeInfo getInfo(Variable variable, String name, boolean unlocked)
          Gets the named and optionally unlocked attribute info of the specified variable.
 Object getKeyValue(Variable variable, String name)
          Gets the named key attribute value of the specified variable.
 List getList(Variable variable)
          Gets the attribute info list of the specified variable.
 List getList(Variable variable, boolean unlocked)
          Gets the optionally unlocked attribute info list of the specified variable.
 Locale getLocale()
          Gets the locale to apply.
 Number getMax(MBeanAttributeInfo attribute)
          Gets the maximum value of the specified attribute.
protected  MBeanServer getMBeanServer()
          Gets a reference to the MBean server.
 Number getMin(MBeanAttributeInfo attribute)
          Gets the minimum value of the specified attribute.
 String getPattern(MBeanAttributeInfo attribute)
          Gets the pattern of the specified attribute.
protected  String getResource(Variable variable, MBeanAttributeInfo attribute, String key)
          Gets an attribute resource.
protected  LookupResourceBundle getResourceBundle(String baseName)
          Gets the resource bundle for a base name.
protected  LookupResourceBundle getResourceBundle(Variable variable, MBeanAttributeInfo attribute)
          Gets the resource bundle for an attribute.
protected  String getResourceBundleName(String baseName)
          Gets the resource bundle name for a base name.
protected  String getResourceBundleName(Variable variable, MBeanAttributeInfo attribute)
          Gets the resource bundle name for an attribute.
protected  ResourceMap getResourceMap()
          Gets the resource map MBean.
 Object getValue(Variable variable, String name)
          Gets the named attribute value of the specified variable.
 Object getValue(Variable variable, String name, int index)
          Gets the indexed element of the named array attribute of the specified variable.
protected  VariableRegistry getVariableRegistry()
          Gets the referent of the variable registry MBean.
 boolean hasConverter(MBeanAttributeInfo attribute)
          Checks the converter of the specified attribute.
 boolean importFrom(Variable variable, Object source)
          Imports the specified variable from another object.
 boolean importFrom(Variable variable, Object source, AttributeFilter filter)
          Imports the specified variable from another object by applying a filter.
 boolean isArray(MBeanAttributeInfo attribute)
          Checks if the specified attribute is an array.
 boolean isBlankAccepted(MBeanAttributeInfo attribute)
          Checks if the specified attribute accepts blank strings.
 boolean isCloneable(MBeanAttributeInfo attribute)
          Checks if the specified attribute is cloneable.
 boolean isCorrelative(MBeanAttributeInfo attribute)
          Checks if the specified attribute is correlative.
 boolean isDisabled(MBeanAttributeInfo attribute)
          Checks if the specified attribute is disabled.
 boolean isEmptyAccepted(MBeanAttributeInfo attribute)
          Checks if the specified attribute is empty arrays.
 boolean isEnumerated(MBeanAttributeInfo attribute)
          Checks if the specified attribute is enumerated.
 boolean isInteractive(MBeanAttributeInfo attribute)
          Checks if the specified attribute is interactive.
 boolean isLocal(MBeanAttributeInfo attribute)
          Checks if the specified attribute is local.
 boolean isLocalized(MBeanAttributeInfo attribute)
          Checks if the specified attribute is localized.
 boolean isLocalizedVariables()
          Checks whether variables are localized.
 boolean isMandatory(MBeanAttributeInfo attribute)
          Checks if the specified attribute is mandatory.
 boolean isOrdered(MBeanAttributeInfo attribute)
          Checks if the specified attribute is ordered.
 boolean isReadable(MBeanAttributeInfo attribute)
          Checks if the specified attribute is readable.
 boolean isSerialized(MBeanAttributeInfo attribute)
          Checks if the specified attribute is serialized.
 boolean isSorted(MBeanAttributeInfo attribute)
          Checks if the specified attribute is sorted.
 boolean isTraceable(MBeanAttributeInfo attribute)
          Checks if the specified attribute is traceable.
 boolean isTransient(MBeanAttributeInfo attribute)
          Checks if the specified attribute is transient.
 boolean isTrimmed(MBeanAttributeInfo attribute)
          Checks if the specified attribute is trimmed.
 boolean isVisible(MBeanAttributeInfo attribute)
          Checks if the specified attribute is visible.
 boolean isWritable(MBeanAttributeInfo attribute)
          Checks if the specified attribute is writable.
 int length(Variable variable, String name)
          Returns the length of the specified array attribute.
 Object removeValue(Variable variable, String name, int index)
          Removes the indexed element from the named array attribute of the specified variable.
 boolean removeValue(Variable variable, String name, Object value)
          Removes an element from the named array attribute of the specified variable.
 void setLocale(Locale locale)
          Sets the locale to apply.
 void setValue(Variable variable, String name, int index, Object value)
          Sets the indexed element of the named array attribute of the specified variable.
 void setValue(Variable variable, String name, Object value)
          Sets the named attribute value of the specified variable.
 void setValue(Variable variable, String name, Object value, boolean forced)
          Sets the named attribute value of the specified variable optionally by-passing attribute's current writable and mandatory settings.
 String toString(Variable variable, String name)
          Returns the specified attribute value as a localized string.
 String[] toStrings(Variable variable, String name)
          Returns the specified attribute values as a localized string array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Introspector

public Introspector()
Constructs a new introspector.


Introspector

public Introspector(MBeanServer server)
Constructs a new introspector for a specific server. Note that MBean server cannot be serialized.

Parameters:
server - the MBean server.
Method Detail

create

public Variable create()
                throws ConstructionException
Creates an empty variable MBean instance.

Returns:
the variable or null.
Throws:
ConstructionException - if construction fails.

create

public Variable create(Object source)
                throws ConstructionException
Creates a variable MBean instance with imported attributes.

Parameters:
source - the source object.
Returns:
the variable or null.
Throws:
ConstructionException - if construction fails.

create

public Variable create(String type)
                throws ConstructionException
Creates a typed variable MBean instance.

Parameters:
type - the variable type.
Returns:
the variable or null.
Throws:
ConstructionException - if construction fails.

create

public Variable create(String type,
                       Object source)
                throws ConstructionException
Creates a typed variable MBean instance with imported attributes.

Parameters:
type - the variable type.
source - the source object.
Returns:
the variable or null.
Throws:
ConstructionException - if construction fails.

contains

public boolean contains(Variable variable,
                        String name)
Checks whether the specified variable contains the named attribute.

Parameters:
variable - the variable.
name - the attribute name.
Returns:
true if contained, false otherwise.

getInfo

public VariableAttributeInfo getInfo(Variable variable,
                                     String name)
Gets the named attribute info of the specified variable.

Parameters:
variable - the variable.
name - the attribute name.
Returns:
the named attribute or null.

getInfo

public VariableAttributeInfo getInfo(Variable variable,
                                     String name,
                                     boolean unlocked)
Gets the named and optionally unlocked attribute info of the specified variable.

Parameters:
variable - the variable.
name - the attribute name.
unlocked - true for unlocked, false otherwise.
Returns:
the named attribute or null.

getList

public List getList(Variable variable)
Gets the attribute info list of the specified variable.

Parameters:
variable - the variable.
Returns:
a list of attributes.

getList

public List getList(Variable variable,
                    boolean unlocked)
Gets the optionally unlocked attribute info list of the specified variable.

Parameters:
variable - the variable.
unlocked - true for unlocked, false otherwise.
Returns:
a list of attributes.

getValue

public Object getValue(Variable variable,
                       String name)
                throws AttributeNotFoundException
Gets the named attribute value of the specified variable. The original value is returned without string conversion or localization.

Parameters:
variable - the variable.
name - the attribute name.
Returns:
the attribute value.
Throws:
AttributeNotFoundException - if not found.

setValue

public void setValue(Variable variable,
                     String name,
                     Object value)
              throws AttributeNotFoundException,
                     InvalidAttributeValueException
Sets the named attribute value of the specified variable. The value must not be a localized value.

Parameters:
variable - the variable.
name - the attribute name.
value - the attribute value.
Throws:
AttributeNotFoundException - if not found.
InvalidAttributeValueException - for an invalid value.

setValue

public void setValue(Variable variable,
                     String name,
                     Object value,
                     boolean forced)
              throws AttributeNotFoundException,
                     InvalidAttributeValueException
Sets the named attribute value of the specified variable optionally by-passing attribute's current writable and mandatory settings. The value must not be a localized value.

Parameters:
variable - the variable.
name - the attribute name.
value - the attribute value.
forced - if true, forces the setting.
Throws:
AttributeNotFoundException - if not found.
InvalidAttributeValueException - for an invalid value.

getValue

public Object getValue(Variable variable,
                       String name,
                       int index)
                throws AttributeNotFoundException
Gets the indexed element of the named array attribute of the specified variable. The original value is returned without string conversion or localization.

Parameters:
variable - the variable.
name - the attribute name.
index - the element index.
Returns:
the attribute value.
Throws:
AttributeNotFoundException - if not found.

setValue

public void setValue(Variable variable,
                     String name,
                     int index,
                     Object value)
              throws AttributeNotFoundException,
                     InvalidAttributeValueException
Sets the indexed element of the named array attribute of the specified variable. The value must not be a localized value.

Parameters:
variable - the variable.
name - the attribute name.
index - the element index.
value - the attribute value.
Throws:
AttributeNotFoundException - if not found.
InvalidAttributeValueException - for an invalid value.

addValue

public void addValue(Variable variable,
                     String name,
                     Object value)
              throws AttributeNotFoundException,
                     InvalidAttributeValueException
Adds an element to the named array attribute of the specified variable. The value must not be a localized value.

Parameters:
variable - the variable.
name - the attribute name.
value - the attribute value.
Throws:
AttributeNotFoundException - if not found.
InvalidAttributeValueException - for an invalid value.

addValue

public void addValue(Variable variable,
                     String name,
                     int index,
                     Object value)
              throws AttributeNotFoundException,
                     InvalidAttributeValueException
Adds the indexed element to the named array attribute of the specified variable. The value must not be a localized value.

Parameters:
variable - the variable.
name - the attribute name.
index - the element index.
value - the attribute value.
Throws:
AttributeNotFoundException - if not found.
InvalidAttributeValueException - for an invalid value.

removeValue

public boolean removeValue(Variable variable,
                           String name,
                           Object value)
                    throws AttributeNotFoundException
Removes an element from the named array attribute of the specified variable. The value must not be a localized value.

Parameters:
variable - the variable.
name - the attribute name.
value - the value of the element.
Returns:
true if removed.
Throws:
AttributeNotFoundException - if the name is unknown.

removeValue

public Object removeValue(Variable variable,
                          String name,
                          int index)
                   throws AttributeNotFoundException
Removes the indexed element from the named array attribute of the specified variable.

Parameters:
variable - the variable.
name - the attribute name.
index - the element index.
Returns:
the removed value of the element.
Throws:
AttributeNotFoundException - if the name is unknown.

getKeyValue

public Object getKeyValue(Variable variable,
                          String name)
                   throws AttributeNotFoundException
Gets the named key attribute value of the specified variable.

Parameters:
variable - the variable.
name - the attribute name.
Returns:
the key attribute value.
Throws:
AttributeNotFoundException - if not found.

toString

public String toString(Variable variable,
                       String name)
                throws AttributeNotFoundException
Returns the specified attribute value as a localized string.

Parameters:
variable - the variable.
name - the attribute name.
Returns:
the attribute value or an empty string.
Throws:
AttributeNotFoundException - if not found.

toStrings

public String[] toStrings(Variable variable,
                          String name)
                   throws AttributeNotFoundException
Returns the specified attribute values as a localized string array.

Parameters:
variable - the variable.
name - the attribute name.
Returns:
the attribute values or an empty string array.
Throws:
AttributeNotFoundException - if not found.

length

public int length(Variable variable,
                  String name)
           throws AttributeNotFoundException
Returns the length of the specified array attribute.

Parameters:
variable - the variable.
name - the attribute name.
Returns:
the length of the array attribute.
Throws:
AttributeNotFoundException - if not found.

getDescription

public String getDescription(Variable variable,
                             MBeanAttributeInfo attribute)
Gets the specified attribute description.

Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the attribute description.

getGroup

public String getGroup(Variable variable,
                       MBeanAttributeInfo attribute)
Gets the specified attribute group.

Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the attribute group or an empty string.

getDetail

public String getDetail(Variable variable,
                        MBeanAttributeInfo attribute)
Gets the specified attribute detail.

Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the attribute detail or an empty string.

getEnumeration

public EnumeratedList getEnumeration(Variable variable,
                                     MBeanAttributeInfo attribute)
Gets the specified attribute value enumeration as a list of localized enumeration attributes.

Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the attribute value enumeration or null.

isVisible

public boolean isVisible(MBeanAttributeInfo attribute)
Checks if the specified attribute is visible.

Parameters:
attribute - the attribute.
Returns:
true if visible, otherwise false.

isReadable

public boolean isReadable(MBeanAttributeInfo attribute)
Checks if the specified attribute is readable.

Parameters:
attribute - the attribute.
Returns:
true if readable, otherwise false.

isWritable

public boolean isWritable(MBeanAttributeInfo attribute)
Checks if the specified attribute is writable.

Parameters:
attribute - the attribute.
Returns:
true if writable, otherwise false.

isCloneable

public boolean isCloneable(MBeanAttributeInfo attribute)
Checks if the specified attribute is cloneable.

Parameters:
attribute - the attribute.
Returns:
true if cloneable, otherwise false.

isMandatory

public boolean isMandatory(MBeanAttributeInfo attribute)
Checks if the specified attribute is mandatory.

Parameters:
attribute - the attribute.
Returns:
true if mandatory, otherwise false.

isTransient

public boolean isTransient(MBeanAttributeInfo attribute)
Checks if the specified attribute is transient.

Parameters:
attribute - the attribute.
Returns:
true if transient, otherwise false.

isSerialized

public boolean isSerialized(MBeanAttributeInfo attribute)
Checks if the specified attribute is serialized.

Parameters:
attribute - the attribute.
Returns:
true if serialized, otherwise false.

isCorrelative

public boolean isCorrelative(MBeanAttributeInfo attribute)
Checks if the specified attribute is correlative.

Parameters:
attribute - the attribute.
Returns:
true if correlative, otherwise false.

isInteractive

public boolean isInteractive(MBeanAttributeInfo attribute)
Checks if the specified attribute is interactive.

Parameters:
attribute - the attribute.
Returns:
true if interactive, otherwise false.

isLocalized

public boolean isLocalized(MBeanAttributeInfo attribute)
Checks if the specified attribute is localized.

Parameters:
attribute - the attribute.
Returns:
true if localized, otherwise false.

isOrdered

public boolean isOrdered(MBeanAttributeInfo attribute)
Checks if the specified attribute is ordered.

Parameters:
attribute - the attribute.
Returns:
true if ordered, otherwise false.

isSorted

public boolean isSorted(MBeanAttributeInfo attribute)
Checks if the specified attribute is sorted.

Parameters:
attribute - the attribute.
Returns:
true if sorted, otherwise false.

isTraceable

public boolean isTraceable(MBeanAttributeInfo attribute)
Checks if the specified attribute is traceable.

Parameters:
attribute - the attribute.
Returns:
true if traceable, otherwise false.

isDisabled

public boolean isDisabled(MBeanAttributeInfo attribute)
Checks if the specified attribute is disabled.

Parameters:
attribute - the attribute.
Returns:
true if disabled, otherwise false.

isTrimmed

public boolean isTrimmed(MBeanAttributeInfo attribute)
Checks if the specified attribute is trimmed.

Parameters:
attribute - the attribute.
Returns:
true if trimmed, otherwise false.

isBlankAccepted

public boolean isBlankAccepted(MBeanAttributeInfo attribute)
Checks if the specified attribute accepts blank strings.

Parameters:
attribute - the attribute.
Returns:
true if accepts blank, otherwise false.

isEmptyAccepted

public boolean isEmptyAccepted(MBeanAttributeInfo attribute)
Checks if the specified attribute is empty arrays.

Parameters:
attribute - the attribute.
Returns:
true if accepts empty, otherwise false.

isLocal

public boolean isLocal(MBeanAttributeInfo attribute)
Checks if the specified attribute is local.

Parameters:
attribute - the attribute.
Returns:
true if local, otherwise false.

getComparator

public Comparator getComparator(MBeanAttributeInfo attribute)
Gets the comparator of the specified attribute.

Parameters:
attribute - the attribute.
Returns:
the comparator or null.

isArray

public boolean isArray(MBeanAttributeInfo attribute)
Checks if the specified attribute is an array.

Parameters:
attribute - the attribute.
Returns:
true if an array, otherwise false.

isEnumerated

public boolean isEnumerated(MBeanAttributeInfo attribute)
Checks if the specified attribute is enumerated.

Parameters:
attribute - the attribute.
Returns:
true if enumeration, otherwise false.

getMin

public Number getMin(MBeanAttributeInfo attribute)
Gets the minimum value of the specified attribute.

Parameters:
attribute - the attribute.
Returns:
the minimum value or 0.

getPattern

public String getPattern(MBeanAttributeInfo attribute)
Gets the pattern of the specified attribute.

Parameters:
attribute - the attribute.
Returns:
the pattern or null.

getMax

public Number getMax(MBeanAttributeInfo attribute)
Gets the maximum value of the specified attribute.

Parameters:
attribute - the attribute.
Returns:
the maximum value or -1.

hasConverter

public boolean hasConverter(MBeanAttributeInfo attribute)
Checks the converter of the specified attribute.

Parameters:
attribute - the attribute.
Returns:
true if a converter is available, false otherwise.

exportTo

public boolean exportTo(Variable variable,
                        Object target)
Exports the specified variable to another object.

Parameters:
variable - the variable.
target - the target object.
Returns:
true on success, false on error.

exportTo

public boolean exportTo(Variable variable,
                        Object target,
                        AttributeFilter filter)
Exports the specified variable to another object by applying a filter.

Parameters:
variable - the variable.
target - the target object.
filter - the filter to apply.
Returns:
true on success, false on error.

importFrom

public boolean importFrom(Variable variable,
                          Object source)
Imports the specified variable from another object.

Parameters:
variable - the variable.
source - the source object.
Returns:
true on success, false on error.

importFrom

public boolean importFrom(Variable variable,
                          Object source,
                          AttributeFilter filter)
Imports the specified variable from another object by applying a filter.

Parameters:
variable - the variable.
source - the source object.
filter - the filter to apply.
Returns:
true on success, false on error.

getLocale

public Locale getLocale()
Gets the locale to apply.

Returns:
the locale.

setLocale

public void setLocale(Locale locale)
Sets the locale to apply.

Parameters:
locale - the locale.

getDefaultLocale

public Locale getDefaultLocale()
Gets the default locale.

Returns:
the default locale.

isLocalizedVariables

public boolean isLocalizedVariables()
Checks whether variables are localized.

Returns:
true if localized, false otherwise.

createVariable

protected Variable createVariable(String type)
                           throws ConstructionException
Creates a variable MBean instance.

Parameters:
type - the variable type.
Returns:
the created variable.
Throws:
ConstructionException - if construction fails.

getResourceBundleName

protected String getResourceBundleName(Variable variable,
                                       MBeanAttributeInfo attribute)
Gets the resource bundle name for an attribute.

Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the resource bundle name or null.

getResourceBundleName

protected String getResourceBundleName(String baseName)
Gets the resource bundle name for a base name.

Parameters:
baseName - the base name.
Returns:
the resource bundle name or null.

getResourceBundle

protected LookupResourceBundle getResourceBundle(Variable variable,
                                                 MBeanAttributeInfo attribute)
Gets the resource bundle for an attribute.

Parameters:
variable - the variable.
attribute - the attribute.
Returns:
the resource bundle or null.

getResourceBundle

protected LookupResourceBundle getResourceBundle(String baseName)
Gets the resource bundle for a base name.

Parameters:
baseName - the base name.
Returns:
the resource bundle or null.

getResource

protected String getResource(Variable variable,
                             MBeanAttributeInfo attribute,
                             String key)
Gets an attribute resource.

Parameters:
variable - the variable.
attribute - the attribute.
key - the key of the resource.
Returns:
the resource or the original key.

clearResourceCache

protected void clearResourceCache()
Clears the resource cache.


getConverter

protected Converter getConverter()
Gets the referent of the converter MBean.

Returns:
the referent of the converter MBean.
Throws:
IllegalStateException - if not available.

getVariableRegistry

protected VariableRegistry getVariableRegistry()
Gets the referent of the variable registry MBean.

Returns:
the referent the variable registry MBean.
Throws:
IllegalStateException - if not available.

getResourceMap

protected ResourceMap getResourceMap()
Gets the resource map MBean.

Returns:
the resource map MBean or null if not available.

getMBeanServer

protected MBeanServer getMBeanServer()
Gets a reference to the MBean server.

Returns:
the server or null.


Copyright © 2004 The Norther Organization. All rights reserved.