com.electrotank.electroserver4.extensions.api.value
Class EsObject

java.lang.Object
  extended by com.electrotank.electroserver4.extensions.api.value.EsObject
All Implemented Interfaces:
EsObjectRO, Serializable, Iterable<EsObjectEntry>

public class EsObject
extends Object
implements EsObjectRO, Serializable

EsObject facilitates the exchange of data between all layers of a multiplayer application.

EsObject is an object that supports a large number of data types. It allows the server and client, or clients and other clients, to exchange simple or complex object structures that retain data types. In addition, EsObjects are used in many places when dealing with extensions and values for room variables, user variables, and user server variables.

One of the most attractive benefits of an EsObject is that it allows for data to be sent across languages cleanly and easily. A plugin written in ActionScript can create an EsObject and send it to a Java client and both sides will treat it consistently. There is no need to perform any messy conversions. For example: A Flash client can create an EsObject, populate it with strings, numbers and arrays of information, and then just send it to a server plugin. The plugin receives this EsObject and can access all of that information.

See Also:
ElectroServer 4 Manual, Understanding the EsObject, EsObjectEntry, EsObjectRO, Serialized Form

Field Summary
static EsObjectRO emptyObject
           
 
Constructor Summary
EsObject()
          Creates a new instance of EsObject
EsObject(Object... entries)
          Creates a new instance of EsObject and fills it with the entries in the Object.
 
Method Summary
 void addAll(EsObjectRO esObject)
          Adds the contents of the argument.
 void fromXML(Node variablesNode, XPath xpath)
           
 boolean getBoolean(String name)
          Gets the boolean value of the named entry.
 boolean getBoolean(String name, boolean defaultValue)
          Gets the boolean value of the named entry, or the default value if any exception occurs.
 boolean[] getBooleanArray(String name)
          Gets the boolean array value of the named entry.
 boolean[] getBooleanArray(String name, boolean[] defaultValue)
          Gets the boolean array value of the named entry, or the default value if any exception occurs.
 byte getByte(String name)
          Gets the byte value of the named entry.
 byte getByte(String name, byte defaultValue)
          Gets the byte value of the named entry, or the default value if any exception occurs.
 byte[] getByteArray(String name)
          Gets the byte array value of the named entry.
 byte[] getByteArray(String name, byte[] defaultValue)
          Gets the byte array value of the named entry, or the default value if any exception occurs.
 char getChar(String name)
          Gets the char value of the named entry.
 char getChar(String name, char defaultValue)
          Gets the char value of the named entry, or the default value if any exception occurs.
 char[] getCharArray(String name)
          Gets the char array value of the named entry.
 char[] getCharArray(String name, char[] defaultValue)
          Gets the char array value of the named entry, or the default value if any exception occurs.
 double getDouble(String name)
          Gets the double value of the named entry.
 double getDouble(String name, double defaultValue)
          Gets the double value of the named entry, or the default value if any exception occurs.
 double[] getDoubleArray(String name)
          Gets the double array value of the named entry.
 double[] getDoubleArray(String name, double[] defaultValue)
          Gets the double array value of the named entry, or the default value if any exception occurs.
 EsObject getEsObject(String name)
          Gets the EsObject value of the named entry.
 EsObject getEsObject(String name, EsObject defaultValue)
          Gets the EsObject value of the named entry, or the default value if any exception occurs.
 EsObject[] getEsObjectArray(String name)
          Gets the EsObject array value of the named entry.
 EsObject[] getEsObjectArray(String name, EsObject[] defaultValue)
          Gets the EsObject array value of the named entry, or the default value if any exception occurs.
 float getFloat(String name)
          Gets the float value of the named entry.
 float getFloat(String name, float defaultValue)
          Gets the float value of the named entry, or the default value if any exception occurs.
 float[] getFloatArray(String name)
          Gets the float array value of the named entry.
 float[] getFloatArray(String name, float[] defaultValue)
          Gets the float array value of the named entry, or the default value if any exception occurs.
 int getInteger(String name)
          Gets the integer value of the named entry.
 int getInteger(String name, int defaultValue)
          Gets the integer value of the named entry, or the default value if any exception occurs.
 int[] getIntegerArray(String name)
          Gets the int array value of the named entry.
 int[] getIntegerArray(String name, int[] defaultValue)
          Gets the int array value of the named entry, or the default value if any exception occurs.
 long getLong(String name)
          Gets the long value of the named entry.
 long getLong(String name, long defaultValue)
          Gets the long value of the named entry, or the default value if any exception occurs.
 long[] getLongArray(String name)
          Gets the long array value of the named entry.
 long[] getLongArray(String name, long[] defaultValue)
          Gets the long array value of the named entry, or the default value if any exception occurs.
 Number getNumber(String name)
          Gets the Number value of the named entry.
 Number getNumber(String name, Number defaultValue)
          Gets the Number value of the named entry, or the default value if any exception occurs.
 Number[] getNumberArray(String name)
          Gets the Number array value of the named entry.
 Number[] getNumberArray(String name, Number[] defaultValue)
          Gets the Number array value of the named entry, or the default value if any exception occurs.
 Object getRawVariable(String name)
          Gets the raw value of the named variable, as an Object.
 short getShort(String name)
          Gets the short value of the named entry.
 short getShort(String name, short defaultValue)
          Gets the short value of the named entry, or the default value if any exception occurs.
 short[] getShortArray(String name)
          Gets the short array value of the named entry.
 short[] getShortArray(String name, short[] defaultValue)
          Gets the short array value of the named entry, or the default value if any exception occurs.
 int getSize()
          Gets the number of values stored in the EsObject.
 String getString(String name)
          Gets the string value of the named entry.
 String getString(String name, String defaultValue)
          Gets the String value of the named entry, or the default value if any exception occurs.
 String[] getStringArray(String name)
          Gets the string array value of the named entry.
 String[] getStringArray(String name, String[] defaultValue)
          Gets the string array value of the named entry, or the default value if any exception occurs.
 Iterator<EsObjectEntry> iterator()
          Creates an iterator over all the entries in the EsObject.
 void removeAll()
          Removes all variables from the EsObject, leaving it empty.
 void removeVariable(String name)
          Removes the named variable from the EsObject.
 void setBoolean(String name, boolean value)
          Sets the named entry of the EsObject to the boolean value.
 void setBooleanArray(String name, boolean[] value)
          Sets the named entry of the EsObject to the boolean array value.
 void setByte(String name, byte value)
          Sets the named entry of the EsObject to the byte value.
 void setByteArray(String name, byte[] value)
          Sets the named entry of the EsObject to the byte array value.
 void setChar(String name, char value)
          Sets the named entry of the EsObject to the char value.
 void setCharArray(String name, char[] value)
          Sets the named entry of the EsObject to the char array value.
 void setDouble(String name, double value)
          Sets the named entry of the EsObject to the double value.
 void setDoubleArray(String name, double[] value)
          Sets the named entry of the EsObject to the double array value.
 void setEsObject(String name, EsObject value)
          Sets the named entry of the EsObject to the EsObject value.
 void setEsObjectArray(String name, EsObject[] value)
          Sets the named entry of the EsObject to the EsObject array value.
 void setFloat(String name, float value)
          Sets the named entry of the EsObject to the float value.
 void setFloatArray(String name, float[] value)
          Sets the named entry of the EsObject to the float array value.
 void setInteger(String name, int value)
          Sets the named entry of the EsObject to the integer value.
 void setIntegerArray(String name, int[] value)
          Sets the named entry of the EsObject to the int array value.
 void setLong(String name, long value)
          Sets the named entry of the EsObject to the long value.
 void setLongArray(String name, long[] value)
          Sets the named entry of the EsObject to the long array value.
 void setNumber(String name, double value)
          Sets the named entry of the EsObject to the double value, cast as a Number.
 void setNumber(String name, float value)
          Sets the named entry of the EsObject to the float value, cast as a Number.
 void setNumber(String name, int value)
          Sets the named entry of the EsObject to the int value, cast as a Number.
 void setNumber(String name, long value)
          Sets the named entry of the EsObject to the long value, cast as a Number.
 void setNumber(String name, Number value)
          Sets the named entry of the EsObject to the Number value.
 void setNumberArray(String name, Number[] value)
          Sets the named entry of the EsObject to the Number array value.
 void setShort(String name, short value)
          Sets the named entry of the EsObject to the short value.
 void setShortArray(String name, short[] value)
          Sets the named entry of the EsObject to the short array value.
 void setString(String name, String value)
          Sets the named entry of the EsObject to the string value.
 void setStringArray(String name, String[] value)
          Sets the named entry of the EsObject to the string array value.
 String toString()
           
 String toString(String tabs)
           
 String toXML()
           
 boolean variableExists(String name)
          Returns true if an entry exists with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

emptyObject

public static final EsObjectRO emptyObject
Constructor Detail

EsObject

public EsObject()
Creates a new instance of EsObject


EsObject

public EsObject(Object... entries)
Creates a new instance of EsObject and fills it with the entries in the Object. This is suitable for use with an ActionScript object.

Parameters:
entries - the names and values to add to the EsObject
Method Detail

iterator

public Iterator<EsObjectEntry> iterator()
Creates an iterator over all the entries in the EsObject.

Specified by:
iterator in interface Iterable<EsObjectEntry>
Returns:
iterator
See Also:
EsObjectEntry

addAll

public void addAll(EsObjectRO esObject)
Adds the contents of the argument. Useful for combining two EsObjects.

Parameters:
esObject - the read-only EsObject to be added.
See Also:
EsObjectRO

getSize

public int getSize()
Description copied from interface: EsObjectRO
Gets the number of values stored in the EsObject.

Specified by:
getSize in interface EsObjectRO
Returns:
size

setInteger

public void setInteger(String name,
                       int value)
Sets the named entry of the EsObject to the integer value.

Parameters:
name - name of the entry
value - integer value of the entry

setString

public void setString(String name,
                      String value)
Sets the named entry of the EsObject to the string value.

Parameters:
name - name of the entry
value - String value of the entry

setDouble

public void setDouble(String name,
                      double value)
Sets the named entry of the EsObject to the double value.

Parameters:
name - name of the entry
value - double value of the entry

setFloat

public void setFloat(String name,
                     float value)
Sets the named entry of the EsObject to the float value.

Parameters:
name - name of the entry
value - float value of the entry

setBoolean

public void setBoolean(String name,
                       boolean value)
Sets the named entry of the EsObject to the boolean value.

Parameters:
name - name of the entry
value - boolean value of the entry

setByte

public void setByte(String name,
                    byte value)
Sets the named entry of the EsObject to the byte value.

Parameters:
name - name of the entry
value - byte value of the entry

setChar

public void setChar(String name,
                    char value)
Sets the named entry of the EsObject to the char value.

Parameters:
name - name of the entry
value - char value of the entry

setLong

public void setLong(String name,
                    long value)
Sets the named entry of the EsObject to the long value.

Parameters:
name - name of the entry
value - long value of the entry

setShort

public void setShort(String name,
                     short value)
Sets the named entry of the EsObject to the short value.

Parameters:
name - name of the entry
value - short value of the entry

setEsObject

public void setEsObject(String name,
                        EsObject value)
Sets the named entry of the EsObject to the EsObject value. This allows for nesting of an EsObject inside another EsObject.

Parameters:
name - name of the entry
value - short value of the entry

setNumber

public void setNumber(String name,
                      Number value)
Sets the named entry of the EsObject to the Number value.

Parameters:
name - name of the entry
value - Number value of the entry

setNumber

public void setNumber(String name,
                      double value)
Sets the named entry of the EsObject to the double value, cast as a Number.

Parameters:
name - name of the entry
value - double value of the entry

setNumber

public void setNumber(String name,
                      float value)
Sets the named entry of the EsObject to the float value, cast as a Number.

Parameters:
name - name of the entry
value - float value of the entry

setNumber

public void setNumber(String name,
                      long value)
Sets the named entry of the EsObject to the long value, cast as a Number.

Parameters:
name - name of the entry
value - long value of the entry

setNumber

public void setNumber(String name,
                      int value)
Sets the named entry of the EsObject to the int value, cast as a Number.

Parameters:
name - name of the entry
value - int value of the entry

setIntegerArray

public void setIntegerArray(String name,
                            int[] value)
Sets the named entry of the EsObject to the int array value.

Parameters:
name - name of the entry
value - int array value of the entry

setStringArray

public void setStringArray(String name,
                           String[] value)
Sets the named entry of the EsObject to the string array value.

Parameters:
name - name of the entry
value - string array value of the entry

setDoubleArray

public void setDoubleArray(String name,
                           double[] value)
Sets the named entry of the EsObject to the double array value.

Parameters:
name - name of the entry
value - double array value of the entry

setFloatArray

public void setFloatArray(String name,
                          float[] value)
Sets the named entry of the EsObject to the float array value.

Parameters:
name - name of the entry
value - float array value of the entry

setBooleanArray

public void setBooleanArray(String name,
                            boolean[] value)
Sets the named entry of the EsObject to the boolean array value.

Parameters:
name - name of the entry
value - boolean array value of the entry

setByteArray

public void setByteArray(String name,
                         byte[] value)
Sets the named entry of the EsObject to the byte array value.

Parameters:
name - name of the entry
value - byte array value of the entry

setCharArray

public void setCharArray(String name,
                         char[] value)
Sets the named entry of the EsObject to the char array value.

Parameters:
name - name of the entry
value - char array value of the entry

setLongArray

public void setLongArray(String name,
                         long[] value)
Sets the named entry of the EsObject to the long array value.

Parameters:
name - name of the entry
value - long array value of the entry

setShortArray

public void setShortArray(String name,
                          short[] value)
Sets the named entry of the EsObject to the short array value.

Parameters:
name - name of the entry
value - short array value of the entry

setEsObjectArray

public void setEsObjectArray(String name,
                             EsObject[] value)
Sets the named entry of the EsObject to the EsObject array value.

Parameters:
name - name of the entry
value - EsObject array value of the entry

setNumberArray

public void setNumberArray(String name,
                           Number[] value)
Sets the named entry of the EsObject to the Number array value.

Parameters:
name - name of the entry
value - Number array value of the entry

getInteger

public int getInteger(String name)
Description copied from interface: EsObjectRO
Gets the integer value of the named entry.

Specified by:
getInteger in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getInteger

public int getInteger(String name,
                      int defaultValue)
Description copied from interface: EsObjectRO
Gets the integer value of the named entry, or the default value if any exception occurs.

Specified by:
getInteger in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getString

public String getString(String name)
Description copied from interface: EsObjectRO
Gets the string value of the named entry.

Specified by:
getString in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getString

public String getString(String name,
                        String defaultValue)
Description copied from interface: EsObjectRO
Gets the String value of the named entry, or the default value if any exception occurs.

Specified by:
getString in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getDouble

public double getDouble(String name)
Description copied from interface: EsObjectRO
Gets the double value of the named entry.

Specified by:
getDouble in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getDouble

public double getDouble(String name,
                        double defaultValue)
Description copied from interface: EsObjectRO
Gets the double value of the named entry, or the default value if any exception occurs.

Specified by:
getDouble in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getFloat

public float getFloat(String name)
Description copied from interface: EsObjectRO
Gets the float value of the named entry.

Specified by:
getFloat in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getFloat

public float getFloat(String name,
                      float defaultValue)
Description copied from interface: EsObjectRO
Gets the float value of the named entry, or the default value if any exception occurs.

Specified by:
getFloat in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getBoolean

public boolean getBoolean(String name)
Description copied from interface: EsObjectRO
Gets the boolean value of the named entry.

Specified by:
getBoolean in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getBoolean

public boolean getBoolean(String name,
                          boolean defaultValue)
Description copied from interface: EsObjectRO
Gets the boolean value of the named entry, or the default value if any exception occurs.

Specified by:
getBoolean in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getByte

public byte getByte(String name)
Description copied from interface: EsObjectRO
Gets the byte value of the named entry.

Specified by:
getByte in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getByte

public byte getByte(String name,
                    byte defaultValue)
Description copied from interface: EsObjectRO
Gets the byte value of the named entry, or the default value if any exception occurs.

Specified by:
getByte in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getChar

public char getChar(String name)
Description copied from interface: EsObjectRO
Gets the char value of the named entry.

Specified by:
getChar in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getChar

public char getChar(String name,
                    char defaultValue)
Description copied from interface: EsObjectRO
Gets the char value of the named entry, or the default value if any exception occurs.

Specified by:
getChar in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getLong

public long getLong(String name)
Description copied from interface: EsObjectRO
Gets the long value of the named entry.

Specified by:
getLong in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getLong

public long getLong(String name,
                    long defaultValue)
Description copied from interface: EsObjectRO
Gets the long value of the named entry, or the default value if any exception occurs.

Specified by:
getLong in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getShort

public short getShort(String name)
Description copied from interface: EsObjectRO
Gets the short value of the named entry.

Specified by:
getShort in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getShort

public short getShort(String name,
                      short defaultValue)
Description copied from interface: EsObjectRO
Gets the short value of the named entry, or the default value if any exception occurs.

Specified by:
getShort in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getEsObject

public EsObject getEsObject(String name)
Description copied from interface: EsObjectRO
Gets the EsObject value of the named entry.

Specified by:
getEsObject in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getEsObject

public EsObject getEsObject(String name,
                            EsObject defaultValue)
Description copied from interface: EsObjectRO
Gets the EsObject value of the named entry, or the default value if any exception occurs.

Specified by:
getEsObject in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getNumber

public Number getNumber(String name)
Description copied from interface: EsObjectRO
Gets the Number value of the named entry.

Specified by:
getNumber in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getNumber

public Number getNumber(String name,
                        Number defaultValue)
Description copied from interface: EsObjectRO
Gets the Number value of the named entry, or the default value if any exception occurs.

Specified by:
getNumber in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getIntegerArray

public int[] getIntegerArray(String name)
Description copied from interface: EsObjectRO
Gets the int array value of the named entry.

Specified by:
getIntegerArray in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getIntegerArray

public int[] getIntegerArray(String name,
                             int[] defaultValue)
Description copied from interface: EsObjectRO
Gets the int array value of the named entry, or the default value if any exception occurs.

Specified by:
getIntegerArray in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getStringArray

public String[] getStringArray(String name)
Description copied from interface: EsObjectRO
Gets the string array value of the named entry.

Specified by:
getStringArray in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getStringArray

public String[] getStringArray(String name,
                               String[] defaultValue)
Description copied from interface: EsObjectRO
Gets the string array value of the named entry, or the default value if any exception occurs.

Specified by:
getStringArray in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getDoubleArray

public double[] getDoubleArray(String name)
Description copied from interface: EsObjectRO
Gets the double array value of the named entry.

Specified by:
getDoubleArray in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getDoubleArray

public double[] getDoubleArray(String name,
                               double[] defaultValue)
Description copied from interface: EsObjectRO
Gets the double array value of the named entry, or the default value if any exception occurs.

Specified by:
getDoubleArray in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getFloatArray

public float[] getFloatArray(String name)
Description copied from interface: EsObjectRO
Gets the float array value of the named entry.

Specified by:
getFloatArray in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getFloatArray

public float[] getFloatArray(String name,
                             float[] defaultValue)
Description copied from interface: EsObjectRO
Gets the float array value of the named entry, or the default value if any exception occurs.

Specified by:
getFloatArray in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getBooleanArray

public boolean[] getBooleanArray(String name)
Description copied from interface: EsObjectRO
Gets the boolean array value of the named entry.

Specified by:
getBooleanArray in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getBooleanArray

public boolean[] getBooleanArray(String name,
                                 boolean[] defaultValue)
Description copied from interface: EsObjectRO
Gets the boolean array value of the named entry, or the default value if any exception occurs.

Specified by:
getBooleanArray in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getByteArray

public byte[] getByteArray(String name)
Description copied from interface: EsObjectRO
Gets the byte array value of the named entry.

Specified by:
getByteArray in interface EsObjectRO
Parameters:
name - name of the entry
Returns:
value

getByteArray

public byte[] getByteArray(String name,
                           byte[] defaultValue)
Description copied from interface: EsObjectRO
Gets the byte array value of the named entry, or the default value if any exception occurs.

Specified by:
getByteArray in interface EsObjectRO
Parameters:
name - name of the entry
defaultValue - value to return if an exception occurs
Returns:
value

getCharArray

public char[] getCharArray(String name)
Description copied from interface: EsObjectRO
Gets the char array value of the named entry.

Specified by: