crn
Class CRNFileParser

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended bycrn.CRNFileParser
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class CRNFileParser
extends org.xml.sax.helpers.DefaultHandler

Parses the XML file containg the description of the CRN.

Author:
Piotrek

Field Summary
private  java.util.Hashtable caseReferences
          The hashtable mapping the IEs to the ArrayLists containg the names of referring cases (Strings).
private  java.util.ArrayList cases
          A list of parsed cases.
private  IE currentIE
          The current IE tag.
private  java.util.ArrayList ies
          A list of parsed IEs.
private  boolean inCases
          Indicates whether the parser is in the Cases section.
private  boolean inIE
          Indicates whether the parser is in the IE section.
private  boolean inIEs
          Indicates whether the parser is in the IEs section.
private  boolean inWeights
          Indicates whether the parser is in the Weights section.
private  org.xml.sax.Locator locator
          The SAX locator.
private  java.util.Hashtable weights
          The hashtable mapping the IEs' names (String) to their values (Float).
 
Constructor Summary
CRNFileParser()
          Constructor.
 
Method Summary
private  void ClearData()
          Clears all the internal data, so the parser is ready to parse a new file.
private static javax.xml.parsers.SAXParser CreateSAXParser()
          Creates an instance of the SAXParser.
 void endElement(java.lang.String uriNamespace, java.lang.String qualifiedName, java.lang.String simpleName)
           
private  CRN GetCRN()
          Creates the CRN according to the data read from the file.
 CRN Parse(java.lang.String fileName)
          Parses the given file.
 void setDocumentLocator(org.xml.sax.Locator locator)
           
 void startElement(java.lang.String uriNamespace, java.lang.String simpleName, java.lang.String qualifiedName, org.xml.sax.Attributes attributes)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

caseReferences

private java.util.Hashtable caseReferences
The hashtable mapping the IEs to the ArrayLists containg the names of referring cases (Strings).


weights

private java.util.Hashtable weights
The hashtable mapping the IEs' names (String) to their values (Float).


currentIE

private IE currentIE
The current IE tag. Needed to add the case referneces to it.


cases

private java.util.ArrayList cases
A list of parsed cases.


ies

private java.util.ArrayList ies
A list of parsed IEs.


inCases

private boolean inCases
Indicates whether the parser is in the Cases section.


inIEs

private boolean inIEs
Indicates whether the parser is in the IEs section.


inIE

private boolean inIE
Indicates whether the parser is in the IE section.


inWeights

private boolean inWeights
Indicates whether the parser is in the Weights section.


locator

private org.xml.sax.Locator locator
The SAX locator.

Constructor Detail

CRNFileParser

public CRNFileParser()
Constructor.

Method Detail

Parse

public CRN Parse(java.lang.String fileName)
          throws java.lang.Exception,
                 java.io.IOException,
                 org.xml.sax.SAXException
Parses the given file.

Parameters:
fileName - The name of the file to be parsed.
Returns:
The CRN created basing on the file.
Throws:
java.lang.Exception - Thrown in case of error.
java.io.IOException - In case of any IO error.
org.xml.sax.SAXException - In case of some parsing error.

ClearData

private void ClearData()
Clears all the internal data, so the parser is ready to parse a new file.


GetCRN

private CRN GetCRN()
Creates the CRN according to the data read from the file.

Returns:
The created CRN.

CreateSAXParser

private static javax.xml.parsers.SAXParser CreateSAXParser()
                                                    throws javax.xml.parsers.ParserConfigurationException,
                                                           org.xml.sax.SAXException
Creates an instance of the SAXParser.

Returns:
The requested parser.
Throws:
javax.xml.parsers.ParserConfigurationException - If it was imposible to create a parser satisfing the current configuration.
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String uriNamespace,
                         java.lang.String simpleName,
                         java.lang.String qualifiedName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException
See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

endElement

public void endElement(java.lang.String uriNamespace,
                       java.lang.String qualifiedName,
                       java.lang.String simpleName)
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
See Also:
ContentHandler.setDocumentLocator(org.xml.sax.Locator)