org.directwebremoting.json.parse.impl
Class StatefulJsonDecoder

java.lang.Object
  extended by org.directwebremoting.json.parse.impl.StatefulJsonDecoder
All Implemented Interfaces:
JsonDecoder
Direct Known Subclasses:
JsonRpcCallsJsonDecoder, ReflectionJsonDecoder, SimpleJsonDecoder

public abstract class StatefulJsonDecoder
extends java.lang.Object
implements JsonDecoder

A stateful implementation of JsonDecoder where we track the stack of objects and allow a subclass to have a simpler set of things to do

Author:
Joe Walker [joe at getahead dot ltd dot uk]

Constructor Summary
StatefulJsonDecoder()
           
 
Method Summary
 void add(java.lang.String propertyName, java.lang.Object value)
          Add the add methods do basically the same thing - add themselves to the current object or array.
 void addBoolean(java.lang.String propertyName, boolean value)
          Add a boolean member.
 void addNull(java.lang.String propertyName)
          Add a null member.
 void addNumber(java.lang.String propertyName, java.lang.String intPart, java.lang.String floatPart, java.lang.String expPart)
          Add a numeric member.
 void addString(java.lang.String propertyName, java.lang.String value)
          Add a string member.
 void beginArray(java.lang.String propertyName)
          We have encountered a [.
 void beginObject(java.lang.String propertyName)
          We have encountered a {.
 void endArray(java.lang.String propertyName)
          We have encountered a ].
 void endObject(java.lang.String propertyName)
          We have encountered a }.
 java.lang.Object getRoot()
          When the parse is finished, this gives access to the result
static java.lang.Object realizeNumber(java.lang.String intPart, java.lang.String floatPart, java.lang.String expPart)
          Create a BigDecimal, double, int, or long depending on the input strings.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatefulJsonDecoder

public StatefulJsonDecoder()
Method Detail

getRoot

public java.lang.Object getRoot()
                         throws JsonParseException
Description copied from interface: JsonDecoder
When the parse is finished, this gives access to the result

Specified by:
getRoot in interface JsonDecoder
Throws:
JsonParseException

beginObject

public void beginObject(java.lang.String propertyName)
                 throws JsonParseException
Description copied from interface: JsonDecoder
We have encountered a {. If this object is a top level object, or the object is being added to an array, then the propertyName argument will be null, otherwise it will contain the name that this object will be assigned to in the parent object. What follows is a series of addXxxx() calls, possibly nested arrays and objects, followed by a call to JsonDecoder.endObject(String)

Specified by:
beginObject in interface JsonDecoder
Throws:
JsonParseException

endObject

public void endObject(java.lang.String propertyName)
               throws JsonParseException
Description copied from interface: JsonDecoder
We have encountered a }. This is called in a matching pair to JsonDecoder.beginObject(String) The propertyName argument will match the value given in the corresponding JsonDecoder.beginObject(String) call.

Specified by:
endObject in interface JsonDecoder
Throws:
JsonParseException

beginArray

public void beginArray(java.lang.String propertyName)
                throws JsonParseException
Description copied from interface: JsonDecoder
We have encountered a [. If this object is a top level object, or the object is being added to an array, then the propertyName argument will be null, otherwise it will contain the name that this object will be assigned to in the parent object. What follows is a series of addXxxxx() calls, possibly including nested arrays and objects, followed by a call to JsonDecoder.endArray(String).

Specified by:
beginArray in interface JsonDecoder
Throws:
JsonParseException

endArray

public void endArray(java.lang.String propertyName)
              throws JsonParseException
Description copied from interface: JsonDecoder
We have encountered a ]. This is called in a matching pair to JsonDecoder.beginArray(String) The propertyName argument will match the value given in the corresponding JsonDecoder.beginArray(String) call.

Specified by:
endArray in interface JsonDecoder
Throws:
JsonParseException
See Also:
JsonDecoder.beginArray(String)

add

public void add(java.lang.String propertyName,
                java.lang.Object value)
         throws JsonParseException
Add the add methods do basically the same thing - add themselves to the current object or array.

Throws:
JsonParseException

addString

public void addString(java.lang.String propertyName,
                      java.lang.String value)
               throws JsonParseException
Description copied from interface: JsonDecoder
Add a string member. If the member is added to an object then the propertyName argument will be the part of the JSON string before the ':'. If the member is added to an array, then propertyName will be null. See the note on JsonDecoder.beginObject(String)

Specified by:
addString in interface JsonDecoder
Throws:
JsonParseException

addNumber

public void addNumber(java.lang.String propertyName,
                      java.lang.String intPart,
                      java.lang.String floatPart,
                      java.lang.String expPart)
               throws JsonParseException
Description copied from interface: JsonDecoder
Add a numeric member. See the note on JsonDecoder.addString(String, String) for the meaning of the propertyName argument. The 3 parts are put together like this: {intPart}[.{floatPart}][E{expPart}]. For example:

Specified by:
addNumber in interface JsonDecoder
Throws:
JsonParseException

addBoolean

public void addBoolean(java.lang.String propertyName,
                       boolean value)
                throws JsonParseException
Description copied from interface: JsonDecoder
Add a boolean member. See the note on JsonDecoder.addString(String, String) for the meaning of the propertyName argument.

Specified by:
addBoolean in interface JsonDecoder
Throws:
JsonParseException

addNull

public void addNull(java.lang.String propertyName)
             throws JsonParseException
Description copied from interface: JsonDecoder
Add a null member. See the note on JsonDecoder.addString(String, String) for the meaning of the propertyName argument.

Specified by:
addNull in interface JsonDecoder
Throws:
JsonParseException

realizeNumber

public static java.lang.Object realizeNumber(java.lang.String intPart,
                                             java.lang.String floatPart,
                                             java.lang.String expPart)
Create a BigDecimal, double, int, or long depending on the input strings.

Parameters:
intPart - A string of [0-9]* representing the integer part of the number.
floatPart - A string of \.[0-9]* representing the floating point part of the number. This INCLUDES the period
expPart - A string of [eE][+-]?[0-9]* representing the integer part of the number. This includes the 'e' or 'E'.

Copyright 2008