Package org.geotools.referencing.wkt
Class AbstractConsole
Object
AbstractConsole
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
Console
Base class for application performing operations on WKT objects from the command line. Instructions are usually read
from the standard input stream and results sent to the standard output
stream, but those streams can be redirected. The set of allowed instructions depends on the subclass used.
- Since:
- 2.1
- Author:
- Martin Desruisseaux (IRD)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final PrintWriter
The error stream, usually the standard one.protected final LineNumberReader
The input stream, usually the standard one.protected final String
The line separator, usually the system default.protected final Writer
The output stream, usually the standard one.protected final Format
The WKT parser, usually aPreprocessor
object. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractConsole
(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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDefinition
(String name, String value) Adds a predefined Well Know Text (WKT).protected abstract void
Execute the specified instruction.void
Executes all instructions (likerun()
), but stop at the first error.Returns the command-line prompt, ornull
if there is none.void
Load all definitions from the specified stream.parseObject
(String text, Class type) Parses the specified text.void
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
Set the command-line prompt, ornull
for none.void
stop()
Stops therun()
method.
-
Field Details
-
in
The input stream, usually the standard one. -
out
The output stream, usually the standard one. -
err
The error stream, usually the standard one. -
lineSeparator
The line separator, usually the system default. -
parser
The WKT parser, usually aPreprocessor
object.
-
-
Constructor Details
-
AbstractConsole
Creates a new console instance using standard input stream, standard output stream, error output stream and the system default line separator.- Parameters:
parser
- The WKT parser, usually aPreprocessor
object.
-
AbstractConsole
Creates a new console instance using the specified input stream.- Parameters:
parser
- The WKT parser, usually aPreprocessor
object.in
- The input stream.
-
AbstractConsole
public AbstractConsole(Format parser, LineNumberReader in, Writer out, PrintWriter err, String lineSeparator) Creates a new console instance using the specified streams and line separator.- Parameters:
parser
- The WKT parser, usually aPreprocessor
object.in
- The input stream.out
- The output stream.err
- The error stream.lineSeparator
- The line separator.
-
-
Method Details
-
parseObject
Parses the specified text. The default implementation delegates the work to the parser.- Parameters:
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 aCoordinateReferenceSystem.class
orMathTransform.class
).- Returns:
- The object.
- Throws:
ParseException
- if parsing the specified WKT failed.FactoryException
- if the object is not of the expected type.
-
addDefinition
Adds a predefined Well Know Text (WKT). Thevalue
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 ofPreprocessor
.- Parameters:
name
- The name for the definition to be added.value
- The Well Know Text (WKT) represented by the name.- Throws:
IllegalArgumentException
- if the name is invalid.ParseException
- if the WKT can't be parsed.
-
loadDefinitions
Load all definitions from the specified stream. Definitions are key-value pairs in the formname = wkt
(without theSET
keyword). The result is the same than invoking theSET
instruction for each line in the specified stream. This method is used for loading predefined objects like the database used byPropertyAuthorityFactory
.- Parameters:
in
- The input stream.- Throws:
IOException
- if an input operation failed.ParseException
- if a well know text (WKT) can't be parsed.
-
printDefinitions
Prints to the output stream a table of all definitions. The content of this table is inferred from the values given to theaddDefinition(java.lang.String, java.lang.String)
method. This method print nothing if the parser is not an instance ofPreprocessor
.- Throws:
IOException
- if an error occured while writting to the output stream.
-
getPrompt
Returns the command-line prompt, ornull
if there is none. -
setPrompt
Set the command-line prompt, ornull
for none. -
run
public void run()Process instructions from the input stream specified at construction time. All lines are read until the end of stream ([Ctrl-Z]
for input from the keyboard), or untilstop()
is invoked. Non-empty and non-comment lines are given to theexecute(java.lang.String)
method. Errors are catched and printed to the error stream. -
executeAll
Executes all instructions (likerun()
), but stop at the first error.- Throws:
Exception
- if an instruction failed.
-
execute
Execute the specified instruction.- Parameters:
instruction
- The instruction to execute.- Throws:
Exception
- if the instruction failed.
-
stop
public void stop() -
reportError
Print an exception message to the standard error stream. The error message includes the line number, and the column where the failure occured in the exception is an instance ofParseException
.- Parameters:
exception
- The exception to report.
-