|
Copyright (C) 2003,2004 dr. Cristiano Sadun | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.sadun.text.ffp.BaseListener
A base implementation of FlatFileParser.Listener which
activates only when on a specific line format name (or a specific regular expression match)
is successfully parsed.
Multiple listeners can be registered at a FlatFileParser
each reacting to a specific line format name.
When #matched(String, String[]) is executed, the method compares the received format name
to the string or regular expression passed at construction and if they correspond, invokes
#onFormatName(String, String[]).
The net result is that the reaction code does not need to perform checks on the format name, since it's invoked only if a match is verified. For example,
FlatFileParser ffp = new FlatFileParser();
..set up two LineFormat objects, one named "header", the other "data"..
ffp.addListener(new BaseListener("header") {
protected void onFormatName(String formatName, String[] values) {
System.out.println("HEADER line");
}
});
ffp.addListener(new BaseListener("data") {
protected void onFormatName(String formatName, String[] values) {
System.out.println("DATA line");
}
});
| Constructor Summary | |
protected |
BaseListener(java.lang.String formatName)
Create a listener which matches exactly the given line format name. |
protected |
BaseListener(java.lang.String formatName,
boolean isRegExp)
Create a listener which matches the given line format name or the given regular expression. |
| Method Summary | |
void |
lineParsed(LineFormat format,
int logicalLineCount,
int physicalLineCount,
java.lang.String[] values)
This implementation checks wether the received format name matches the name or regular expression provided at construction, and invokes #onFormatName(String, String[])
if so. |
protected abstract void |
onFormatName(LineFormat format,
int logicalLineCount,
int physicalLineCount,
java.lang.String[] values)
Invoked when a line whose format name matches the name or regexp provided at construction is found. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
protected BaseListener(java.lang.String formatName)
formatName - the name of the desired LineFormat
protected BaseListener(java.lang.String formatName,
boolean isRegExp)
formatName - the format name or regular expressionisRegExp - true if the given formatName is to be treated as a regular expression| Method Detail |
public final void lineParsed(LineFormat format,
int logicalLineCount,
int physicalLineCount,
java.lang.String[] values)
throws AbortFFPException
#onFormatName(String, String[])
if so.
lineParsed in interface FlatFileParser.Listenerformat - the LineFormat object which has executed the parsingvalues - the values resulting from the parsing
AbortFFPException
protected abstract void onFormatName(LineFormat format,
int logicalLineCount,
int physicalLineCount,
java.lang.String[] values)
throws AbortFFPException
values - the parsed values
AbortFFPException
|
Copyright (C) 2003,2004 dr. Cristiano Sadun | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||