org.jmx4odp.dynamicManagement
Class PropertyReader

java.lang.Object
  extended by org.jmx4odp.dynamicManagement.PropertyReader
All Implemented Interfaces:
javax.management.NotificationBroadcaster, javax.management.NotificationEmitter

public final class PropertyReader
extends java.lang.Object
implements javax.management.NotificationEmitter

These are created by the PropertyReaderFactory. They are in memory singletons that are automatically instrumented and mbeans. You can access the values as type specific. You can add a listener to the PropertyReader to monitor when an existing value has been updated.

Author:
Lucas McGregor
See Also:
PropertyReaderFactory

Constructor Summary
protected PropertyReader()
           
protected PropertyReader(PropertyReader pr)
           
 
Method Summary
 void addNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
           
 boolean contains(java.lang.String key)
           
 void destroy()
          remove any resources attributed to this object
 boolean getBoolean(java.lang.String key)
          Tries to parse the data as a boolean.
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Tries to parse the data as a boolean.
 java.util.Date getCreateDate()
           
 double getDouble(java.lang.String key)
           
 double getDouble(java.lang.String key, double defaultValue)
          Tries to parse the data as a double.
 float getFloat(java.lang.String key)
           
 float getFloat(java.lang.String key, float defaultValue)
          Tries to parse the data as a float.
 int getInt(java.lang.String key)
          Tries to parse the data as a int.
 int getInt(java.lang.String key, int defaultValue)
          Tries to parse the data as a int.
 java.util.HashMap getKeyValues()
           
 long getLong(java.lang.String key)
          Tries to parse the data as a long.
 long getLong(java.lang.String key, long defaultValue)
          Tries to parse the data as a long.
 javax.management.MBeanNotificationInfo[] getNotificationInfo()
           
 javax.management.ObjectName getObjectName()
           
 java.util.HashMap getPrefixedProperties(java.lang.String prefix)
           
 java.util.Properties getProperties()
          return the properties set as a Properties object.
 java.util.HashMap getPropertiesByKeyName(java.lang.String keyName)
           
 java.util.HashMap getPropertiesByKeyName(java.lang.String keyName, java.lang.String separator)
           
 java.util.Iterator getPropertyNames()
           
 java.lang.String getPropertyString()
           
 java.lang.String getResourceName()
           
 short getShort(java.lang.String key)
           
 short getShort(java.lang.String key, short defaultValue)
          Tries to parse the data as a short.
 java.lang.String getString(java.lang.String key)
          Tries to parse the data as a String.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Tries to parse the data as a String.
 void init(java.util.HashMap in_keyValues)
          initializes the PropertyReader with a HashMap of key/value pairs.
 void init(java.lang.String resource)
          same as init(resource, true);
 void init(java.lang.String resource, boolean register)
          Initializes the PropertyReader with the location of a properties file as a resource
 boolean remove(java.lang.String key)
           
 void removeNotificationListener(javax.management.NotificationListener listener)
           
 void removeNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
           
 boolean setBoolean(java.lang.String key, boolean val)
          Tries to set a boolean value.
 int setInt(java.lang.String key, int val)
          Tries to set an integer value.
 long setLong(java.lang.String key, long val)
          Tries to set an long value.
 java.lang.String setString(java.lang.String key, java.lang.String val)
          Tries to set a String value.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PropertyReader

protected PropertyReader()

PropertyReader

protected PropertyReader(PropertyReader pr)
Method Detail

getKeyValues

public java.util.HashMap getKeyValues()

getProperties

public java.util.Properties getProperties()
return the properties set as a Properties object. weird, huh?


getPrefixedProperties

public java.util.HashMap getPrefixedProperties(java.lang.String prefix)
Parameters:
prefix, - a string that represents the prefix to a set of property names. This will cycle through the full property set and filter out properties with names that start with this prefix. It will return a HashMap of the properties with the name/key stripped of the prefix. This can be used with code uses a set of name=values and uses a prefix to seperate out pools or groups.
Returns:
HashMap of name=vlues that had names that started with the prefix with the prefix now stripped off.

getPropertiesByKeyName

public java.util.HashMap getPropertiesByKeyName(java.lang.String keyName)

getPropertiesByKeyName

public java.util.HashMap getPropertiesByKeyName(java.lang.String keyName,
                                                java.lang.String separator)

getObjectName

public javax.management.ObjectName getObjectName()
Returns:
ObjectName for the mbean, maybe null if this is not registered as an mbean

init

public void init(java.lang.String resource)
          throws java.util.MissingResourceException
same as init(resource, true);

Throws:
java.util.MissingResourceException

init

public void init(java.lang.String resource,
                 boolean register)
          throws java.util.MissingResourceException
Initializes the PropertyReader with the location of a properties file as a resource

Parameters:
resource -
manage -
Throws:
java.util.MissingResourceException

init

public void init(java.util.HashMap in_keyValues)
initializes the PropertyReader with a HashMap of key/value pairs. If this init method is invoked, then the PropertyReader will not register itselt as an Mbean automatically.

Parameters:
in_keyValues -

destroy

public void destroy()
remove any resources attributed to this object


getCreateDate

public java.util.Date getCreateDate()
Returns:
the date when this object was created

getPropertyString

public java.lang.String getPropertyString()
Returns:
a string of all the name,value properties that has HTML breaks

contains

public boolean contains(java.lang.String key)
Returns:
true if the reader contains a property with this name

getPropertyNames

public java.util.Iterator getPropertyNames()
Returns:
an iterator of all the property names in the reader

getResourceName

public java.lang.String getResourceName()
Returns:
the name of the resource bundle. Will be null if the propertyreader was initialized from a hashmap

getInt

public int getInt(java.lang.String key)
Tries to parse the data as a int. Any exception will return a -1.


getInt

public int getInt(java.lang.String key,
                  int defaultValue)
Tries to parse the data as a int. Any problem (missing value or exception) will return the default value.


setInt

public int setInt(java.lang.String key,
                  int val)
Tries to set an integer value. Returns the old value, if it existed, otherwise, a null


getLong

public long getLong(java.lang.String key)
Tries to parse the data as a long. Any exception will return a -1.


getLong

public long getLong(java.lang.String key,
                    long defaultValue)
Tries to parse the data as a long. Any problem (missing value or exception) will return the default value.


setLong

public long setLong(java.lang.String key,
                    long val)
Tries to set an long value. Returns the old value, if it existed, otherwise, a null


getFloat

public float getFloat(java.lang.String key)

getFloat

public float getFloat(java.lang.String key,
                      float defaultValue)
Tries to parse the data as a float. Any problem (missing value or exception) will return the default value.


getDouble

public double getDouble(java.lang.String key)

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
Tries to parse the data as a double. Any problem (missing value or exception) will return the default value.


getShort

public short getShort(java.lang.String key)

getShort

public short getShort(java.lang.String key,
                      short defaultValue)
Tries to parse the data as a short. Any problem (missing value or exception) will return the default value.


getBoolean

public boolean getBoolean(java.lang.String key)
Tries to parse the data as a boolean. Any exception will return a false. any word that starts with T or t, or int that is 1 == true.


getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
Tries to parse the data as a boolean. Any problem (missing value or exception) will return the default value.


setBoolean

public boolean setBoolean(java.lang.String key,
                          boolean val)
Tries to set a boolean value. Returns the old value, if it existed, otherwise, a null


getString

public java.lang.String getString(java.lang.String key)
Tries to parse the data as a String. Any exception will return a null.


getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
Tries to parse the data as a String. Any problem (missing value or an exception) will return the default value.


setString

public java.lang.String setString(java.lang.String key,
                                  java.lang.String val)
Tries to set a String value. Returns the old value, if it existed, otherwise, a null


remove

public boolean remove(java.lang.String key)
Parameters:
name - of the property to remove
Returns:
true if the property was removed

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

removeNotificationListener

public void removeNotificationListener(javax.management.NotificationListener listener,
                                       javax.management.NotificationFilter filter,
                                       java.lang.Object handback)
                                throws javax.management.ListenerNotFoundException
Specified by:
removeNotificationListener in interface javax.management.NotificationEmitter
Throws:
javax.management.ListenerNotFoundException

removeNotificationListener

public void removeNotificationListener(javax.management.NotificationListener listener)
                                throws javax.management.ListenerNotFoundException
Specified by:
removeNotificationListener in interface javax.management.NotificationBroadcaster
Throws:
javax.management.ListenerNotFoundException

addNotificationListener

public void addNotificationListener(javax.management.NotificationListener listener,
                                    javax.management.NotificationFilter filter,
                                    java.lang.Object handback)
                             throws java.lang.IllegalArgumentException
Specified by:
addNotificationListener in interface javax.management.NotificationBroadcaster
Throws:
java.lang.IllegalArgumentException

getNotificationInfo

public javax.management.MBeanNotificationInfo[] getNotificationInfo()
Specified by:
getNotificationInfo in interface javax.management.NotificationBroadcaster