model
Class XMLFile

java.lang.Object
  extended by java.io.File
      extended by model.XMLFile
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<java.io.File>

public class XMLFile
extends java.io.File

The class is used to store the data contained in a Tournament object to the file system in XML format. The XML document is maintained in memory and when it is altered the changes are saved to disk.

See Also:
Serialized Form

Nested Class Summary
private static class XMLFile.BackupDataFileFilter
           
 
Field Summary
private  org.w3c.dom.Element base_fee
           
private  org.w3c.dom.Element confirmed_pre_entries
           
private  org.w3c.dom.Element date
           
private  org.w3c.dom.Element default_country
           
private  org.w3c.dom.Element discount_id_counter
           
private  org.w3c.dom.Element discounts
           
private  org.w3c.dom.Document doc
           
private  org.w3c.dom.Element element_id
           
private  org.w3c.dom.Element entries
           
private  org.w3c.dom.Element entry_id_counter
           
private  org.w3c.dom.Element header
           
private  org.w3c.dom.Element html
           
private  org.w3c.dom.Element name
           
private  org.w3c.dom.Element pre_entries
           
private  org.w3c.dom.Element preregistration_open
           
private static long serialVersionUID
          UID for serialization
private  org.w3c.dom.Element tournament_open
           
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
protected XMLFile(java.io.File folder, java.lang.String filename)
          Creates a pathname string and calls the constructor XMLFile(final String pathname)
protected XMLFile(java.io.File folder, java.lang.String filename, TournamentInitializer initializer)
          Creates a pathname string and calls the constructor XMLFile(final String pathname, final TournamentInitializer initializer)
protected XMLFile(java.lang.String pathname)
          Create a new XMLFile object based on a XML data file on disk
protected XMLFile(java.lang.String pathname, TournamentInitializer initializer)
          Creates a completely new tournament XML data file with data from the initializer.
 
Method Summary
protected  void addEntry(Entry... entriestoadd)
          Adds a new entry element to XML document as a child of element 'entries' with the data from the entry.
protected  void addPreEntry(Entry... preentries)
          Adds a new entry element to XML document as a child of element 'preEntries' with the data from the entry.
protected  void closeTournament()
          Sets the tournament as closed in the XML data file
protected  void confirmPreEntry(ID entry_id)
          Moves the pre-entry with the given ID under the element 'confirmedPreEntries'
private static void copyFile(java.io.File from_file, java.io.File to_file)
          Copies a file.
protected  void deleteBackupFiles()
           
protected  void deleteEntry(ID entry_id)
          Deletes an entry element that is a descendant of 'entries'
private  org.w3c.dom.Element deleteEntry(ID entry_id, org.w3c.dom.Element parent_elem)
          Deletes an entry element that is a descendant of 'parent_elem'
protected  void deletePreEntry(ID entry_id)
          Deletes an entry element that is a descendant of 'preEntries'
protected  java.util.ArrayList<Entry> getConfirmedPreEntries(Tournament tournament)
          Returns an Entry-array of all the confirmed pre-entries in the tournament file.
protected  ID getDiscountIdCounter()
           
protected  java.util.ArrayList<Entry> getEntries(Tournament tournament)
          Returns an Entry-array of all the entries in the tournament file.
private  org.w3c.dom.Element getEntryElement(ID entry_id)
           
private  org.w3c.dom.Element getEntryElement(ID entry_id, org.w3c.dom.Element parent_elem)
           
protected  ID getEntryIdCounter()
           
protected  java.util.ArrayList<Entry> getPreEntries(Tournament tournament)
          Returns an Entry-array of all the pre-entries in the tournament file.
protected  ID getTournamentId()
           
protected  TournamentInitializer getTournamentInitializer()
           
protected  ID incrementDiscountIdCounter(int increment)
          Updates the discount ID counter of the tournament
protected  ID incrementEntryIdCounter(int increment)
          Updates the entry ID counter of the tournament
protected  void openTournament()
          Sets the tournament as open in the XML data file
private  void setElementReferences()
          Sets the fields of the class to point to different elements of the XML document for convenience
protected  void updateEntry(ID entry_id, EntryUpdater updater)
          Updates the entry element with the ID 'entry_id' with the data from the updater
protected  void updateHeader(TournamentUpdater updater)
          Updates the tournament information and discounts.
protected  void write()
          Writes the XML document to disk.
 
Methods inherited from class java.io.File
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
UID for serialization

See Also:
Constant Field Values

doc

private transient org.w3c.dom.Document doc

header

private transient org.w3c.dom.Element header

element_id

private transient org.w3c.dom.Element element_id

name

private transient org.w3c.dom.Element name

html

private transient org.w3c.dom.Element html

default_country

private transient org.w3c.dom.Element default_country

date

private transient org.w3c.dom.Element date

base_fee

private transient org.w3c.dom.Element base_fee

preregistration_open

private transient org.w3c.dom.Element preregistration_open

tournament_open

private transient org.w3c.dom.Element tournament_open

discounts

private transient org.w3c.dom.Element discounts

entry_id_counter

private transient org.w3c.dom.Element entry_id_counter

discount_id_counter

private transient org.w3c.dom.Element discount_id_counter

entries

private transient org.w3c.dom.Element entries

pre_entries

private transient org.w3c.dom.Element pre_entries

confirmed_pre_entries

private transient org.w3c.dom.Element confirmed_pre_entries
Constructor Detail

XMLFile

protected XMLFile(java.lang.String pathname)
           throws DataFileException,
                  XMLParsingException
Create a new XMLFile object based on a XML data file on disk

Parameters:
pathname - absolute pathname of the XML file to be read
Throws:
DataFileException - thrown if the XML data file is not found
XMLParsingException - thrown if the data file cannot be parsed as an XML document

XMLFile

protected XMLFile(java.lang.String pathname,
                  TournamentInitializer initializer)
           throws GoException
Creates a completely new tournament XML data file with data from the initializer.

Parameters:
pathname - absolute pathname of the XMLFile to be created
Throws:
GoException - thrown if the XMLFile cannot be created or the initializer cannot be read

XMLFile

protected XMLFile(java.io.File folder,
                  java.lang.String filename)
           throws DataFileException,
                  XMLParsingException
Creates a pathname string and calls the constructor XMLFile(final String pathname)

Throws:
DataFileException
XMLParsingException

XMLFile

protected XMLFile(java.io.File folder,
                  java.lang.String filename,
                  TournamentInitializer initializer)
           throws GoException
Creates a pathname string and calls the constructor XMLFile(final String pathname, final TournamentInitializer initializer)

Throws:
GoException
Method Detail

setElementReferences

private void setElementReferences()
Sets the fields of the class to point to different elements of the XML document for convenience


getEntryElement

private org.w3c.dom.Element getEntryElement(ID entry_id)
Parameters:
entry_id - ID
Returns:
entry XML element with given ID

getEntryElement

private org.w3c.dom.Element getEntryElement(ID entry_id,
                                            org.w3c.dom.Element parent_elem)
Parameters:
entry_id - ID
parent_elem -
Returns:
entry XML element with given ID under parent element

getTournamentId

protected ID getTournamentId()
Returns:
ID of the tournament

getTournamentInitializer

protected TournamentInitializer getTournamentInitializer()
                                                  throws GoException
Returns:
a new TournamentInitializer object based on the data in the XML document
Throws:
GoException - if there is a problem with the initializer

closeTournament

protected void closeTournament()
                        throws GoIOException
Sets the tournament as closed in the XML data file

Throws:
GoIOException - if write operation fails

openTournament

protected void openTournament()
                       throws GoIOException
Sets the tournament as open in the XML data file

Throws:
GoIOException - if write operation fails

getEntryIdCounter

protected ID getEntryIdCounter()
Returns:
next available entry ID of the tournament

getDiscountIdCounter

protected ID getDiscountIdCounter()
Returns:
next available discount ID of the tournament

incrementEntryIdCounter

protected ID incrementEntryIdCounter(int increment)
                              throws GoIOException
Updates the entry ID counter of the tournament

Parameters:
increment - by how much the counter is incremented
Returns:
next available entry ID of the tournament
Throws:
GoIOException - if the write operation fails

incrementDiscountIdCounter

protected ID incrementDiscountIdCounter(int increment)
                                 throws GoIOException
Updates the discount ID counter of the tournament

Parameters:
increment - by how much the counter is incremented
Returns:
next available discount ID of the tournament
Throws:
GoIOException - if the write operation fails

addPreEntry

protected void addPreEntry(Entry... preentries)
                    throws GoIOException
Adds a new entry element to XML document as a child of element 'preEntries' with the data from the entry.

Parameters:
preentries - the pre-entries to be added
Throws:
GoIOException - if the write operation fails

addEntry

protected void addEntry(Entry... entriestoadd)
                 throws GoIOException
Adds a new entry element to XML document as a child of element 'entries' with the data from the entry.

Parameters:
entriestoadd - the entries to be added
Throws:
GoIOException - if the write operation fails

getEntries

protected java.util.ArrayList<Entry> getEntries(Tournament tournament)
                                         throws GoException
Returns an Entry-array of all the entries in the tournament file.

Throws:
GoException

getPreEntries

protected java.util.ArrayList<Entry> getPreEntries(Tournament tournament)
                                            throws GoException
Returns an Entry-array of all the pre-entries in the tournament file.

Throws:
GoException

getConfirmedPreEntries

protected java.util.ArrayList<Entry> getConfirmedPreEntries(Tournament tournament)
                                                     throws GoException
Returns an Entry-array of all the confirmed pre-entries in the tournament file.

Throws:
GoException

confirmPreEntry

protected void confirmPreEntry(ID entry_id)
                        throws GoIOException
Moves the pre-entry with the given ID under the element 'confirmedPreEntries'

Throws:
GoIOException

updateHeader

protected void updateHeader(TournamentUpdater updater)
                     throws GoIOException
Updates the tournament information and discounts.

Throws:
GoIOException

deleteEntry

protected void deleteEntry(ID entry_id)
                    throws GoIOException
Deletes an entry element that is a descendant of 'entries'

Throws:
GoIOException

deletePreEntry

protected void deletePreEntry(ID entry_id)
                       throws GoIOException
Deletes an entry element that is a descendant of 'preEntries'

Throws:
GoIOException

deleteEntry

private org.w3c.dom.Element deleteEntry(ID entry_id,
                                        org.w3c.dom.Element parent_elem)
Deletes an entry element that is a descendant of 'parent_elem'


updateEntry

protected void updateEntry(ID entry_id,
                           EntryUpdater updater)
                    throws GoIOException
Updates the entry element with the ID 'entry_id' with the data from the updater

Throws:
GoIOException

write

protected void write()
              throws GoIOException
Writes the XML document to disk. A backup copy is made to the folder given by the method Settings.getBackupFolder.

Throws:
GoIOException

copyFile

private static void copyFile(java.io.File from_file,
                             java.io.File to_file)
Copies a file. Used for creating backups of the XML data file.


deleteBackupFiles

protected void deleteBackupFiles()