org.norther.tammi.core.config
Class DefaultConfigurable

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.config.DefaultConfigurable
All Implemented Interfaces:
Serializable, EventListener, NotificationBroadcaster, NotificationEmitter, TraceListener, Manageable, MBeanDelegate, Configurable
Direct Known Subclasses:
AbstractChartGenerator, AbstractRealm, AbstractReportEngine, AbstractTemplateEngine, DefaultConfigurableConverter, DefaultConfigurableFactory, DefaultMailSender

public class DefaultConfigurable
extends Adaptee
implements Configurable, TraceListener

A default implementation of Configurable maintaining its configuration in key/value based properties.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
static int MODIFIED
          The modified properties state.
static int SYNCHRONIZED
          The synchronized properties state.
static int UNMODIFIED
          The unmodified properties state.
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.base.MBeanDelegate
ARRAY_TYPE, OBJECT_TYPE, PRIMITIVE_TYPE, STRING_TYPE
 
Constructor Summary
DefaultConfigurable()
          Constructs a new configurable MBean.
 
Method Summary
 void addProperty(int index, String key, String value)
          Inserts a multivalued property at the specified index.
 void addProperty(String key, String value)
          Adds a multivalued property.
 void clearProperties()
          Clears all properties.
 boolean containsProperty(String key)
          Checks whether a property is defined.
 String getConfigKey()
          Gets the path finder key for resolving configuration paths.
 Configuration getConfiguration()
          Gets the configuration.
 int getModifiedState()
          Gets the modified state.
 String[] getProperties(String key)
          Gets a multivalued property.
 String getProperty(String key)
          Gets a property.
 String getPropertyFilePath()
          Gets the property file path.
 int indexOfProperty(String key, String value)
          Returns the index of a multivalued property value.
 Configuration loadConfiguration(File file)
          Loads a configuration from the specified file.
 Configuration loadConfiguration(String path)
          Loads a configuration from the specified path.
 Configuration loadConfiguration(URL url)
          Loads a configuration from the specified URL.
 void modified(TraceEvent event)
          Notifies the object that the trace has been modified.
 OrderedMap propertyMap()
          Returns a map of properties.
 OrderedMap propertyMap(String prefix)
          Returns a map of prefixed properties.
 Object removeProperty(String key)
          Removes a property.
 boolean removeProperty(String key, String value)
          Removes a multivalued property.
 void setConfigKey(String key)
          Sets the path finder key for resolving configuration paths.
 void setModifiedState(int state)
          Sets the modified state.
 Object setProperties(String key, String[] values)
          Sets a multivalued property.
 Object setProperty(String key, String value)
          Sets a property.
 void setPropertyFilePath(String path)
          Sets the property file path.
 void setPropertyFilePath(String path, String encoding)
          Sets the property file path with encoding.
 void storeProperties()
          Stores properties to the property file.
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unmanaged, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNMODIFIED

public static final int UNMODIFIED
The unmodified properties state.

See Also:
Constant Field Values

MODIFIED

public static final int MODIFIED
The modified properties state.

See Also:
Constant Field Values

SYNCHRONIZED

public static final int SYNCHRONIZED
The synchronized properties state.

See Also:
Constant Field Values
Constructor Detail

DefaultConfigurable

public DefaultConfigurable()
Constructs a new configurable MBean.

Method Detail

getConfigKey

public String getConfigKey()
Description copied from interface: Configurable
Gets the path finder key for resolving configuration paths.

Specified by:
getConfigKey in interface Configurable
Returns:
the path finder key.

setConfigKey

public void setConfigKey(String key)
Description copied from interface: Configurable
Sets the path finder key for resolving configuration paths. The default key is PathFinderMBean.CONFIG.

Specified by:
setConfigKey in interface Configurable
Parameters:
key - the path finder key.

getPropertyFilePath

public String getPropertyFilePath()
Description copied from interface: Configurable
Gets the property file path.

Specified by:
getPropertyFilePath in interface Configurable
Returns:
the property file path.

setPropertyFilePath

public void setPropertyFilePath(String path)
Description copied from interface: Configurable
Sets the property file path. The path may be an absolute file path, a file path relative to the specified config key folder or a URL. The properties will be loaded before the next get/set property operation.

Specified by:
setPropertyFilePath in interface Configurable
Parameters:
path - a property file path.

setPropertyFilePath

public void setPropertyFilePath(String path,
                                String encoding)
Description copied from interface: Configurable
Sets the property file path with encoding. The path may be an absolute file path, a file path relative to the specified config key folder or a URL. The properties will be loaded before the next get/set property operation.

Specified by:
setPropertyFilePath in interface Configurable
Parameters:
path - a property file path.
encoding - the encoding to use.

containsProperty

public boolean containsProperty(String key)
Description copied from interface: Configurable
Checks whether a property is defined.

Specified by:
containsProperty in interface Configurable
Parameters:
key - the key.
Returns:
true for a defined property, false otherwise.

getProperty

public String getProperty(String key)
Description copied from interface: Configurable
Gets a property.

Specified by:
getProperty in interface Configurable
Parameters:
key - the key.
Returns:
the value or null.

setProperty

public Object setProperty(String key,
                          String value)
Description copied from interface: Configurable
Sets a property.

Specified by:
setProperty in interface Configurable
Parameters:
key - the key.
value - the value.
Returns:
the previous value.

getProperties

public String[] getProperties(String key)
Description copied from interface: Configurable
Gets a multivalued property.

Specified by:
getProperties in interface Configurable
Parameters:
key - the key.
Returns:
the values or null.

setProperties

public Object setProperties(String key,
                            String[] values)
Description copied from interface: Configurable
Sets a multivalued property.

Specified by:
setProperties in interface Configurable
Parameters:
key - the key.
values - the values.
Returns:
the previous value.

removeProperty

public Object removeProperty(String key)
Description copied from interface: Configurable
Removes a property.

Specified by:
removeProperty in interface Configurable
Parameters:
key - the key.
Returns:
the removed value or null.

indexOfProperty

public int indexOfProperty(String key,
                           String value)
Description copied from interface: Configurable
Returns the index of a multivalued property value.

Specified by:
indexOfProperty in interface Configurable
Parameters:
key - the key.
value - the value.
Returns:
the index of the value or -1.

addProperty

public void addProperty(String key,
                        String value)
Description copied from interface: Configurable
Adds a multivalued property.

Specified by:
addProperty in interface Configurable
Parameters:
key - the key.
value - the property.

addProperty

public void addProperty(int index,
                        String key,
                        String value)
Description copied from interface: Configurable
Inserts a multivalued property at the specified index.

Specified by:
addProperty in interface Configurable
Parameters:
index - the index.
key - the key.
value - the value.

removeProperty

public boolean removeProperty(String key,
                              String value)
Description copied from interface: Configurable
Removes a multivalued property.

Specified by:
removeProperty in interface Configurable
Parameters:
key - the key.
value - the value.
Returns:
true if removed, false otherwise.

clearProperties

public void clearProperties()
Description copied from interface: Configurable
Clears all properties.

Specified by:
clearProperties in interface Configurable

propertyMap

public OrderedMap propertyMap()
Description copied from interface: Configurable
Returns a map of properties. Multivalued properties are presented as string arrays.

Specified by:
propertyMap in interface Configurable
Returns:
a map of properties.

propertyMap

public OrderedMap propertyMap(String prefix)
Description copied from interface: Configurable
Returns a map of prefixed properties. The prefix is removed from the keys of the returned map. Multivalued properties are presented as string arrays.

Specified by:
propertyMap in interface Configurable
Parameters:
prefix - the prefix.
Returns:
a map of properties.

storeProperties

public void storeProperties()
                     throws IOException
Description copied from interface: Configurable
Stores properties to the property file.

Specified by:
storeProperties in interface Configurable
Throws:
IOException - on I/O errors.

modified

public void modified(TraceEvent event)
Description copied from interface: TraceListener
Notifies the object that the trace has been modified.

Specified by:
modified in interface TraceListener
Parameters:
event - the probe event.

getModifiedState

public int getModifiedState()
Gets the modified state. This method is not synchronized but the state is volatile enabling subclasses to implement different update strategies.

Returns:
the modified state.

setModifiedState

public void setModifiedState(int state)
Sets the modified state. This method is synchronized with the configuration to guarantee correct state changes.

Parameters:
state - the modified state.

getConfiguration

public Configuration getConfiguration()
Gets the configuration.

Returns:
the configuration.

loadConfiguration

public Configuration loadConfiguration(String path)
Loads a configuration from the specified path.

Parameters:
path - the path.
Returns:
the configuration.

loadConfiguration

public Configuration loadConfiguration(File file)
Loads a configuration from the specified file.

Parameters:
file - the file.
Returns:
the configuration.

loadConfiguration

public Configuration loadConfiguration(URL url)
Loads a configuration from the specified URL.

Parameters:
url - the URL.
Returns:
the configuration.


Copyright © 2004 The Norther Organization. All rights reserved.