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, DefaultMailer

public class DefaultConfigurable
extends Adaptee
implements Configurable, TraceListener

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

Version:
$Id: DefaultConfigurable.java,v 1.18 2009/11/27 14:06:06 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Nested Class Summary
static class DefaultConfigurable.Modified
          Modified state of properties.
 
Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
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 addPropertyFilePath(String path)
          Adds a property file path.
 void addPropertyFilePath(String path, String encoding)
          Adds a property file path with an encoding.
protected  void checkConfiguration()
          Checks the configuration.
 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.
 DefaultConfigurable.Modified 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.
 String[] getPropertyFilePaths()
          Gets the property file paths.
 int indexOfProperty(String key, String value)
          Returns the index of a multivalued property value.
 Configuration loadConfiguration(File file, String... encoding)
          Loads a configuration from the specified file.
 Configuration loadConfiguration(String path, String... encoding)
          Loads a configuration from the specified path.
 Configuration loadConfiguration(URL url, String... encoding)
          Loads a configuration from the specified URL.
 void modified(TraceEvent event)
          Notifies the object that the trace has been modified.
 OrderedMap<String,Object> propertyMap()
          Returns a map of properties.
 OrderedMap<String,Object> 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 removePropertyFilePath(String path)
          Removes a property file path.
 void setConfigKey(String key)
          Sets the path finder key for resolving configuration paths.
 void setModifiedState(DefaultConfigurable.Modified 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 an encoding.
 void setPropertyFilePaths(String[] paths)
          Sets the property file paths.
 void setPropertyFilePaths(String[] paths, String... encoding)
          Sets the property file paths with encodings.
 void storeProperties()
          Stores properties to the property file.
protected  void validateConfiguration(Configuration config)
          Validates the configuration.
 
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
 

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. The first one is returned if more than one is defined.

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

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.

Note that all previously defined property file paths and properties are cleared.

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 an encoding.

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

getPropertyFilePaths

public String[] getPropertyFilePaths()
Description copied from interface: Configurable
Gets the property file paths.

Specified by:
getPropertyFilePaths in interface Configurable
Returns:
the property file paths.

setPropertyFilePaths

public void setPropertyFilePaths(String[] paths)
Description copied from interface: Configurable
Sets the property file paths. 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. New paths are added after existing ones.

Specified by:
setPropertyFilePaths in interface Configurable
Parameters:
paths - property file paths.

setPropertyFilePaths

public void setPropertyFilePaths(String[] paths,
                                 String... encoding)
Description copied from interface: Configurable
Sets the property file paths with encodings.

Specified by:
setPropertyFilePaths in interface Configurable
Parameters:
paths - property file paths.
encoding - encodings to use.

addPropertyFilePath

public void addPropertyFilePath(String path)
Description copied from interface: Configurable
Adds a property file path.

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

addPropertyFilePath

public void addPropertyFilePath(String path,
                                String encoding)
Description copied from interface: Configurable
Adds a property file path with an encoding.

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

removePropertyFilePath

public void removePropertyFilePath(String path)
Description copied from interface: Configurable
Removes a property file path.

Specified by:
removePropertyFilePath in interface Configurable
Parameters:
path - the property file path.

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<String,Object> 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<String,Object> 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. The first defined property file is applied to all properties.

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 trace event.

getModifiedState

public DefaultConfigurable.Modified 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(DefaultConfigurable.Modified 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,
                                       String... encoding)
                                throws IOException
Loads a configuration from the specified path.

Parameters:
path - the path.
encoding - an optional encoding.
Returns:
the configuration.
Throws:
IOException - on I/O errors.

loadConfiguration

public Configuration loadConfiguration(File file,
                                       String... encoding)
                                throws IOException
Loads a configuration from the specified file.

Parameters:
file - the file.
encoding - an optional encoding.
Returns:
the configuration.
Throws:
IOException - on I/O errors.

loadConfiguration

public Configuration loadConfiguration(URL url,
                                       String... encoding)
                                throws IOException
Loads a configuration from the specified URL.

Parameters:
url - the URL.
encoding - an optional encoding.
Returns:
the configuration.
Throws:
IOException - on I/O errors.

checkConfiguration

protected void checkConfiguration()
Checks the configuration.


validateConfiguration

protected void validateConfiguration(Configuration config)
Validates the configuration.

Parameters:
config - the configuration.


Copyright © 2004 The Norther Organization. All rights reserved.