nenok.parser
Class XmlParser

java.lang.Object
  extended by nenok.parser.XmlParser
All Implemented Interfaces:
JT_Parser, KB_Parser, Parser

public abstract class XmlParser
extends Object
implements KB_Parser, JT_Parser

This class parses XML input files. It processes their static skeleton and delegates the generic parts to the user's subclass implementation. This class uses the JDOM framework and demands the XML file to reference a XML schema instance.

Version:
1.1
Author:
Marc Pouly

Constructor Summary
XmlParser()
          Constructor:
 
Method Summary
 boolean accept(File file)
          Verifies that this file type can be used together with this parser instance.
 ResultSet parse(File file)
          Parses the content of the given file and builds a result set, i.e. a wrapper class that bundles valuations and queries (domains) converted from the file content.
 Node parse(File file, JoinTree.Construction data)
          Rebuilds a jointree which is serialized in the given file.
 Domain parseDomain(org.jdom.Element domain, Hashtable<String,Variable> variables)
          This method converts the informations representing a domain read from an XML file to a domain object.
abstract  Valuation parseValuation(List<org.jdom.Element> content, Hashtable<String,Variable> variables)
          This method converts the informations representing a valuation read from an XML file to a valuation object.
abstract  Variable parseVariable(String name, List<org.jdom.Element> content)
          This method converts the informations representing a variable read from an XML file to a variable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlParser

public XmlParser()
Constructor:

Method Detail

accept

public boolean accept(File file)
Description copied from interface: Parser
Verifies that this file type can be used together with this parser instance.

Specified by:
accept in interface Parser
Parameters:
file - The file to verify.
Returns:
true if the file extension satisfies the precondition of this parser.
See Also:
Parser.accept(java.io.File)

parse

public ResultSet parse(File file)
                throws ParserException
Description copied from interface: KB_Parser
Parses the content of the given file and builds a result set, i.e. a wrapper class that bundles valuations and queries (domains) converted from the file content.

Specified by:
parse in interface KB_Parser
Parameters:
file - The file whose content is parsed.
Returns:
A bundle that encapsulates all data constructed from the file's content.
Throws:
ParserException - Exceptions that are thrown during the parsing process.
See Also:
KB_Parser.parse(java.io.File)

parse

public Node parse(File file,
                  JoinTree.Construction data)
           throws ParserException
Description copied from interface: JT_Parser
Rebuilds a jointree which is serialized in the given file.

Specified by:
parse in interface JT_Parser
Parameters:
file - The file containing a serialized jointree.
data - Object that contains all necessary information to build join trees.
Returns:
The root node of the jointree reconstructed from the file content.
Throws:
ParserException - Exceptions that are thrown during the parsing process.
See Also:
JT_Parser.parse(java.io.File, nenok.lc.JoinTree.Construction)

parseDomain

public Domain parseDomain(org.jdom.Element domain,
                          Hashtable<String,Variable> variables)
                   throws ParserException
This method converts the informations representing a domain read from an XML file to a domain object. The "domain" tag's content is given as a org.jdom.Element object.

Parameters:
domain - The content of the "domain" tag read from the XML file.
variables - A hashtable that maps variable names on variable objects.
Returns:
A new domain instance created from the tag's content.
Throws:
ParserException - Exceptions caused by the parsing process.

parseVariable

public abstract Variable parseVariable(String name,
                                       List<org.jdom.Element> content)
                                throws ParserException
This method converts the informations representing a variable read from an XML file to a variable object. The "variable" tag's content is given as a list of org.jdom.Element objects.

Parameters:
name - The variable's name (this is part of the file's skeleton).
content - All sub-elements of the "variable" element read from the XML file.
Returns:
A new variable instance created from the content list.
Throws:
ParserException - Exceptions caused by the parsing process.

parseValuation

public abstract Valuation parseValuation(List<org.jdom.Element> content,
                                         Hashtable<String,Variable> variables)
                                  throws ParserException
This method converts the informations representing a valuation read from an XML file to a valuation object. The "valuation" tag's content is given as a list of org.jdom.Element objects.

Parameters:
content - All sub-elements of the "valuation" element read from the XML file.
variables - A hashtable that maps variable names on variable objects.
Returns:
A new valuation instance created from the content list.
Throws:
ParserException - Exceptions caused by the parsing process.