|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.japaki.self.ParserBench
public class ParserBench
This is the standard entry point to the japaki library. The typical usage is as follows:
Create
a new parser bench.parser store
, if necessary.
parsing
or formatting
.Handle
exceptions.
Constructor Summary | |
---|---|
ParserBench()
|
Method Summary | ||
---|---|---|
|
add(String name,
Class<T> type,
String pattern)
Adds a new parser to the underlying parser store. |
|
|
addEnum(Class<T> type)
Creates a mold from an enum type: Looks for a property file in the class path at the same place as the class file of the given type. |
|
ParserStore |
getParserStore()
Returns the underlying parser store. |
|
static void |
handleException(Exception e)
Performs the default way to handle exceptions that occur during parsing or formatting. |
|
void |
loadSyntax(String fileName)
Loads parsers definitions from a file and stores them in the underlying parser store. |
|
|
loadSyntaxFromResource(String fileName)
Loads parsers definitions from a file in the classpath and stores them in the underlying parser store. |
|
|
parse(String parserName,
Reader reader,
T target)
Performs the following steps: The parser is looked up in the parser store. |
|
|
parse(String parserName,
String fileName,
T target)
Performs the following steps: The parser is looked up in the parser store. |
|
void |
setInspectorMill(InspectorMill inspectorMill)
Specifies the inspector mill to be used. |
|
static void |
useLoggingDefaults()
Initializes the logging mechanism. |
|
|
write(String parserName,
String fileName,
T source)
Performs the following steps: The parser is looked up in the parser store. |
|
|
write(String parserName,
Writer writer,
T source)
Performs the following steps: The parser is looked up in the parser store. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ParserBench()
Method Detail |
---|
public void setInspectorMill(InspectorMill inspectorMill)
inspectorMill
- new inspector millpublic ParserStore getParserStore()
public <T extends Enum<T>> void addEnum(Class<T> type)
simple name
of the type.
type
- an enum type
NullPointerException
- if type
is null
DuplicateKeyException
- if there is already an entry for the name
MissingResourceException
- if no resource bundle for the
specified base name can be foundResourceBundle
public <T> void add(String name, Class<T> type, String pattern) throws IOException, ParseException
name
- name of the new parsertype
- the class that the parse can handlepattern
- pattern representation of the new parser,
the syntax is described in SyntaxParser
.
NullPointerException
- if type is null
or
if a parameter in the pattern is missing
DuplicateKeyException
- if there is already an entry for the name
IllegalArgumentException
- if a parameter in the pattern
can not be used to create a parser
NoSuchPropertyException
- if the pattern contains an invalid
property name
ParseException
- when an exception occured while parsing the
pattern
IOException
- If an I/O error occurspublic void loadSyntax(String fileName) throws IOException, ParseException
name,class := pattern
whereSyntaxParser
.
fileName
- name of the syntax definition file
BeanStoreException
- if the parsed value could not be stored
IOException
- If an I/O error occurs
ParseException
- when an exception occured while parsing the
filepublic <T> void loadSyntaxFromResource(String fileName) throws IOException, ParseException
fileName
- name of the syntax definition file
BeanStoreException
- if the parsed value could not be stored
IOException
- If an I/O error occurs
ParseException
- when an exception occured while parsing the
fileloadSyntax(String)
public <T> void parse(String parserName, Reader reader, T target) throws IOException, ParseException
parserName
- name of the parser to be usedreader
- reader with the text to be parsedtarget
- object where the parsing result is stored
NullPointerException
- if reader
or target
or one of its (sub-) properties is null
and the parser cannot handle it
IllegalArgumentException
- if a parser of the given name is not
found in the store
BeanStoreException
- if the parsed value could not be stored
IOException
- If an I/O error occurs
ParseException
- if the reader content could not be parsedpublic <T> void parse(String parserName, String fileName, T target) throws IOException, ParseException
parserName
- name of the parser to be usedfileName
- name of the file with the text to be parsedtarget
- object where the parsing result is stored
NullPointerException
- if target
or one of its (sub-) properties is null
and the parser cannot handle it
IllegalArgumentException
- if a parser of the given name is not
found in the store
BeanStoreException
- if the parsed value could not be stored
IOException
- If an I/O error occurs
ParseException
- if the file content could not be parsedpublic <T> void write(String parserName, Writer writer, T source) throws IOException, FormatException
parserName
- name of the parser to be usedwriter
- writer where the formatted source object is written tosource
- object to be formatted
NullPointerException
- if writer
or source
or one of its (sub-) properties is null
and the parser cannot handle it
IllegalArgumentException
- if a parser of the given name is not
found in the store or if the parser cannot handle the source object
IOException
- If an I/O error occurs
FormatException
- if the source object can not be formatted with
this parser.public <T> void write(String parserName, String fileName, T source) throws IOException, FormatException
parserName
- name of the parser to be usedfileName
- name of the file where the formatted source object is
written tosource
- object to be formatted
NullPointerException
- if source
or one of its (sub-) properties is null
and the parser cannot handle it
IllegalArgumentException
- if a parser of the given name is not
found in the store or if the parser cannot handle the source object
IOException
- If an I/O error occurs
FormatException
- if the source object can not be formatted with
this parser.public static void handleException(Exception e) throws RuntimeException
e
- an exception that was thrown
RuntimeException
- RuntimeExceptions
are not handled
by this method, but passed on.public static void useLoggingDefaults()
ConsoleHandler
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |