net.smartlab.config
Class XMLConfiguration

java.lang.Object
  extended by net.smartlab.config.Element
      extended by net.smartlab.config.Node
          extended by net.smartlab.config.Configuration
              extended by net.smartlab.config.XMLConfiguration

public final class XMLConfiguration
extends Configuration

Represents a configuration expressed through an XML document.

Author:
rlogiacco

Nested Class Summary
protected static class XMLConfiguration.XMLHandler
          SAX Handler implementation to provide the in-memory representation of an XML configuration file.
 
Field Summary
 
Fields inherited from class net.smartlab.config.Configuration
listeners, 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
XMLConfiguration(java.io.File source)
          Constructs a configuration structure from an XML file.
XMLConfiguration(java.io.File source, javax.crypto.Cipher cipher)
          Constructs a configuration structure from an encrypted XML file.
XMLConfiguration(java.lang.String source)
          Constructs a configuration structure from an XML file accessible through a file system dependent string representation of a path.
XMLConfiguration(java.lang.String source, javax.crypto.Cipher cipher)
          Constructs a configuration structure from an encrypted XML file accessible through a file system dependent string representation of a path.
XMLConfiguration(java.net.URL source)
          Constructs a configuration structure from an XML stream of characters.
XMLConfiguration(java.net.URL source, javax.crypto.Cipher cipher)
          Constructs a configuration structure from an encrypted XML stream of characters.
 
Method Summary
static void encrypt(java.io.File plain, java.io.File symKey, java.io.File ciphered, java.lang.String algorithm)
          TODO documentation
 boolean isChanged()
          This method checks if the source from the configuration structure was modified since it was last read.
 void update()
          Ensures the in memory representation of the configuration matches with the underlying representation.
 
Methods inherited from class net.smartlab.config.Configuration
addListener, check, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getListeners, getResolve, init, removeListener, resolve, setResolve
 
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
 

Constructor Detail

XMLConfiguration

public XMLConfiguration(java.io.File source)
                 throws ConfigurationException
Constructs a configuration structure from an XML file.

Parameters:
source - a File object pointing to the underlying represantation of the configuration.
Throws:
ConfigurationException - if the file specified is not a valid XML file or is no more readable.

XMLConfiguration

public XMLConfiguration(java.lang.String source)
                 throws ConfigurationException
Constructs a configuration structure from an XML file accessible through a file system dependent string representation of a path.

Parameters:
source - a String representation of a system dependant path pointing to a valid configuration representation.
Throws:
ConfigurationException - if the file is not a valid XML file or is no more accessible through the specified path.

XMLConfiguration

public XMLConfiguration(java.net.URL source)
                 throws ConfigurationException
Constructs a configuration structure from an XML stream of characters. The isChanged method returns always false

Parameters:
source - a stream of characters representing a valid XML document.
Throws:
ConfigurationException - if the stream doesn't represent a valid XML document or if an IO error were generated while accessing the stream.

XMLConfiguration

public XMLConfiguration(java.io.File source,
                        javax.crypto.Cipher cipher)
                 throws ConfigurationException
Constructs a configuration structure from an encrypted XML file. This constructor needs a Cipher reference correctly initialized for the appropriate encoding scheme.

Parameters:
source - a File object pointing to the underlying represantation of the configuration.
cipher - an appropriately initialized instance of a Cipher to be used to decrypt the document.
Throws:
ConfigurationException - if the file specified is not a valid XML file or is no more readable.

XMLConfiguration

public XMLConfiguration(java.lang.String source,
                        javax.crypto.Cipher cipher)
                 throws ConfigurationException
Constructs a configuration structure from an encrypted XML file accessible through a file system dependent string representation of a path. This constructor needs a Cipher reference correctly initialized for the appropriate encoding scheme.

Parameters:
source - a String representation of a system dependant path pointing to a valid configuration representation.
cipher - an appropriately initialized instance of a Cipher to be used to decrypt the document.
Throws:
ConfigurationException - if the file is not a valid XML file or is no more accessible through the specified path.

XMLConfiguration

public XMLConfiguration(java.net.URL source,
                        javax.crypto.Cipher cipher)
                 throws ConfigurationException
Constructs a configuration structure from an encrypted XML stream of characters. This constructor needs a Cipher reference correctly initialized for the appropriate encoding scheme. The isChanged method returns true only if the update method was never called.

Parameters:
source - a stream of characters representing a valid XML document.
cipher - an appropriately initialized instance of a Cipher to be used to decrypt the document.
Throws:
ConfigurationException - if the stream doesn't represent a valid XML document or if an IO error were generated while accessing the stream.
Method Detail

isChanged

public boolean isChanged()
                  throws ConfigurationException
Description copied from class: Configuration
This method checks if the source from the configuration structure was modified since it was last read.

Specified by:
isChanged in class Configuration
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.
See Also:
Configuration.isChanged()

update

public void update()
            throws ConfigurationException
Description copied from class: Configuration
Ensures the in memory representation of the configuration matches with the underlying representation.

Specified by:
update in class Configuration
Throws:
ConfigurationException - if the underlying representation of the structure is no more accessible or the decoding process fails due to an unappropriately initialized Cipher.
See Also:
Configuration.update()

encrypt

public static void encrypt(java.io.File plain,
                           java.io.File symKey,
                           java.io.File ciphered,
                           java.lang.String algorithm)
                    throws java.io.IOException,
                           java.lang.ClassNotFoundException,
                           java.security.NoSuchAlgorithmException,
                           javax.crypto.NoSuchPaddingException,
                           java.security.InvalidKeyException
TODO documentation

Parameters:
plain -
symKey -
ciphered -
algorithm -
Throws:
java.io.IOException
java.lang.ClassNotFoundException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException


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