erland.util
Class ParameterStorageString

java.lang.Object
  extended by erland.util.ParameterStorageString
All Implemented Interfaces:
ParameterValueStorageExInterface, ParameterValueStorageInterface
Direct Known Subclasses:
ParameterStorageGroup, ParameterStorageStringEx

public class ParameterStorageString
extends Object
implements ParameterValueStorageExInterface

Get, set or delete parameters stored in a file

Author:
Erland Isaksson

Constructor Summary
ParameterStorageString(StorageInterface primaryStorage, StorageInterface secondaryStorage)
          Createa a storage object
ParameterStorageString(StorageInterface primaryStorage, StorageInterface secondaryStorage, String documentName)
          Creates a storage object
 
Method Summary
protected  XMLNode addChild(XMLNode parent, String name, String value)
          Add a child XMLNode object to the specified parent, the value of the child object will be parsed to a child tree if it contains XML
protected  XMLNode addChildAsStorage(XMLNode parent, String name, StorageInterface value)
          Add a child XMLNode object to the specified parent, the value of the child object is a StorageInterface object and will be parsed to a child tree if it contains XML
 void delParameter(String name)
          Delete a parameter
protected  void delSpecialParameterInData(XMLNode data, String name)
          Delets a parameter in the XMLNode tree specified, this method is only called if isSpecialHandled(String) returns true
protected  StorageInterface getNodeAsStorage(XMLNode node, String name)
          Return the specified node as a storage.
 String getParameter(String name)
          Get a parameter value
 StorageInterface getParameterAsStorage(String name)
          Retreives the parameter as a StorageInterface object instead of a value Observe that this is a new StorageInterface object and will not be related to any of your other StorageInterface objects
protected  StorageInterface getSpecialParameterAsStorageInData(XMLNode data, String name)
          Gets a storage object for a parameter from the XMLNode tree specified, this method is only called if isSpecialHandled(String) returns true
protected  String getSpecialParameterInData(XMLNode data, String name)
          Gets the parameter value for a parameter from the XMLNode tree specified, this method is only called if isSpecialHandled(String) returns true
protected  void init(StorageInterface primaryStorage, StorageInterface secondaryStorage, String documentName)
          Initialize this object
protected  boolean isSpecialHandled(String name)
          Check if this parameter should be special handled, will be autmatically called when a parameter is accessed.
protected  void setNodeAsStorage(XMLNode node, String name, StorageInterface value)
          Set the specified node as a storage.
 void setParameter(String name, String value)
          Set a parameter value
 void setParameterAsStorage(String name, StorageInterface value)
          Sets the parameter as a StorageInterface object instead of a value Observe that this is a new StorageInterface object must have been retreived with the ParameterValueStorageExInterface.getParameterAsStorage(String) method
protected  void setSpecialParameterAsStorageInData(XMLNode data, String name, StorageInterface value)
          Sets the parameter value for a parameter in the XMLNode tree specified, this method is only called if isSpecialHandled(String) returns true The value is specified as a StorageInterface object
protected  void setSpecialParameterInData(XMLNode data, String name, String value)
          Sets the parameter value for a parameter in the XMLNode tree specified, this method is only called if isSpecialHandled(String) returns true
protected  void setValue(XMLNode node, String value)
          Sets the value of a XMLNode object, the value will be parsed to a child tree if it contains XML
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParameterStorageString

public ParameterStorageString(StorageInterface primaryStorage,
                              StorageInterface secondaryStorage)
Createa a storage object

Parameters:
primaryStorage - The storage object which the parameters should be read/write from/to
secondaryStorage - The storage object which the parameters should be read from if they don't exist in the primaryStorage

ParameterStorageString

public ParameterStorageString(StorageInterface primaryStorage,
                              StorageInterface secondaryStorage,
                              String documentName)
Creates a storage object

Parameters:
primaryStorage - The storage object which the parameters should be read/write from/to
secondaryStorage - The storage object which the parameters should be read from if they don't exist in the primaryStorage
documentName - The name of the section in the storage where parameters are stored
Method Detail

init

protected void init(StorageInterface primaryStorage,
                    StorageInterface secondaryStorage,
                    String documentName)
Initialize this object

Parameters:
primaryStorage - The storage object which the parameters should be read/write from/to
secondaryStorage - The storage object which the parameters should be read from if they don't exist in the primaryStorage
documentName - The name of the section in the file where parameters are stored

isSpecialHandled

protected boolean isSpecialHandled(String name)
Check if this parameter should be special handled, will be autmatically called when a parameter is accessed. Implement this in your sub class if you want to handle some parameters in a special way.

Parameters:
name - The parameter name
Returns:
Always false
true - This parameter should be special handled,then one of 
         getSpecialParameterInData(erland.util.XMLNode,String), setSpecialParameterInData(erland.util.XMLNode,String,String), delSpecialParameterInData(erland.util.XMLNode,String),
         will be called to access the parameter
false - This parameter is handled in the normal way, one of
         getParameter(String), setParameter(String,String), delParameter(String), 
         will be called to access the parameter

getSpecialParameterInData

protected String getSpecialParameterInData(XMLNode data,
                                           String name)
Gets the parameter value for a parameter from the XMLNode tree specified, this method is only called if isSpecialHandled(String) returns true

Parameters:
data - The XMLNode tree to search for the parameter in
name - The parameter name of the parameter
Returns:
The value of the parameter

getSpecialParameterAsStorageInData

protected StorageInterface getSpecialParameterAsStorageInData(XMLNode data,
                                                              String name)
Gets a storage object for a parameter from the XMLNode tree specified, this method is only called if isSpecialHandled(String) returns true

Parameters:
data - The XMLNode tree to search for the parameter in
name - The parameter name of the parameter
Returns:
The storage object for the parameter

getParameter

public String getParameter(String name)
Description copied from interface: ParameterValueStorageInterface
Get a parameter value

Specified by:
getParameter in interface ParameterValueStorageInterface
Parameters:
name - The name of the parameter
Returns:
The value of the parameter, will be an empty string if the parameter does not exist

setSpecialParameterInData

protected void setSpecialParameterInData(XMLNode data,
                                         String name,
                                         String value)
Sets the parameter value for a parameter in the XMLNode tree specified, this method is only called if isSpecialHandled(String) returns true

Parameters:
data - The XMLNode tree to set the parameter in
name - The parameter name of the parameter
value - The parameter value of the parameter

setSpecialParameterAsStorageInData

protected void setSpecialParameterAsStorageInData(XMLNode data,
                                                  String name,
                                                  StorageInterface value)
Sets the parameter value for a parameter in the XMLNode tree specified, this method is only called if isSpecialHandled(String) returns true The value is specified as a StorageInterface object

Parameters:
data - The XMLNode tree to set the parameter in
name - The parameter name of the parameter
value - The parameter value of the parameter

setParameter

public void setParameter(String name,
                         String value)
Description copied from interface: ParameterValueStorageInterface
Set a parameter value

Specified by:
setParameter in interface ParameterValueStorageInterface
Parameters:
name - The name of the parameter
value - The value of the parameter

addChild

protected XMLNode addChild(XMLNode parent,
                           String name,
                           String value)
Add a child XMLNode object to the specified parent, the value of the child object will be parsed to a child tree if it contains XML

Parameters:
parent - The parent XMLNode object
name - The name of the child object
value - The value of the child object
Returns:
The added child XMLNode object

addChildAsStorage

protected XMLNode addChildAsStorage(XMLNode parent,
                                    String name,
                                    StorageInterface value)
Add a child XMLNode object to the specified parent, the value of the child object is a StorageInterface object and will be parsed to a child tree if it contains XML

Parameters:
parent - The parent XMLNode object
name - The name of the child object
value - The value of the child object
Returns:
The added child XMLNode object

setValue

protected void setValue(XMLNode node,
                        String value)
Sets the value of a XMLNode object, the value will be parsed to a child tree if it contains XML

Parameters:
node - The XMLNode object to set value on
value - The value to set

delSpecialParameterInData

protected void delSpecialParameterInData(XMLNode data,
                                         String name)
Delets a parameter in the XMLNode tree specified, this method is only called if isSpecialHandled(String) returns true

Parameters:
data - The XMLNode tree to set the parameter in
name - The parameter name of the parameter

delParameter

public void delParameter(String name)
Description copied from interface: ParameterValueStorageInterface
Delete a parameter

Specified by:
delParameter in interface ParameterValueStorageInterface
Parameters:
name - The name of the parameter

toString

public String toString()
Overrides:
toString in class Object

getParameterAsStorage

public StorageInterface getParameterAsStorage(String name)
Description copied from interface: ParameterValueStorageExInterface
Retreives the parameter as a StorageInterface object instead of a value Observe that this is a new StorageInterface object and will not be related to any of your other StorageInterface objects

Specified by:
getParameterAsStorage in interface ParameterValueStorageExInterface
Parameters:
name - The name of the parameter to retreive
Returns:
A StorageInterface object containing the value of the parameter

getNodeAsStorage

protected StorageInterface getNodeAsStorage(XMLNode node,
                                            String name)
Return the specified node as a storage. This method can be overridden by sub classes in case you want to control which node that is returned or which type of storage that is returned

Parameters:
node - The node that matched the parameter name
name - The parameter name that was searched for
Returns:
The storage for the node

setNodeAsStorage

protected void setNodeAsStorage(XMLNode node,
                                String name,
                                StorageInterface value)
Set the specified node as a storage. This method can be overridden by sub classes in case you want to control which node that is modified or which type of storage that is set/allowed

Parameters:
node - The node that matched the parameter name
name - The parameter name that was searched for
value - The value as a StorageInterface object

setParameterAsStorage

public void setParameterAsStorage(String name,
                                  StorageInterface value)
Description copied from interface: ParameterValueStorageExInterface
Sets the parameter as a StorageInterface object instead of a value Observe that this is a new StorageInterface object must have been retreived with the ParameterValueStorageExInterface.getParameterAsStorage(String) method

Specified by:
setParameterAsStorage in interface ParameterValueStorageExInterface
Parameters:
name - The name of the parameter to set
value - The value as a StorageInterface object


Copyright © 2003-2005 Erland Isaksson. All Rights Reserved.