org.bibalex.daf.managers.resourcemanager
Class ResourceManager

java.lang.Object
  extended by org.bibalex.daf.managers.resourcemanager.ResourceManager

public class ResourceManager
extends java.lang.Object

Handles the resource file. This class employs Singleton design pattern to enforce one instance of this class. The resource file is assumed to be in the following format:
<Resource>
<Section Name="Section Name">
<Element Name="Element Name" Caption="" Attribute1="" Attribute2="" ... />
<Element Name="Element Name" Caption="" Attribute1="" Attribute2="" ... />
.
.
.
</Section>
.
.
.
<Resource/>

Author:
Shehab.Kamal

Field Summary
private  org.w3c.dom.Node currentSection
          The current section that values are read from.
private static org.w3c.dom.Document document
          The document that is used by the ResourceManager.
private  XmlHandler handler
          An XmlHandler to handle XPath queries.
 
Constructor Summary
ResourceManager()
          Creates a new instance of ResourceManager.
 
Method Summary
 org.w3c.dom.Node getCurrentSection()
          Gets the current section in the document.
 ResourceElement getElement(java.lang.String elementName)
          Gets the ResourceElement within the given name within the
 ResourceElement[] getElements(java.lang.String sectionName)
          Gets all the ResourceElements within the given name within the
static void initialize(java.lang.String resourceFile)
          Initializes a Document to be shared among all the ResourceManager instances.
static int readInteger(java.lang.String sectionName, java.lang.String elementName, int defaultValue)
          Reads an integer from the resource file.
 boolean setCurrentSection(java.lang.String sectionName)
          Sets the current section to read values from.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

document

private static org.w3c.dom.Document document
The document that is used by the ResourceManager.


currentSection

private org.w3c.dom.Node currentSection
The current section that values are read from.


handler

private XmlHandler handler
An XmlHandler to handle XPath queries.

Constructor Detail

ResourceManager

public ResourceManager()
Creates a new instance of ResourceManager.

Method Detail

initialize

public static void initialize(java.lang.String resourceFile)
                       throws ResourceManagerException
Initializes a Document to be shared among all the ResourceManager instances.

Parameters:
resourceFile - The path of the resource file.
Throws:
ResourceManagerException - If the Document instance couldn't be created.

readInteger

public static int readInteger(java.lang.String sectionName,
                              java.lang.String elementName,
                              int defaultValue)
Reads an integer from the resource file.

Parameters:
sectionName - The section name.
elementName - The element name whose caption holds the number.
defaultValue - The default number to use if data cannot be read from the resource file.
Returns:
The inetger read from the resource file or the default value.

setCurrentSection

public boolean setCurrentSection(java.lang.String sectionName)
Sets the current section to read values from.

Parameters:
sectionName - The name of the section to use.
Returns:
True if a section with given exists as a chidl fo the root otherwise false.

getCurrentSection

public org.w3c.dom.Node getCurrentSection()
Gets the current section in the document.

Returns:
An XmlNode representing the current section of the document. If setSection hasn't been called, null is returned.

getElement

public ResourceElement getElement(java.lang.String elementName)
Gets the ResourceElement within the given name within the

Parameters:
elementName - The name of the ResourceElement to retrieve.
Returns:
A ResourceElement with the given name within the current section. If no such element exists, null is returned.

getElements

public ResourceElement[] getElements(java.lang.String sectionName)
Gets all the ResourceElements within the given name within the

Parameters:
sectionName - The name of the section to retrieve.
Returns:
A ResourceElement with the given name within the current section. If no such element exists, null is returned.