|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.bsd.x2svg.ParserLoader
public class ParserLoader
This singleton class is used to load the Parsers as plugins.
Parsers are expected to live in the package de.bsd.x2svg.parsers
and to implement the interface InputParser
.
load()
.
de.bsd.x2svg.parsers
Nested Class Summary | |
---|---|
private static class |
ParserLoader.ClassNameFileFilter
Filter that accepts files ending in .class |
Field Summary | |
---|---|
private static boolean |
debug
|
private java.util.Map<java.lang.String,java.lang.String> |
helpByMode
|
private boolean |
loaded
|
private java.util.Map<java.lang.String,java.lang.String> |
modeAndSuffix
|
private static java.lang.String |
NO_SPECIFIC_HELP_AVAILABLE
|
private static java.lang.String |
PACKAGE_STRING
|
private java.util.Map<java.lang.String,java.lang.Class<InputParser>> |
parserByMode
|
private java.util.Map<java.lang.String,java.lang.Class<InputParser>> |
parserBySuffix
|
private static ParserLoader |
theLoader
|
Constructor Summary | |
---|---|
private |
ParserLoader()
Private constructor as we are a singleton |
Method Summary | |
---|---|
private void |
addToParserList(java.lang.Class<InputParser> clazz)
Enter the passed class into the lists of parsers |
private void |
checkClassIsParser(java.lang.String classname)
Checks if the class passed in is a valid InputParser. |
java.lang.String |
getHelpForMode(java.lang.String mode)
Return the parser specific help for the passed mode. |
static ParserLoader |
getLoader()
Get the instance of ParserLoader |
InputParser |
getParserByMode(java.lang.String mode)
Return a parser for a given mode. |
InputParser |
getParserForFilename(java.lang.String filename)
Return a parser instance by selecting a matching suffix for the file name. |
java.lang.String |
listParsers()
List all parsers that we know about |
void |
load()
Load the parsers from the main jar and register them in our list. |
static void |
main(java.lang.String[] args)
For debugging the ParserLoader separately |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String PACKAGE_STRING
private static volatile ParserLoader theLoader
private java.util.Map<java.lang.String,java.lang.Class<InputParser>> parserByMode
private java.util.Map<java.lang.String,java.lang.Class<InputParser>> parserBySuffix
private java.util.Map<java.lang.String,java.lang.String> helpByMode
private java.util.Map<java.lang.String,java.lang.String> modeAndSuffix
private static boolean debug
private static final java.lang.String NO_SPECIFIC_HELP_AVAILABLE
private boolean loaded
Constructor Detail |
---|
private ParserLoader()
Method Detail |
---|
public static ParserLoader getLoader()
public InputParser getParserByMode(java.lang.String mode) throws NoParserException, java.lang.IllegalAccessException, java.lang.InstantiationException
mode
- a Mode that needs to be registered by the parser.
InputParser
if found
NoParserException
- if the passed mode is invalid or no parser was found
java.lang.IllegalAccessException
- If the parser class is not accessible
java.lang.InstantiationException
- If the parser class can not be instantiated
java.lang.IllegalStateException
- If load()
has not yet been calledpublic InputParser getParserForFilename(java.lang.String filename) throws NoParserException, java.lang.InstantiationException, java.lang.IllegalAccessException
filename
- Name of the file to determine the suffix
InputParser
NoParserException
- if the input is invalid or no parser was found for the passed filename.
java.lang.IllegalAccessException
- If the parser class is not accessible
java.lang.InstantiationException
- If the parser class can not be instantiated
java.lang.IllegalStateException
- If load()
has not yet been calledString.endsWith(String)
public void load()
InputParser
. After this, we pass the the
matching class to the addToParserList() method, which does the magic
for us.
private void checkClassIsParser(java.lang.String classname) throws java.lang.ClassNotFoundException
classname
- Name of a class in form of a path
java.lang.ClassNotFoundException
- If the passed class could not be found in the classpathprivate void addToParserList(java.lang.Class<InputParser> clazz)
clazz
- The main class of an InputParserpublic java.lang.String listParsers()
java.lang.IllegalStateException
- If load()
has not yet been calledpublic java.lang.String getHelpForMode(java.lang.String mode)
mode
- a valid mode or '*'
java.lang.IllegalStateException
- If load()
has not yet been calledpublic static void main(java.lang.String[] args)
args
- No command line options needed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |