org.spaceroots.rkcheck
Class XMLFile

java.lang.Object
  extended byorg.spaceroots.rkcheck.XMLFile
All Implemented Interfaces:
org.xml.sax.ErrorHandler
Direct Known Subclasses:
RungeKuttaFile

public abstract class XMLFile
extends java.lang.Object
implements org.xml.sax.ErrorHandler

This class is the base class for application-specific XML files reading/writing.

In order to read/write application-specific XML files, a concrete class extending this abstract base class must be created and the four analyze, build, getPublicId and getSystemId methods must be implemented.

Version:
$Id: XMLFile.java,v 1.2 2004/05/23 20:14:04 luc Exp $
Author:
Luc Maisonobe

Field Summary
protected  java.lang.String uri
          URI of the configuration file.
 
Constructor Summary
XMLFile()
          Simple constructor.
 
Method Summary
abstract  void analyze(org.w3c.dom.Document document, java.lang.String uri)
          Analyze the DOM tree.
abstract  void build(org.w3c.dom.Document document, java.lang.String uri)
          Build the DOM tree.
 void error(org.xml.sax.SAXParseException exception)
          Receive notification of a recoverable error.
 void fatalError(org.xml.sax.SAXParseException exception)
          Receive notification of a non-recoverable error.
protected  java.lang.String getAttribute(org.w3c.dom.Node element, java.lang.String name, boolean missingOK)
          Get an attribute value.
protected  java.lang.String getContent(org.w3c.dom.Node node)
          Get the content of a node.
protected  org.w3c.dom.Element getElement(org.w3c.dom.Node parent, java.lang.String name, boolean missingOK)
          Get a specific child element node.
protected abstract  java.lang.String getPublicId()
          Get the public ID of the DTD.
protected abstract  java.lang.String getSystemId()
          Get the system ID of the DTD.
 void read(java.lang.String uri)
          Parse an XML document containing an application-specific configuration.
 void warning(org.xml.sax.SAXParseException exception)
          Receive notification of a warning.
 void write(java.io.Writer writer, java.lang.String uri)
          Write an XML document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uri

protected java.lang.String uri
URI of the configuration file.

Constructor Detail

XMLFile

public XMLFile()
        throws RKCheckException
Simple constructor.

Throws:
RKCheckException - if no parser can be built
Method Detail

read

public void read(java.lang.String uri)
          throws RKCheckException,
                 java.io.IOException,
                 java.io.FileNotFoundException
Parse an XML document containing an application-specific configuration.

Parameters:
uri - URI of the project document to read
Throws:
RKCheckException - if an error occurs during parsing (mainly because there is an error in the document)
java.io.IOException - if there is low level read error
java.io.FileNotFoundException - if there is low level file error

write

public void write(java.io.Writer writer,
                  java.lang.String uri)
           throws RKCheckException,
                  java.io.IOException
Write an XML document.

Parameters:
writer - writer to use for producing the document
uri - URI of the document
Throws:
RKCheckException - if an error occurs during write
java.io.IOException - if there is low level read error

getElement

protected org.w3c.dom.Element getElement(org.w3c.dom.Node parent,
                                         java.lang.String name,
                                         boolean missingOK)
                                  throws RKCheckException
Get a specific child element node.

Parameters:
parent - parent node
name - name of the element
missingOK - if true no exception is generated if the element is not found
Returns:
element node with the given name (null if not found and missingOK is true)
Throws:
RKCheckException - if the element cannot be found and missingOK is false

getAttribute

protected java.lang.String getAttribute(org.w3c.dom.Node element,
                                        java.lang.String name,
                                        boolean missingOK)
                                 throws RKCheckException
Get an attribute value.

Parameters:
element - element containing the attribute
name - attribute name
missingOK - if true no exception is generated if the attribute is not found
Returns:
attribute value (null if not found and missingOK is true)
Throws:
RKCheckException - if the attribute cannot be found and missingOK is false

getContent

protected java.lang.String getContent(org.w3c.dom.Node node)
                               throws RKCheckException
Get the content of a node.

Parameters:
node - node to analyze
Returns:
node content
Throws:
RKCheckException - if the node contains unexpected elements

error

public void error(org.xml.sax.SAXParseException exception)
           throws org.xml.sax.SAXParseException
Receive notification of a recoverable error.

Specified by:
error in interface org.xml.sax.ErrorHandler
Parameters:
exception - the recoverable error
Throws:
org.xml.sax.SAXException - the error is directly thrown as an exception
org.xml.sax.SAXParseException

fatalError

public void fatalError(org.xml.sax.SAXParseException exception)
                throws org.xml.sax.SAXParseException
Receive notification of a non-recoverable error.

Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Parameters:
exception - the non-recoverable error
Throws:
org.xml.sax.SAXException - the error is directly thrown as an exception
org.xml.sax.SAXParseException

warning

public void warning(org.xml.sax.SAXParseException exception)
             throws org.xml.sax.SAXParseException
Receive notification of a warning.

Specified by:
warning in interface org.xml.sax.ErrorHandler
Parameters:
exception - the warning
Throws:
org.xml.sax.SAXException - the error is directly thrown as an exception
org.xml.sax.SAXParseException

analyze

public abstract void analyze(org.w3c.dom.Document document,
                             java.lang.String uri)
                      throws RKCheckException,
                             java.lang.NumberFormatException
Analyze the DOM tree.

This method is called by the read method after having build the DOM tree. Its purpose is to analyze the tree and store the contained information in application-specific ways.

Parameters:
document - DOM tree to analyze
uri - URI from which the project document was read (useful mainly for error messages)
Throws:
RKCheckException - if some data cannot be found in the tree
java.lang.NumberFormatException - if some number cannot be parsed

build

public abstract void build(org.w3c.dom.Document document,
                           java.lang.String uri)
                    throws RKCheckException
Build the DOM tree.

This method is called by the write method before writing the DOM tree. Its purpose is to build the DOM tree in application-specific ways.

Parameters:
document - empty DOM tree to build
uri - URI where the project document will be written (useful mainly for error messages)
Throws:
RKCheckException - if some problem occurs while building the tree

getPublicId

protected abstract java.lang.String getPublicId()
Get the public ID of the DTD.

Returns:
public ID of the DTD

getSystemId

protected abstract java.lang.String getSystemId()
Get the system ID of the DTD.

Returns:
system ID of the DTD


Copyright © 2002-2004 Luc Maisonobe. All Rights Reserved.