public abstract class AbstractParser extends Object implements Parser
Modifier and Type | Field and Description |
---|---|
static String |
BUNDLE_CLASSNAME
The default resource bundle base name.
|
protected int |
current
The current character.
|
protected ErrorHandler |
errorHandler
The error handler.
|
protected NormalizingReader |
reader
The normalizing reader.
|
Constructor and Description |
---|
AbstractParser() |
Modifier and Type | Method and Description |
---|---|
protected String |
createErrorMessage(String key,
Object[] args)
Returns a localized error message.
|
protected abstract void |
doParse()
Method responsible for actually parsing data after AbstractParser
has initialized itself.
|
protected String |
getBundleClassName()
Returns the resource bundle base name.
|
int |
getCurrent()
Returns the current character value.
|
void |
parse(String s)
Parses the given string.
|
protected void |
reportCharacterExpectedError(char expectedChar,
int currentChar)
simple api to call often reported error.
|
protected void |
reportError(String key,
Object[] args)
Signals an error to the error handler.
|
protected void |
reportUnexpectedCharacterError(int currentChar)
simple api to call often reported error.
|
void |
setErrorHandler(ErrorHandler handler)
Allow an application to register an error event handler.
|
protected void |
skipCommaSpaces()
Skips the whitespaces and an optional comma.
|
protected void |
skipSpaces()
Skips the whitespaces in the current reader.
|
public static final String BUNDLE_CLASSNAME
protected ErrorHandler errorHandler
protected NormalizingReader reader
protected int current
public int getCurrent()
public void setErrorHandler(ErrorHandler handler)
If the application does not register an error event handler, all error events reported by the parser will cause an exception to be thrown.
Applications may register a new or different handler in the middle of a parse, and the parser must begin using the new handler immediately.
setErrorHandler
in interface Parser
handler
- The error handler.public void parse(String s) throws ParseException
parse
in interface Parser
ParseException
protected abstract void doParse() throws ParseException, IOException
ParseException
IOException
protected void reportError(String key, Object[] args) throws ParseException
key
- The message key in the resource bundle.args
- The message arguments.ParseException
protected void reportCharacterExpectedError(char expectedChar, int currentChar)
expectedChar
- what caller expectedcurrentChar
- what caller foundprotected void reportUnexpectedCharacterError(int currentChar)
currentChar
- what the caller found and didnt expectprotected String createErrorMessage(String key, Object[] args)
key
- The message key in the resource bundle.args
- The message arguments.protected String getBundleClassName()
protected void skipSpaces() throws IOException
IOException
protected void skipCommaSpaces() throws IOException
IOException
Copyright (c) 2010 Gaudenz Alder, David Benson. All rights reserved.