com.mcdermottroe.exemplar.input
Class InputUtils

java.lang.Object
  extended by com.mcdermottroe.exemplar.input.InputUtils

public final class InputUtils
extends Object

Input handling utilities.

Since:
0.1

Constructor Summary
private InputUtils()
          Private constructor to prevent instantiation of this class.
 
Method Summary
static SortedMap<String,String> availableInputLanguages()
          Find out the available input languages.
static XMLDocumentType parse(String inputFile, String inputType)
          Given an input file and the type of that file, create the XMLDocumentType for it.
private static Class<?> parserClass(String name)
          Locate the input parsing class for a given input module.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputUtils

private InputUtils()
Private constructor to prevent instantiation of this class.

Method Detail

parserClass

private static Class<?> parserClass(String name)
                             throws ClassNotFoundException
Locate the input parsing class for a given input module. The returned class implements the InputModule interface.

Parameters:
name - The name of the input module. The class returned will be $PACKAGE.input.$name.Parser.
Returns:
The Class that can be used to read in the XML vocabulary specification.
Throws:
ClassNotFoundException - When the class $PACKAGE.input.$name.Parser could not be found.

parse

public static XMLDocumentType parse(String inputFile,
                                    String inputType)
                             throws InputException,
                                    ParserException
Given an input file and the type of that file, create the XMLDocumentType for it. This method hides away the implementations of the input modules to allow a plug-in style way of accessing them. Students of design patterns will recognise this as something like the Abstract Factory pattern (with InputModule as the abstract interface. However, this goes one step further by invoking the InputModule.parse(String) method on the created class.

Parameters:
inputFile - The input file.
inputType - The type of file inputFile is.
Returns:
An XMLDocumentType describing the vocabulary of XML that was contained in inputFile.
Throws:
InputException - if the parsing method did not conform to the required interface or was otherwise inaccessible.
ParserException - if an error was thrown inside the parser.

availableInputLanguages

public static SortedMap<String,String> availableInputLanguages()
Find out the available input languages. This is done by querying the Packages.findSubPackages(java.lang.String) method to find all of the packages below Constants.Input.PACKAGE which are in the prescribed form.

Returns:
A SortedMap where the keys are tokens representing legal input languages and the values are descriptions of those languages.