org.geotools.referencing.wkt
Class Preprocessor

Object
  extended by Format
      extended by Preprocessor
All Implemented Interfaces:
Serializable, Cloneable

public class Preprocessor
extends Format

A parser that performs string replacements before to delegate the work to an other parser. String replacements are specified through calls to the addDefinition method. In the example below, the WGS84 string in the parseObject call is expanded into the full GEOGCS["WGS84", ... string before to be parsed.

addDefinition("WGS84", "GEOGCS[\"WGS84\", DATUM[ ...etc... ]]
parseObject("PROJCS[\"Mercator_1SP\", WGS84, PROJECTION[
...etc... ]]")

Since:
2.1
Author:
Martin Desruisseaux (IRD)
See Also:
Serialized Form
Module:

Nested Class Summary
 
Nested classes/interfaces inherited from class Format
Format.Field
 
Field Summary
protected  Format parser
          The WKT parser, usually a Parser object.
 
Constructor Summary
Preprocessor(Format parser)
          Creates a new preprocessor that delegates the work to the specified parser.
 
Method Summary
 void addDefinition(String name, String value)
          Adds a predefined Well Know Text (WKT).
 StringBuffer format(Object object, StringBuffer toAppendTo, FieldPosition position)
          Formats the specified object.
 Set getDefinitionNames()
          Returns an unmodifiable set which contains all definition's names given to the addDefinition(name, ...)
 Object parseObject(String wkt)
          Parses the specified Well Know Text without restriction on the expected type.
 Object parseObject(String text, Class type)
          Parses the specified text and ensure that the resulting object is of the specified type.
 Object parseObject(String wkt, ParsePosition position)
          Parses the specified Well Know Text starting at the specified position.
 void printDefinitions(Writer out)
          Prints to the specified stream a table of all definitions.
 void removeDefinition(String name)
          Removes a definition set in some previous call to addDefinition(name, ...)
 
Methods inherited from class Format
clone, format, formatToCharacterIterator
 
Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parser

protected final Format parser
The WKT parser, usually a Parser object.

Constructor Detail

Preprocessor

public Preprocessor(Format parser)
Creates a new preprocessor that delegates the work to the specified parser.

Parameters:
parser - The WKT parser, usually a Parser object.
Method Detail

format

public StringBuffer format(Object object,
                           StringBuffer toAppendTo,
                           FieldPosition position)
Formats the specified object. This method delegates the work to the parser given at construction time.

Specified by:
format in class Format
Parameters:
object - The object to format.
toAppendTo - Where the text is to be appended.
position - Identification of a field in the formatted text.
Returns:
The string buffer passed in as toAppendTo, with formatted text appended

parseObject

public Object parseObject(String wkt,
                          ParsePosition position)
Parses the specified Well Know Text starting at the specified position. The default implementation delegates the work to parseObject(wkt.substring(position.getIndex())).

Specified by:
parseObject in class Format
Parameters:
wkt - The text to parse.
position - The index of the first character to parse.
Returns:
The parsed object, or null in case of failure.

parseObject

public Object parseObject(String wkt)
                   throws ParseException
Parses the specified Well Know Text without restriction on the expected type. The default implementation delegates the work to parseObject(wkt, Object.class).

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

parseObject

public Object parseObject(String text,
                          Class type)
                   throws ParseException,
                          FactoryException
Parses the specified text and ensure that the resulting object is of the specified type. The text can be any of the following:

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 a CoordinateReferenceSystem.class or MathTransform.class).
Returns:
The object.
Throws:
ParseException - if parsing the specified WKT failed.
FactoryException - if the object is not of the expected type.

addDefinition

public void addDefinition(String name,
                          String value)
                   throws ParseException
Adds a predefined Well Know Text (WKT). The value argument given to this method can contains itself other definitions specified in some previous calls to this method.

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.

removeDefinition

public void removeDefinition(String name)
Removes a definition set in some previous call to addDefinition(name, ...).

Parameters:
name - The name of the definition to remove.

getDefinitionNames

public Set getDefinitionNames()
Returns an unmodifiable set which contains all definition's names given to the addDefinition(name, ...) method. The elements in this set are sorted in alphabetical order.


printDefinitions

public void printDefinitions(Writer out)
                      throws IOException
Prints to the specified stream a table of all definitions. The content of this table is inferred from the values given to the addDefinition(java.lang.String, java.lang.String) method.

Parameters:
out - writer The output stream where to write the table.
Throws:
IOException - if an error occured while writting to the output stream.


Copyright © 1996-2009 Geotools. All Rights Reserved.