net.smartlab.config
Class Configuration

java.lang.Object
  extended by net.smartlab.config.Element
      extended by net.smartlab.config.Node
          extended by net.smartlab.config.Configuration
Direct Known Subclasses:
SQLConfiguration, XMLConfiguration

public abstract class Configuration
extends Node

This class provides a skeletal implementation of a configuration tree to provide a set of common operations with a generic implementation.

Author:
rlogiacco

Field Summary
protected  java.util.Collection listeners
           
protected  net.smartlab.config.Configuration.Monitor monitor
           
 
Fields inherited from class net.smartlab.config.Node
attributes, children, content, resolved
 
Fields inherited from class net.smartlab.config.Element
name, parent
 
Constructor Summary
protected Configuration()
          Creates an instance of the class as an Element without a parent node.
 
Method Summary
 void addListener(Listener listener)
          Adds a configuration changes listener.
protected  void check()
          Checks if the underling configuration has been changed and notifies listeners of the change.
static Configuration getInstance(java.lang.String uri)
          Returns an instance of a Configuration subclass accordingly to the provided URI.
static Configuration getInstance(java.lang.String uri, java.util.Collection listeners)
          Returns an instance of a Configuration subclass accordingly to the provided URI monitoring it for updates which will be notified to the provided collection of listeners.
static Configuration getInstance(java.lang.String uri, Listener listener)
          Returns an instance of a Configuration subclass accordingly to the provided URI monitoring it for updates which will be notified to the provided listener.
static Configuration getInstance(java.net.URI uri)
          Returns an instance of a Configuration subclass accordingly to the provided URI.
static Configuration getInstance(java.net.URI uri, java.util.Collection listeners)
          Returns an instance of a Configuration subclass accordingly to the provided URI monitoring it for updates which will be notified to the provided collection of listeners.
static Configuration getInstance(java.net.URI uri, Listener listener)
          Returns an instance of a Configuration subclass accordingly to the provided URI monitoring it for updates which will be notified to the provided listener.
 java.util.Collection getListeners()
          Returns the registered changes listeners.
 boolean getResolve()
          Returns the resolution method adopted by this configuration tree.
protected  void init(java.lang.String name, org.xml.sax.Attributes attributes)
          Initializes this configuration with a name and a set of attributes.
abstract  boolean isChanged()
          This method checks if the source from the configuration structure was modified since it was last read.
 void removeListener(Listener listener)
          Removes a configuration changes listener.
protected  Node resolve(java.lang.String name, java.lang.String id)
          Resolves the requested reference through its children nodes or, recursively in the parent node children.
 void setResolve(boolean resolve)
          Sets the resolution method to adopt while querying this configuration tree.
abstract  void update()
          Ensures the in memory representation of the configuration matches with the underlying representation.
 
Methods inherited from class net.smartlab.config.Node
getAttribute, getAttributeNames, getAttributes, getContent, getElement, getElements, getElements, getId, resolve, setContent
 
Methods inherited from class net.smartlab.config.Element
getAttributeValues, getElement, getElement, getName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

listeners

protected java.util.Collection listeners

monitor

protected net.smartlab.config.Configuration.Monitor monitor
Constructor Detail

Configuration

protected Configuration()
Creates an instance of the class as an Element without a parent node. This constructor is providen for subclasses convenience.

Method Detail

init

protected void init(java.lang.String name,
                    org.xml.sax.Attributes attributes)
Initializes this configuration with a name and a set of attributes.

Parameters:
name - the name of the configuration tree.
attributes - a set of attributes relative to the global configuration tree.

resolve

protected Node resolve(java.lang.String name,
                       java.lang.String id)
                throws ConfigurationException
Description copied from class: Node
Resolves the requested reference through its children nodes or, recursively in the parent node children.

Overrides:
resolve in class Node
Parameters:
name - the referenced element name.
id - the referenced element identifier.
Returns:
the referenced element.
Throws:
ConfigurationException - if the referenced element cannot be found in the wntire configuration tree.
See Also:
Node.resolve(java.lang.String, java.lang.String)

isChanged

public abstract boolean isChanged()
                           throws ConfigurationException
This method checks if the source from the configuration structure was modified since it was last read.

Returns:
true if the underlying representation of the structure was modified since last read.
Throws:
ConfigurationException - if something wrong occurred while checking the underlaying structure like the file is no more readable or the stream no more available.

update

public abstract void update()
                     throws ConfigurationException
Ensures the in memory representation of the configuration matches with the underlying representation.

Throws:
ConfigurationException - if the underlying representation of the structure is no more accessible or the decoding process fails due to an unappropriately initialized Cipher.

setResolve

public void setResolve(boolean resolve)
Sets the resolution method to adopt while querying this configuration tree. When set to true all internal references are automatically resolved to the destination node if present in the configuration tree.

Parameters:
resolve - the resolution method to adopt.

getResolve

public boolean getResolve()
Returns the resolution method adopted by this configuration tree.

Returns:
true if internal references should be automatically resolved.

getListeners

public java.util.Collection getListeners()
Returns the registered changes listeners.

Returns:
the registered changes listeners.

addListener

public void addListener(Listener listener)
Adds a configuration changes listener.

Parameters:
listener - the listener to add.

removeListener

public void removeListener(Listener listener)
Removes a configuration changes listener.

Parameters:
listener - the listener to remove.

getInstance

public static final Configuration getInstance(java.lang.String uri)
                                       throws ConfigurationException,
                                              java.net.URISyntaxException
Returns an instance of a Configuration subclass accordingly to the provided URI. Monitoring interval can be set through the system property smartconfig.monitor.delay expressed in milliseconds and defaulting to 60000.

Parameters:
uri - the URI to access the configuration.
Returns:
an instance of a Configuration subclass.
Throws:
ConfigurationException - if no handler matches the specified URI or an error is encountered trying to access the configuration URI.
java.net.URISyntaxException

getInstance

public static final Configuration getInstance(java.lang.String uri,
                                              Listener listener)
                                       throws ConfigurationException,
                                              java.net.URISyntaxException
Returns an instance of a Configuration subclass accordingly to the provided URI monitoring it for updates which will be notified to the provided listener. Monitoring interval can be set through the system property smartconfig.monitor.delay expressed in milliseconds and defaulting to 60000.

Parameters:
uri - the URI to access the configuration.
listener - a Listener interface implementation.
Returns:
an instance of a Configuration subclass.
Throws:
ConfigurationException - if no handler matches the specified URI or an error is encountered trying to access the configuration URI.
java.net.URISyntaxException

getInstance

public static final Configuration getInstance(java.lang.String uri,
                                              java.util.Collection listeners)
                                       throws ConfigurationException,
                                              java.net.URISyntaxException
Returns an instance of a Configuration subclass accordingly to the provided URI monitoring it for updates which will be notified to the provided collection of listeners. Monitoring interval can be set through the system property smartconfig.monitor.delay expressed in milliseconds and defaulting to 60000.

Parameters:
uri - the URI to access the configuration.
listeners - a collection of Listener interface implementors.
Returns:
an instance of a Configuration subclass.
Throws:
ConfigurationException - if no handler matches the specified URI or an error is encountered trying to access the configuration URI.
java.net.URISyntaxException

getInstance

public static final Configuration getInstance(java.net.URI uri)
                                       throws ConfigurationException
Returns an instance of a Configuration subclass accordingly to the provided URI. Monitoring interval can be set through the system property smartconfig.monitor.delay expressed in milliseconds and defaulting to 60000.

Parameters:
uri - the URI to access the configuration.
Returns:
an instance of a Configuration subclass.
Throws:
ConfigurationException - if no handler matches the specified URI or an error is encountered trying to access the configuration URI.

getInstance

public static final Configuration getInstance(java.net.URI uri,
                                              Listener listener)
                                       throws ConfigurationException
Returns an instance of a Configuration subclass accordingly to the provided URI monitoring it for updates which will be notified to the provided listener. Monitoring interval can be set through the system property smartconfig.monitor.delay expressed in milliseconds and defaulting to 60000.

Parameters:
uri - the URI to access the configuration.
listener - a Listener interface implementation.
Returns:
an instance of a Configuration subclass.
Throws:
ConfigurationException - if no handler matches the specified URI or an error is encountered trying to access the configuration URI.

getInstance

public static final Configuration getInstance(java.net.URI uri,
                                              java.util.Collection listeners)
                                       throws ConfigurationException
Returns an instance of a Configuration subclass accordingly to the provided URI monitoring it for updates which will be notified to the provided collection of listeners. Monitoring interval can be set through the system property smartconfig.monitor.delay expressed in milliseconds and defaulting to 60000.

Parameters:
uri - the URI to access the configuration.
listeners - a collection of Listener interface implementors.
Returns:
an instance of a Configuration subclass.
Throws:
ConfigurationException - if no handler matches the specified URI or an error is encountered trying to access the configuration URI.

check

protected final void check()
Checks if the underling configuration has been changed and notifies listeners of the change.



Copyright © 2002-2008 SmartLab s.r.l.. All Rights Reserved.