Class 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... ]]")
    Martin Desruisseaux (IRD)
    See Also:
    Serialized Form
    • 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.
        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
        object - The object to format.
        toAppendTo - Where the text is to be appended.
        position - Identification of a field in the formatted text.
        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
        wkt - The text to parse.
        position - The index of the first character to parse.
        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).
        parseObject in class Format
        wkt - The text to parse.
        The parsed object.
        ParseException - if the text can't be parsed.
      • parseObject

        public Object parseObject​(String text,
                                  Class<?> type)
                           throws ParseException,
        Parses the specified text and ensure that the resulting object is of the specified type. The text can be any of the following:
        • A name declared in some previous call to addDefinition(name, ...).
        • A Well Know Text, which may contains itself shortcuts declared in previous call to addDefinition. This text is given to the underlying parser.
        • Any services provided by subclasses. For example a subclass way recognize some authority code like EPSG:6326.
        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).
        The object.
        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.
        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.
      • removeDefinition

        public void removeDefinition​(String name)
        Removes a definition set in some previous call to addDefinition(name, ...).
        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.
        out - writer The output stream where to write the table.
        IOException - if an error occured while writting to the output stream.