|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object condor.classad.ClassAdParser
A factory for creating classad expressions (instances of Expr
), by parsing a textual or XML representation.
Input can come from a String, a Reader, or an InputStream.
ClassAd
,
Expr
Field Summary | |
int |
format
Input format. |
static int |
TEXT
Flag indicating that input format is "text". |
static int |
XML
Flag indicating that input format is xml. |
Constructor Summary | |
ClassAdParser()
Create a parser to parse text input. |
|
ClassAdParser(InputStream str)
Create a parser to parse an InputStream in default (text) format. |
|
ClassAdParser(InputStream str,
int format)
Create a parser to parse an InputStream. |
|
ClassAdParser(int format)
Create a parser to parse input. |
|
ClassAdParser(Reader rdr)
Create a parser to parse characters in default (text) format. |
|
ClassAdParser(Reader rdr,
int format)
Create a parser to parse characters. |
|
ClassAdParser(String s)
Create a parser to parse a string in default (text) format. |
|
ClassAdParser(String s,
int format)
Create a parser to parse a string. |
Method Summary | |
boolean |
enableTracing(boolean on)
Control whether the actions of the parser are traced. |
int |
getNextToken()
Get and remove the "lookahead" token: the first token not yet consumed by the parser. |
int |
nextToken()
Get the "lookahead" token: the first token not yet consumed by the parser. |
Object |
nextValue()
The the "value" of the lookahead token. |
Expr |
parse()
Parse a classsad Expr from the current input stream. |
Expr |
parse(boolean acceptPrefix)
Parse a classsad Expr from the current input stream. |
void |
printMessage(String msg)
Print a message, decorated with the current line and column number. |
void |
reset(InputStream str)
Reset this parser to parse input from an InputStream. |
void |
reset(Reader rdr)
Reset this parser to parse input from a Reader. |
void |
reset(String s)
Reset this parser to parse input from a String. |
PrintStream |
setErrorStream(PrintStream dest)
Set the destination for error messages. |
int |
setVerbosity(int level)
Set verbosity of error messages. |
Methods inherited from class Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int TEXT
XML
,
Constant Field Valuespublic static final int XML
TEXT
,
Constant Field Valuespublic final int format
TEXT
or XML
.
Constructor Detail |
public ClassAdParser()
public ClassAdParser(int format)
format
- either TEXT
or XML
.public ClassAdParser(String s)
s
- the string to be parsed.public ClassAdParser(String s, int format)
s
- the string to be parsed.format
- either TEXT
or XML
.public ClassAdParser(InputStream str)
str
- the string to be parsed.public ClassAdParser(InputStream str, int format)
str
- the string to be parsed.format
- either TEXT
or XML
.public ClassAdParser(Reader rdr)
rdr
- the string to be parsed.public ClassAdParser(Reader rdr, int format)
rdr
- the string to be parsed.format
- either TEXT
or XML
.Method Detail |
public void reset(String s)
s
- the string to parse.public void reset(InputStream str)
str
- the stream that supplies the input.public void reset(Reader rdr)
rdr
- the reader that supplies the input.public Expr parse(boolean acceptPrefix)
a + b cThe first call to parse() will return "a+b" and a subsequent call will return "c". Note that this "greedy" algorithm may fail to break the input into a sequence of valid expressions if it is possible. For example, the input
a - - bcan be parsed as the two expressions
a
and
--b
, but the first call will stop at the second minus sign
and fail, because a -
is not a valid expression.
If "acceptPrefix" is false, the parse will fail unless all the remaining input, up to end-of-stream, forms a valid expression.
If an error is detected, the return value is null and one or more error
messages will be printed to the current error stream, provided the
verbosity level is non-zero. See setVerbosity(int)
and
setErrorStream(PrintStream)
.
If format is XML, the entire stream will be parsed as a single Expr as if "acceptPrefix" were false. In this case, subsequent calls will always return null.
acceptPrefix
- if true, parse a maximal valid prefix of the input.
IllegalStateException
- if no input source has been specified by
a constructor or a call to a reset method.nextToken()
public Expr parse()
IllegalStateException
- if no input source has been specified by
a constructor or a call to a reset method.parse(boolean)
public int nextToken()
XML
parsers, always returns 0;
getNextToken()
public Object nextValue()
XML
parsers, always returns null;
nextToken()
public int getNextToken()
XML
parsers, always returns 0;
getNextToken()
public boolean enableTracing(boolean on)
XML
parsers, has no effect.
on
- if true, turn on tracing; if false, turn it off.
public int setVerbosity(int level)
TEXT
) or document info
(XML
)
TEXT
only)
level
- desired level.
IllegalArgumentException
- if level < 0 or level > 0 and
setErrorStream(PrintStream)
has been called with a null
argument.setErrorStream(PrintStream)
public PrintStream setErrorStream(PrintStream dest)
dest
- destination of error messages. A null value is equivalent
to setVerbosity(0).
setVerbosity(int)
public void printMessage(String msg)
msg
- the message to print.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |