public abstract class AbstractConsole extends Object implements Runnable
Modifier and Type | Field and Description |
---|---|
protected PrintWriter |
err
The error stream, usually the standard one.
|
protected LineNumberReader |
in
The input stream, usually the standard one.
|
protected String |
lineSeparator
The line separator, usually the system default.
|
protected Writer |
out
The output stream, usually the standard one.
|
protected Format |
parser
The WKT parser, usually a
Preprocessor object. |
Constructor and Description |
---|
AbstractConsole(Format parser)
Creates a new console instance using standard input stream,
standard output stream, error output stream
and the system default line separator.
|
AbstractConsole(Format parser,
LineNumberReader in)
Creates a new console instance using the specified input stream.
|
AbstractConsole(Format parser,
LineNumberReader in,
Writer out,
PrintWriter err,
String lineSeparator)
Creates a new console instance using the specified streams and line separator.
|
Modifier and Type | Method and Description |
---|---|
void |
addDefinition(String name,
String value)
Adds a predefined Well Know Text (WKT).
|
protected abstract void |
execute(String instruction)
Execute the specified instruction.
|
void |
executeAll()
Executes all instructions (like
run() ), but stop at the first error. |
String |
getPrompt()
Returns the command-line prompt, or
null if there is none. |
void |
loadDefinitions(LineNumberReader in)
Load all definitions from the specified stream.
|
Object |
parseObject(String text,
Class type)
Parses the specified text.
|
void |
printDefinitions()
Prints to the output stream a table of all definitions.
|
protected void |
reportError(Exception exception)
Print an exception message to the standard error stream.
|
void |
run()
Process instructions from the input stream specified at construction time.
|
void |
setPrompt(String prompt)
Set the command-line prompt, or
null for none. |
void |
stop()
Stops the
run() method. |
protected final LineNumberReader in
protected final Writer out
protected final PrintWriter err
protected final String lineSeparator
protected final Format parser
Preprocessor
object.public AbstractConsole(Format parser)
parser
- The WKT parser, usually a Preprocessor
object.public AbstractConsole(Format parser, LineNumberReader in)
parser
- The WKT parser, usually a Preprocessor
object.in
- The input stream.public AbstractConsole(Format parser, LineNumberReader in, Writer out, PrintWriter err, String lineSeparator)
parser
- The WKT parser, usually a Preprocessor
object.in
- The input stream.out
- The output stream.err
- The error stream.lineSeparator
- The line separator.public Object parseObject(String text, Class type) throws ParseException, FactoryException
text
- The text, as a name, a WKT to parse, or an authority code.type
- The expected type for the object to be parsed (usually a
CoordinateReferenceSystem.class
or
MathTransform.class
).ParseException
- if parsing the specified WKT failed.FactoryException
- if the object is not of the expected type.public void addDefinition(String name, String value) throws ParseException
value
argument given to this method can
contains itself other definitions specified in some previous calls to this method. This
method do nothing if the parser is not an instance of Preprocessor
.name
- The name for the definition to be added.value
- The Well Know Text (WKT) represented by the name.IllegalArgumentException
- if the name is invalid.ParseException
- if the WKT can't be parsed.public void loadDefinitions(LineNumberReader in) throws IOException, ParseException
name = wkt
(without the SET
keyword). The result is the same than invoking
the SET
instruction for each line in the specified stream. This method is used for
loading predefined objects like the database used by PropertyAuthorityFactory
.in
- The input stream.IOException
- if an input operation failed.ParseException
- if a well know text (WKT) can't be parsed.public void printDefinitions() throws IOException
addDefinition(java.lang.String, java.lang.String)
method. This method
print nothing if the parser is not an instance of Preprocessor
.IOException
- if an error occured while writting to the output stream.public String getPrompt()
null
if there is none.public void setPrompt(String prompt)
null
for none.public void run()
[Ctrl-Z]
for input from the keyboard), or
until stop()
is invoked. Non-empty and non-comment lines are given to the execute(java.lang.String)
method. Errors are catched and printed to the error stream.public void executeAll() throws Exception
run()
), but stop at the first error.Exception
- if an instruction failed.protected abstract void execute(String instruction) throws Exception
instruction
- The instruction to execute.Exception
- if the instruction failed.public void stop()
protected void reportError(Exception exception)
ParseException
.exception
- The exception to report.Copyright © 1996–2019 Geotools. All rights reserved.