discovery.data
Class NarrativeDataManager

java.lang.Object
  extended by discovery.data.NarrativeDataManager

public class NarrativeDataManager
extends java.lang.Object

This class is responsible for all program interaction with the narrative database. All narrative information is saved in an XML file called 'narratives.xml', which is found in the current project's folder in the workspace directory. The class uses the JDOM package to deal with all XML operations. Methods are included to save and load the XML file. Narratives can be added, updated and deleted using the relevant methods. Accessor methods are also included, allowing Narrative objects to be built from the data and returned.


Constructor Summary
NarrativeDataManager()
           
 
Method Summary
 void addNarrative(NarrativeModel n)
          This is a mutator method which adds the data held within a Narrative object to the 'narratives.xml' file.
 void deleteNarrative(int toFind)
          This is a mutator method which deletes a narrative from the 'narratives.xml' file.
 NarrativeModel getNarrative(int toFind)
          This is an accessor method which returns a Narrative object of a narrative in the database.
 org.jdom.Document loadDatabase()
          This method uses the SAXBuilder class to construct a Document object of the XML data held within the 'narratives.xml' file.
 void saveDatabase(org.jdom.Document doc)
          This method saves the data in a Document object to the XML file 'narratives.xml'.
 void updateNarrative(NarrativeModel n)
          This is a mutator method which updates a narrative in the XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NarrativeDataManager

public NarrativeDataManager()
Method Detail

loadDatabase

public org.jdom.Document loadDatabase()
This method uses the SAXBuilder class to construct a Document object of the XML data held within the 'narratives.xml' file. The Document object representing the file is returned. Returns null if the file cannot be found.

Returns:
a JDOM Document object representing the 'narratives.xml' file

saveDatabase

public void saveDatabase(org.jdom.Document doc)
This method saves the data in a Document object to the XML file 'narratives.xml'. It uses the XMLOutputter class to write the data to file with correct XML formatting. If the file doesn't already exist, this method creates it.

Parameters:
doc - the JDOM document object representing the data to be saved

addNarrative

public void addNarrative(NarrativeModel n)
This is a mutator method which adds the data held within a Narrative object to the 'narratives.xml' file.

Parameters:
cm - the Narrative object representing the narrative to be added to the file

deleteNarrative

public void deleteNarrative(int toFind)
This is a mutator method which deletes a narrative from the 'narratives.xml' file. This method takes an integer, representing the unique ID number of the narrative to be deleted. If there is no narrative with the supplied ID in the database, then no narrative is deleted.

Parameters:
toFind - the ID number of the narrative to be deleted

updateNarrative

public void updateNarrative(NarrativeModel n)
This is a mutator method which updates a narrative in the XML file. The method is supplied with a Narrative object, and if there already exists a narrative with the supplied Narrative's ID in the database, this narrative is updated with the data in the Narrative.

Parameters:
cm - the Narrative object representing the updated version of the narrative

getNarrative

public NarrativeModel getNarrative(int toFind)
This is an accessor method which returns a Narrative object of a narrative in the database. This method takes and integer representing the desired narrative's ID number. If a narrative with the supplied ID exists in the database, it is returned. Otherwise, null is returned.

Parameters:
toFind - an integer representing the ID number of the desired narrative
Returns:
a Narrative object representing the requested narrative