|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.Observable anon.infoservice.Database
public final class Database
This class is the generic implementation of a database. It is used by the database implementations for the different services. It is also a registry for all databases used in the context of this application. Instances of this class are observable. Observers of the instances are notified, if an entry is added, renewed or removed from the database or if the whole database is cleared. The observers will always get a DatabaseMessage object as the argument of the update() method. The DatabaseMessage will identify the reason of the notification, see the DatabaseMessage class for more information.
Field Summary | |
---|---|
private java.lang.Class |
m_DatabaseEntryClass
The DatabaseEntry class for that this Database is registered. |
private static java.util.Hashtable |
m_databases
The registered databases. |
private static IDistributor |
m_distributor
The distributor that forwards new database entries. |
private java.util.Hashtable |
m_serviceDatabase
Stores services we know. |
private java.util.Vector |
m_timeoutList
Chronological order (in relation to timeouts) of all objects in the database. |
Fields inherited from interface anon.util.IXMLEncodable |
---|
FIELD_XML_ELEMENT_CONTAINER_NAME, FIELD_XML_ELEMENT_NAME, XML_ATTR_ID, XML_ATTR_VERSION |
Constructor Summary | |
---|---|
private |
Database(java.lang.Class a_DatabaseEntryClass)
Creates a new instance of a Database. |
Method Summary | |
---|---|
void |
addObserver(java.util.Observer a_observer)
Adds an observer to this database. |
AbstractDatabaseEntry |
getEntryById(java.lang.String entryId)
Returns the DatabaseEntry with the given ID. |
java.lang.Class |
getEntryClass()
Returns the DatabaseEntry class for that this Database is registered. |
java.util.Hashtable |
getEntryHash()
|
java.util.Vector |
getEntryList()
Returns a snapshot of all values in the serviceDatabase. |
java.util.Enumeration |
getEntrySnapshotAsEnumeration()
Returns a snapshot of all entries in the Database as an Enumeration. |
static Database |
getInstance(java.lang.Class a_DatabaseEntryClass)
Gets the Database for the specified database entries. |
static java.util.Enumeration |
getInstances()
Get an Enumeration of all registered Databases. |
int |
getNumberOfEntries()
Returns the number of DatabaseEntries in the Database. |
AbstractDatabaseEntry |
getRandomEntry()
Returns a random entry from the database. |
int |
getTimeoutListSize()
|
boolean |
isEntryIdInTimeoutList(java.lang.String a_entryId)
|
int |
loadFromXml(org.w3c.dom.Element a_dbNode)
Adds all database entries that are subnodes of the given element to the database. |
static void |
registerDistributor(IDistributor a_distributor)
Registers a distributor that forwards new database entries. |
private static Database |
registerInstance(Database a_Database)
Registers a Database object. |
boolean |
remove(AbstractDatabaseEntry a_deleteEntry)
Removes an entry from the database. |
boolean |
remove(java.lang.String a_entryID)
Removes an entry from the database. |
void |
removeAll()
Removes all entries from the database. |
void |
run()
This is the garbage collector for the database. |
org.w3c.dom.Element |
toXmlElement(org.w3c.dom.Document a_doc)
If the entries of this database implement IXMLEncodable and has a proper value for the field XML_ELEMENT_CONTAINER_NAME, this database is transormed into an XML element. |
org.w3c.dom.Element |
toXmlElement(org.w3c.dom.Document a_doc,
java.lang.String a_xmlContainerName)
Creates an XML node with all database entries, but only for those entries that implement IXMLEncodable. |
private static Database |
unregisterInstance(java.lang.Class a_DatabaseEntryClass)
Unregisters the Database object that contains instances of the specified DatabaseEntry class. |
private static void |
unregisterInstances()
Unregisters all Database instances This method is used for testing purposes and should not be removed. |
boolean |
update(AbstractDatabaseEntry newEntry)
Updates an entry in the database. |
boolean |
update(AbstractDatabaseEntry newEntry,
boolean a_bDistribute)
Updates an entry in the database. |
Methods inherited from class java.util.Observable |
---|
clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static java.util.Hashtable m_databases
private static IDistributor m_distributor
private java.lang.Class m_DatabaseEntryClass
private java.util.Hashtable m_serviceDatabase
private java.util.Vector m_timeoutList
Constructor Detail |
---|
private Database(java.lang.Class a_DatabaseEntryClass) throws java.lang.IllegalArgumentException
a_DatabaseEntryClass
- the DatabaseEntry class for that this Database is registered
java.lang.IllegalArgumentException
- if the argument is no valid DatabaseEntry classMethod Detail |
---|
public static void registerDistributor(IDistributor a_distributor)
a_distributor
- a distributor that forwards new database entriesprivate static Database registerInstance(Database a_Database)
a_Database
- the registered Database
private static Database unregisterInstance(java.lang.Class a_DatabaseEntryClass)
a_DatabaseEntryClass
- the DatabaseEntry class for that the corresponding Database
is unregistered
private static void unregisterInstances()
public static Database getInstance(java.lang.Class a_DatabaseEntryClass) throws java.lang.IllegalArgumentException
a_DatabaseEntryClass
- the DatabaseEntry class for that the method returns
the corresponding Database object
java.lang.IllegalArgumentException
- if the argument is no valid DatabaseEntry classpublic static java.util.Enumeration getInstances()
public void run()
run
in interface java.lang.Runnable
public boolean update(AbstractDatabaseEntry newEntry) throws java.lang.IllegalArgumentException
newEntry
- The database entry to update.
java.lang.IllegalArgumentException
- if the database entry is not of the type the Database
can storepublic boolean update(AbstractDatabaseEntry newEntry, boolean a_bDistribute) throws java.lang.IllegalArgumentException
newEntry
- The database entry to update.a_bDistribute
- distribute to other InfoServices if distributor object is set; should be default
java.lang.IllegalArgumentException
- if the database entry is not of the type the Database
can storepublic java.lang.Class getEntryClass()
public boolean remove(java.lang.String a_entryID)
a_entryID
- The ID of the entry to remove. If it is not in the database, nothing is done.
public boolean remove(AbstractDatabaseEntry a_deleteEntry)
a_deleteEntry
- The entry to remove. If it is not in the database, nothing is done.
public void removeAll()
public int loadFromXml(org.w3c.dom.Element a_dbNode)
a_dbNode
- The xml node that contains db entries.
public org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
toXmlElement
in interface IXMLEncodable
a_doc
- a Document
public org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc, java.lang.String a_xmlContainerName)
a_doc
- The XML document, which is the environment for the created XML node.a_xmlContainerName
- the name of the XML element that should contain the entries
public java.util.Hashtable getEntryHash()
public java.util.Vector getEntryList()
public java.util.Enumeration getEntrySnapshotAsEnumeration()
public int getNumberOfEntries()
public AbstractDatabaseEntry getEntryById(java.lang.String entryId)
entryId
- The ID of the database entry.
public AbstractDatabaseEntry getRandomEntry()
public void addObserver(java.util.Observer a_observer)
addObserver
in class java.util.Observable
a_observer
- The observer to add to this database.public boolean isEntryIdInTimeoutList(java.lang.String a_entryId)
public int getTimeoutListSize()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |