de.saar.chorus.domgraph
Class ExampleManager

Object
  extended by DefaultHandler
      extended by ExampleManager
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class ExampleManager
extends DefaultHandler

An example manager for facilitating access to example input files. This class allows the user to register example files and get Reader objects for reading from them conveniently.

TODO: Right now, the example manager's behaviour is undefined when there is more than one example with the same filename.

Author:
Alexander Koller

Nested Class Summary
static class ExampleManager.ParserException
          A parser exception that occurred while reading an examples specification file.
 
Constructor Summary
ExampleManager()
           
 
Method Summary
 void addAllExamples(String directory)
          Adds all examples from a given example specification file.
 void addExample(String filename, String directory, String description)
          Adds an example to the registry.
 String getDescriptionForExample(String example)
          Returns the description for the example of the given name.
 List<String> getExampleNames()
          Returns the list of all registered example names.
 Reader getExampleReader(String name)
          Returns a Reader for the specified example file.
 void startElement(String uri, String localName, String qName, Attributes attributes)
           
 
Methods inherited from class DefaultHandler
characters, endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExampleManager

public ExampleManager()
Method Detail

getExampleNames

public List<String> getExampleNames()
Returns the list of all registered example names.

Returns:

getDescriptionForExample

public String getDescriptionForExample(String example)
Returns the description for the example of the given name.

Parameters:
example -
Returns:

getExampleReader

public Reader getExampleReader(String name)
Returns a Reader for the specified example file. This reader looks for the file at its original pathname relative to the classpath. It is robust towards packaging in a Jar or the use of alternative class loaders, and provides the preferred way of accessing an example file.

Parameters:
name -
Returns:

addAllExamples

public void addAllExamples(String directory)
                    throws ExampleManager.ParserException
Adds all examples from a given example specification file. An example specification file is an XML file with the name "examples.xml" in the given directory. It is assumed to have the following form:
<examples> <example filename="..." description="..." /> </examples>
Each example element specifies a filename and a description for one example file. The filename is interpreted relative to the directory which contains the "examples.xml" file.

Parameters:
directory - a directory containing a file with the name "examples.xml".
Throws:
ExampleManager.ParserException - if a parsing error occurred while reading the XML file.

addExample

public void addExample(String filename,
                       String directory,
                       String description)
Adds an example to the registry.

Parameters:
filename -
directory -
description -

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes attributes)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Throws:
SAXException