org.geotools.referencing.wkt
Class Preprocessor

java.lang.Object
  extended byjava.text.Format
      extended byorg.geotools.referencing.wkt.Preprocessor
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Preprocessor
extends java.text.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 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
Version:
$Id: Preprocessor.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
java.text.Format.Field
 
Field Summary
protected  java.text.Format parser
          The WKT parser, usually a Parser object.
 
Constructor Summary
Preprocessor(java.text.Format parser)
          Creates a new preprocessor that delegates the work to the specified parser.
 
Method Summary
 void addDefinition(java.lang.String name, java.lang.String value)
          Adds a predefined Well Know Text (WKT).
 java.lang.StringBuffer format(java.lang.Object object, java.lang.StringBuffer toAppendTo, java.text.FieldPosition position)
          Formats the specified object.
 java.util.Set getDefinitionNames()
          Returns an unmodifiable set which contains all definition's names given to the addDefinition(name, ...)
 java.lang.Object parseObject(java.lang.String wkt)
          Parses the specified Well Know Text without restriction on the expected type.
 java.lang.Object parseObject(java.lang.String text, java.lang.Class type)
          Parses the specified text and ensure that the resulting object is of the specified type.
 java.lang.Object parseObject(java.lang.String wkt, java.text.ParsePosition position)
          Parses the specified Well Know Text starting at the specified position.
 void printDefinitions(java.io.Writer out)
          Prints to the specified stream a table of all definitions.
 void removeDefinition(java.lang.String name)
          Removes a definition set in some previous call to addDefinition(name, ...)
 
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
 

Field Detail

parser

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

Constructor Detail

Preprocessor

public Preprocessor(java.text.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 java.lang.StringBuffer format(java.lang.Object object,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition position)
Formats the specified object. This method delegates the work to the parser given at construction time.

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 , with formatted text appended

parseObject

public java.lang.Object parseObject(java.lang.String wkt,
                                    java.text.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())).

Parameters:
wkt - The text to parse.
position - The index of the first character to parse.
Returns:
The parsed object, or in case of failure.

parseObject

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

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

parseObject

public java.lang.Object parseObject(java.lang.String text,
                                    java.lang.Class type)
                             throws java.text.ParseException,
                                    org.opengis.referencing.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:
java.text.ParseException - if parsing the specified WKT failed.
org.opengis.referencing.FactoryException - if the object is not of the expected type.

addDefinition

public void addDefinition(java.lang.String name,
                          java.lang.String value)
                   throws java.text.ParseException
Adds a predefined Well Know Text (WKT). The 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:
java.lang.IllegalArgumentException - if the name is invalid.
java.text.ParseException - if the WKT can't be parsed.

removeDefinition

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

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

getDefinitionNames

public java.util.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(java.io.Writer out)
                      throws java.io.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:
java.io.IOException - if an error occured while writting to the output stream.


Copyright © GeoTools. All Rights Reserved.