Class ExampleManager

java.lang.Object
org.xml.sax.helpers.DefaultHandler
de.saar.chorus.domgraph.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
  • Constructor Details

    • ExampleManager

      public ExampleManager()
  • Method Details

    • 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