FreeHEP API
Version current

org.freehep.util.parameterdatabase
Class ParameterDatabase

java.lang.Object
  extended byorg.freehep.util.parameterdatabase.ParameterDatabase

public class ParameterDatabase
extends Object

Source Code:
ParameterDatabase.java

Field Summary
protected  Hashtable database
          The hashtable which contains all of the parameters.
protected  LinkedList databaseListeners
          This list contains all of the database listeners.
 
Constructor Summary
ParameterDatabase()
          Constructor creates the hashtable to hold all of the parameters.
ParameterDatabase(int size)
          Constructor creates the hashtable of the given initial size to hold all of the parameters.
 
Method Summary
 void addDatabaseListener(DatabaseListener listener)
          Add a database listener.
 boolean addParameter(String parameterName, Object value, Iterator iterator, PropertyChangeListener listener)
          Add a parameter to the database.
 boolean addParameter(String parameterName, Object value, Iterator iterator, PropertyChangeListener listener, boolean overwrite)
          Add a parameter to the database.
 void clear()
          Completely clear this parameter database.
 Hashtable cloneLocalParameters(Object object)
          Return a hash table in which the keys are the parameter names and the values are clones of those values in the database.
protected  Object cloneObject(Object originalObject)
          This will "clone" the given object.
 void firePropertyChange(String parameterName, ParameterValue parameterValue)
          Send off the property change event.
 String[] getCurrentParameterSet(Iterator iterator)
          Get a string array which contains the names of all parameters defined by this iterator.
 String[] getLocalParameterSet(Object object)
          Get a string array which gives all of the parameters which are defined locally on the given object.
 Object getParameter(String parameterName, Iterator iterator)
          Retrieve a parameter from the database.
 boolean isParameterDefined(String parameterName, Iterator iterator)
          Return a boolean indicating whether this parameter is defined using the given iterator to iterate through a set of objects.
 boolean isParameterDefined(String parameterName, Object object)
          Return a boolean indicating whether this parameter is defined for the given object.
 boolean isParameterLocal(String parameterName, Iterator iterator)
          This method will determine if the given parameter is local.
 void purgeEntries(Object object)
          Purge all entries based on a particular object.
 void purgeParameter(String parameterName, Iterator iterator)
          Purge a parameter from the list of objects defined by the iterator.
 void purgePropertyChangeListener(Iterator iterator, PropertyChangeListener listener)
          Purge all references to a particular listener.
 void purgePropertyChangeListener(PropertyChangeListener listener)
          Purge all references to a particular listener.
 void removeDatabaseListener(DatabaseListener listener)
          Remove a database listener
 boolean removeParameter(String parameterName, Iterator iterator)
          Remove a parameter from the database.
 boolean setParameter(String parameterName, Object value, Iterator iterator)
          Set a parameter.
 boolean writeAsXML(XMLWriter xmlWriter, Hashtable instanceMap)
          Write out the entire database as an XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

database

protected Hashtable database
The hashtable which contains all of the parameters.


databaseListeners

protected LinkedList databaseListeners
This list contains all of the database listeners.

Constructor Detail

ParameterDatabase

public ParameterDatabase()
Constructor creates the hashtable to hold all of the parameters. The default size is 10000 entries.


ParameterDatabase

public ParameterDatabase(int size)
Constructor creates the hashtable of the given initial size to hold all of the parameters.

Method Detail

isParameterLocal

public boolean isParameterLocal(String parameterName,
                                Iterator iterator)
This method will determine if the given parameter is local. That is, that the parameter is defined on the first object returned from the iterator.


getParameter

public Object getParameter(String parameterName,
                           Iterator iterator)
Retrieve a parameter from the database. The iterator must produce a sequence of Objects which correspond to the specific tables in which to try to find the parameter. The iteration will stop when the parameter is first found.


setParameter

public boolean setParameter(String parameterName,
                            Object value,
                            Iterator iterator)
Set a parameter. Use the iterator to traverse a series of tables in which to find the given parameter. Only the first parameter with this name will be modified. This method returns true if the parameter was found and set; it returns false otherwise.


isParameterDefined

public boolean isParameterDefined(String parameterName,
                                  Iterator iterator)
Return a boolean indicating whether this parameter is defined using the given iterator to iterate through a set of objects.


isParameterDefined

public boolean isParameterDefined(String parameterName,
                                  Object object)
Return a boolean indicating whether this parameter is defined for the given object.


addParameter

public boolean addParameter(String parameterName,
                            Object value,
                            Iterator iterator,
                            PropertyChangeListener listener)
Add a parameter to the database. This will only add the parameter to the first object returned by the given iterator. After the parameter is added, the listener will be added to the value. This same listener will be removed from the next visible parameter of the same name. If the parameter already exists, the listener is added but the value is not modified.


addParameter

public boolean addParameter(String parameterName,
                            Object value,
                            Iterator iterator,
                            PropertyChangeListener listener,
                            boolean overwrite)
Add a parameter to the database. This will only add the parameter to the first object returned by the given iterator. After the parameter is added, the listener will be added to the value. This same listener will be removed from the next visible parameter of the same name. If the parameter already exists, the listener is added but the value is not modified unless overwrite is true.


removeParameter

public boolean removeParameter(String parameterName,
                               Iterator iterator)
Remove a parameter from the database. This will only remove the parameter from the first object returned by the given iterator. After the parameter is removed, the listeners from this entry will be added to the next visible value.


purgeParameter

public void purgeParameter(String parameterName,
                           Iterator iterator)
Purge a parameter from the list of objects defined by the iterator.


purgeEntries

public void purgeEntries(Object object)
Purge all entries based on a particular object.


purgePropertyChangeListener

public void purgePropertyChangeListener(PropertyChangeListener listener)
Purge all references to a particular listener.


purgePropertyChangeListener

public void purgePropertyChangeListener(Iterator iterator,
                                        PropertyChangeListener listener)
Purge all references to a particular listener.


clear

public void clear()
Completely clear this parameter database.


writeAsXML

public boolean writeAsXML(XMLWriter xmlWriter,
                          Hashtable instanceMap)
Write out the entire database as an XML file. Returns true if there were no errors generated; returns false otherwise. Note that this simply appends a parameters element to the given XMLWriter. The instanceMap must map instances of non-Class objects to a unique Integer. The integer value is used to tag "local" copies of parameters. If null is passed in as the instanceMap none of the local copies of parameters will be saved.


firePropertyChange

public void firePropertyChange(String parameterName,
                               ParameterValue parameterValue)
Send off the property change event.


addDatabaseListener

public void addDatabaseListener(DatabaseListener listener)
Add a database listener.


removeDatabaseListener

public void removeDatabaseListener(DatabaseListener listener)
Remove a database listener


getCurrentParameterSet

public String[] getCurrentParameterSet(Iterator iterator)
Get a string array which contains the names of all parameters defined by this iterator. Note that all parameters in the database are checked to see if they match the given objects.


getLocalParameterSet

public String[] getLocalParameterSet(Object object)
Get a string array which gives all of the parameters which are defined locally on the given object.


cloneLocalParameters

public Hashtable cloneLocalParameters(Object object)
Return a hash table in which the keys are the parameter names and the values are clones of those values in the database.


cloneObject

protected Object cloneObject(Object originalObject)
                      throws NoSuchMethodException,
                             InstantiationException,
                             IllegalAccessException,
                             InvocationTargetException
This will "clone" the given object. This method makes the assumption that the objects stored in the database produce a result from the toString() method which will then produce an identical object when the single-string constructor is called. (Note: this is a general assumption of the database as a whole.)

Throws:
NoSuchMethodException
InstantiationException
IllegalAccessException
InvocationTargetException

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.