Search this API

y.io.gml
Class GMLTokenizer

java.lang.Object
  extended by y.io.gml.GMLTokenizer

public class GMLTokenizer
extends Object

This class is used to parse a valid stream from a reader, which contains well formed gml. A callback method must be registered with this class, whose methods will be invoked during the parsing of the stream.


Nested Class Summary
static interface GMLTokenizer.Callback
          The interface used for the callback during parsing.
static class GMLTokenizer.DebugCallback
          An implementation of the callback which can be used to debug the parser.
static class GMLTokenizer.EncoderCallback
          An implementation of the callback, which will call the appropriate methods on an encoder.
 
Field Summary
protected static int AMPERSAND
          The type constant for '&'
protected static int CLOSE
          The closing brace type constant ']'
protected static int COMMENT
          The type constant for a comment in a gml file
protected static int DIGIT
          The type constant for a digit in GML
protected static int EOF
          The type constant for the end of file token
protected static int LETTER
          The type constant for a letter in GML
protected static int NEWLINE
          The type constant for a newline in a gml file
protected static int OPEN
          The opening brace type constant '['
protected static int QUOTE
          The type constant for '"'
protected static int UNKNOWN
          The type constant for anything that cannot be categorized in GML
protected static int WHITESPACE
          The type constant for any type of whitespace in GML
 
Constructor Summary
GMLTokenizer()
          Creates a new instance of GMLTokenizer
GMLTokenizer(GMLTokenizer.Callback callback)
          Creates a new instance of GMLTokenizer and installs the given callback
 
Method Summary
protected  int classify(char c)
          classifies the given character
 GMLTokenizer.Callback getCallback()
          Getter for property callback.
protected  int lookAhead(PushbackReader reader)
          takes a look at the next character in the stream and classifies it using one of the constants.
protected  void parse(PushbackReader pbReader)
          this is the actual parsing method
 void parse(Reader reader)
          starts the parsing and will fire events to the registered callback
protected  void parseComment(PushbackReader reader)
          parses a comment whitespace
protected  char parseEntity(PushbackReader reader)
          parses an entity from a GML "instring"
protected  String parseInString(PushbackReader reader)
          parses the GML "instring"
protected  String parseKey(PushbackReader reader)
          parses a key
protected  List parseList(PushbackReader reader)
          parses a GML list
protected  Number parseNumber(PushbackReader reader)
          parses a Number (Double or Integer)
protected  String parseString(PushbackReader reader)
          parses a GML String, i.e. removes the quotes and replaces ISO 8859-1 entities with their corresponding characters.
protected  Object parseValue(PushbackReader reader)
          parses a value, which might be either a String, or a Number, i.e. either Integer or Double
protected  void parseWhiteSpace(PushbackReader reader)
          parses whitespace
 void setCallback(GMLTokenizer.Callback callback)
          Setter for property callback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN

protected static final int OPEN
The opening brace type constant '['

See Also:
Constant Field Values

CLOSE

protected static final int CLOSE
The closing brace type constant ']'

See Also:
Constant Field Values

AMPERSAND

protected static final int AMPERSAND
The type constant for '&'

See Also:
Constant Field Values

QUOTE

protected static final int QUOTE
The type constant for '"'

See Also:
Constant Field Values

WHITESPACE

protected static final int WHITESPACE
The type constant for any type of whitespace in GML

See Also:
Constant Field Values

LETTER

protected static final int LETTER
The type constant for a letter in GML

See Also:
Constant Field Values

DIGIT

protected static final int DIGIT
The type constant for a digit in GML

See Also:
Constant Field Values

EOF

protected static final int EOF
The type constant for the end of file token

See Also:
Constant Field Values

NEWLINE

protected static final int NEWLINE
The type constant for a newline in a gml file

See Also:
Constant Field Values

COMMENT

protected static final int COMMENT
The type constant for a comment in a gml file

See Also:
Constant Field Values

UNKNOWN

protected static final int UNKNOWN
The type constant for anything that cannot be categorized in GML

See Also:
Constant Field Values
Constructor Detail

GMLTokenizer

public GMLTokenizer()
Creates a new instance of GMLTokenizer


GMLTokenizer

public GMLTokenizer(GMLTokenizer.Callback callback)
Creates a new instance of GMLTokenizer and installs the given callback

Parameters:
callback - the callback to be used
Method Detail

parse

public void parse(Reader reader)
           throws IOException
starts the parsing and will fire events to the registered callback

Throws:
IOException - in the case of an I/O Exception
Parameters:
reader - the stream to be parsed

lookAhead

protected int lookAhead(PushbackReader reader)
                 throws IOException
takes a look at the next character in the stream and classifies it using one of the constants.

Throws:
IOException - in the case of an I/O Exception
Parameters:
reader - the reader from which to read
Returns:
one of the constants defined in this class

parse

protected void parse(PushbackReader pbReader)
              throws IOException
this is the actual parsing method

Throws:
IOException - in the case of an I/O Exception
Parameters:
pbReader - the reader which will be used to parse the stream

classify

protected int classify(char c)
classifies the given character

Parameters:
c - the character
Returns:
one of the constants defined in this class

parseWhiteSpace

protected void parseWhiteSpace(PushbackReader reader)
                        throws IOException
parses whitespace

Throws:
IOException - in the case of an I/O Exception
Parameters:
reader - the reader

parseComment

protected void parseComment(PushbackReader reader)
                     throws IOException
parses a comment whitespace

Throws:
IOException - in the case of an I/O Exception
Parameters:
reader - the reader

parseKey

protected String parseKey(PushbackReader reader)
                   throws IOException
parses a key

Throws:
IOException - in the case of an I/O Exception
Parameters:
reader - the reader
Returns:
the key

parseValue

protected Object parseValue(PushbackReader reader)
                     throws IOException
parses a value, which might be either a String, or a Number, i.e. either Integer or Double

Throws:
IOException - in the case of an I/O Exception
Parameters:
reader - the reader
Returns:
a String or a Number

parseNumber

protected Number parseNumber(PushbackReader reader)
                      throws IOException
parses a Number (Double or Integer)

Throws:
IOException - in the case of an I/O Exception
Parameters:
reader - the reader
Returns:
a Number (Double or Integer)

parseString

protected String parseString(PushbackReader reader)
                      throws IOException
parses a GML String, i.e. removes the quotes and replaces ISO 8859-1 entities with their corresponding characters.

Throws:
IOException - in the case of an I/O Exception
Parameters:
reader - the reader
Returns:
the translated GML "instring"

parseInString

protected String parseInString(PushbackReader reader)
                        throws IOException
parses the GML "instring"

Throws:
IOException

parseEntity

protected char parseEntity(PushbackReader reader)
                    throws IOException
parses an entity from a GML "instring"

Throws:
IOException

parseList

protected List parseList(PushbackReader reader)
                  throws IOException
parses a GML list

Throws:
IOException

getCallback

public GMLTokenizer.Callback getCallback()
Getter for property callback.

Returns:
Value of property callback.

setCallback

public void setCallback(GMLTokenizer.Callback callback)
Setter for property callback.

Parameters:
callback - New value of property callback.

© Copyright 2000-2013,
yWorks GmbH.
All rights reserved.