org.elkoserver.json
Class JSONLiteralArray

java.lang.Object
  extended by org.elkoserver.json.JSONLiteralArray

public class JSONLiteralArray
extends Object

A literal JSON string, representing an array, undergoing incremental construction. Users of this class should call the constructor to begin creation of the literal, incrementally add to it using the various addElement() methods, then finally complete it by calling the finish() method. After the literal is completed, it may be used as another literal's parameter value.


Constructor Summary
JSONLiteralArray()
          Begin a new array literal that will be filled in incrementally.
JSONLiteralArray(EncodeControl control)
          Begin a new array literal that will be filled in incrementally.
 
Method Summary
 void addElement(boolean value)
          Add a boolean element to an incomplete array.
 void addElement(double value)
          Add a floating point element to an incomplete array.
 void addElement(Encodable value)
          Add an object element to an incomplete array.
 void addElement(int value)
          Add an integer element to an incomplete array.
 void addElement(JSONObject value)
          Add a JSON object element to an incomplete array.
 void addElement(long value)
          Add a long element to an incomplete array.
 void addElement(Object value)
          Add an element to the incomplete array literal.
 void addElement(Referenceable value)
          Add a reference element to an incomplete array.
 void addElement(String value)
          Add a string element to an incomplete array.
 void finish()
          Finish construction of the literal.
 String sendableString()
          Obtain a string representation of this literal suitable for output to a connection.
 int size()
          Obtain the array's element count.
 String toString()
          Obtain a printable String representation of this literal, in whatever its current state is.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JSONLiteralArray

public JSONLiteralArray(EncodeControl control)
Begin a new array literal that will be filled in incrementally.

Parameters:
control - Encode control determining what flavor of encoding is being done.

JSONLiteralArray

public JSONLiteralArray()
Begin a new array literal that will be filled in incrementally.

Method Detail

addElement

public void addElement(Object value)
Add an element to the incomplete array literal. Note that any element value that encodes to the Java value null will be ignored (i.e., not added to the literal).

Parameters:
value - The element value.
Throws:
Error - if you try to add an element to literal that is already complete.

addElement

public void addElement(Encodable value)
Add an object element to an incomplete array.

Parameters:
value - The (Encodable) element value.

addElement

public void addElement(double value)
Add a floating point element to an incomplete array.

Parameters:
value - The (double) element value.

addElement

public void addElement(boolean value)
Add a boolean element to an incomplete array.

Parameters:
value - The (boolean) element value.

addElement

public void addElement(int value)
Add an integer element to an incomplete array.

Parameters:
value - The (int) element value.

addElement

public void addElement(long value)
Add a long element to an incomplete array.

Parameters:
value - The (long) element value.

addElement

public void addElement(JSONObject value)
Add a JSON object element to an incomplete array.

Parameters:
value - The (JSONObject) element value.

addElement

public void addElement(Referenceable value)
Add a reference element to an incomplete array.

Parameters:
value - The (Referenceable) element value.

addElement

public void addElement(String value)
Add a string element to an incomplete array.

Parameters:
value - The (String) element value.

finish

public void finish()
Finish construction of the literal.

Throws:
Error - if you try to finish a literal that is already complete.

sendableString

public String sendableString()
Obtain a string representation of this literal suitable for output to a connection.

Returns:
a sendable string representation of this literal.
Throws:
Error - if the literal is not finished.

size

public int size()
Obtain the array's element count.

Returns:
the number of elements in this array (so far).

toString

public String toString()
Obtain a printable String representation of this literal, in whatever its current state is.

Overrides:
toString in class Object
Returns:
a printable representation of this literal.