org.geotools.referencing.wkt
Class AbstractParser

java.lang.Object
  extended by java.text.Format
      extended by org.geotools.referencing.wkt.AbstractParser
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
MathTransformParser

public abstract class AbstractParser
extends java.text.Format

Base class for Well Know Text (WKT) parser.

Since:
2.0
Version:
$Id: AbstractParser.java 30641 2008-06-12 17:42:27Z acuster $
Author:
Remi Eve, Martin Desruisseaux (IRD)
See Also:
Well Know Text specification, OGC WKT Coordinate System Issues, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
java.text.Format.Field
 
Constructor Summary
AbstractParser(Symbols symbols)
          Constructs a parser using the specified set of symbols.
 
Method Summary
 java.lang.StringBuffer format(java.lang.Object object, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          Format the specified object as a Well Know Text.
 org.opengis.metadata.citation.Citation getAuthority()
          Returns the preferred authority for formatting WKT entities.
protected  Element getTree(java.lang.String text, java.text.ParsePosition position)
          Returns a tree of Element for the specified text.
 java.lang.String getWarning()
          If a warning occured during the last WKT formatting, returns the warning.
 boolean isColorEnabled()
          Returns true if syntax coloring is enabled.
protected abstract  java.lang.Object parse(Element element)
          Parses the next element in the specified Well Know Text (WKT) tree.
 java.lang.Object parseObject(java.lang.String text)
          Parses a Well Know Text (WKT).
 java.lang.Object parseObject(java.lang.String text, java.text.ParsePosition position)
          Parses a Well Know Text (WKT).
 void reformat(java.io.BufferedReader in, java.io.Writer out, java.io.PrintWriter err)
          Read WKT strings from an input stream and reformat them to the specified output stream.
 void setAuthority(org.opengis.metadata.citation.Citation authority)
          Set the preferred authority for formatting WKT entities.
 void setColorEnabled(boolean enabled)
          Enables or disables syntax coloring on ANSI X3.64 (aka ECMA-48 and ISO/IEC 6429) compatible terminal.
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractParser

public AbstractParser(Symbols symbols)
Constructs a parser using the specified set of symbols.

Parameters:
symbols - The set of symbols to use.
Method Detail

getAuthority

public org.opengis.metadata.citation.Citation getAuthority()
Returns the preferred authority for formatting WKT entities. The format methods will uses the name specified by this authority, if available.

Returns:
The expected authority.

setAuthority

public void setAuthority(org.opengis.metadata.citation.Citation authority)
Set the preferred authority for formatting WKT entities. The format methods will uses the name specified by this authority, if available.

Parameters:
authority - The new authority.

isColorEnabled

public boolean isColorEnabled()
Returns true if syntax coloring is enabled. By default, syntax coloring is disabled.

Returns:
true if syntax coloring are enabled.
Since:
2.4

setColorEnabled

public void setColorEnabled(boolean enabled)
Enables or disables syntax coloring on ANSI X3.64 (aka ECMA-48 and ISO/IEC 6429) compatible terminal. This apply only when formatting text. By default, syntax coloring is disabled. When enabled, Format.format(Object) tries to highlight most of the elements compared by CRS.equalsIgnoreMetadata(java.lang.Object, java.lang.Object).

Parameters:
enabled - true for enabling syntax coloring.
Since:
2.4

parseObject

public final java.lang.Object parseObject(java.lang.String text)
                                   throws java.text.ParseException
Parses a Well Know Text (WKT).

Overrides:
parseObject in class java.text.Format
Parameters:
text - The text to be parsed.
Returns:
The object.
Throws:
java.text.ParseException - if the string can't be parsed.

parseObject

public final java.lang.Object parseObject(java.lang.String text,
                                          java.text.ParsePosition position)
Parses a Well Know Text (WKT).

Specified by:
parseObject in class java.text.Format
Parameters:
text - The text to be parsed.
position - The position to start parsing from.
Returns:
The object.

parse

protected abstract java.lang.Object parse(Element element)
                                   throws java.text.ParseException
Parses the next element in the specified Well Know Text (WKT) tree.

Parameters:
element - The element to be parsed.
Returns:
The object.
Throws:
java.text.ParseException - if the element can't be parsed.

getTree

protected final Element getTree(java.lang.String text,
                                java.text.ParsePosition position)
                         throws java.text.ParseException
Returns a tree of Element for the specified text.

Parameters:
text - The text to parse.
position - In input, the position where to start parsing from. In output, the first character after the separator.
Returns:
The tree of elements to parse.
Throws:
java.text.ParseException - If an parsing error occured while creating the tree.

format

public java.lang.StringBuffer format(java.lang.Object object,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)
Format the specified object as a Well Know Text. Formatting will uses the same set of symbols than the one used for parsing.

Specified by:
format in class java.text.Format
Parameters:
object - The object to format.
toAppendTo - Where the text is to be appended.
pos - An identification of a field in the formatted text.
See Also:
getWarning()

reformat

public void reformat(java.io.BufferedReader in,
                     java.io.Writer out,
                     java.io.PrintWriter err)
              throws java.io.IOException
Read WKT strings from an input stream and reformat them to the specified output stream. WKT strings are read until the the end-of-stream, or until an unparsable WKT has been hit. In this later case, an error message is formatted to the specified error stream.

Parameters:
in - The input stream.
out - The output stream.
err - The error stream.
Throws:
java.io.IOException - if an error occured while reading from the input stream or writting to the output stream.

getWarning

public java.lang.String getWarning()
If a warning occured during the last WKT formatting, returns the warning. Otherwise returns null. The warning is cleared every time a new object is formatted.

Returns:
The last warning, or null if none.
Since:
2.4


Copyright © 1996-2010 Geotools. All Rights Reserved.