org.elkoserver.server.context.mods
Class Dictionary

java.lang.Object
  extended by org.elkoserver.server.context.Mod
      extended by org.elkoserver.server.context.mods.Dictionary
All Implemented Interfaces:
Cloneable, DispatchTarget, Encodable, ContextMod, GeneralMod, ItemMod, UserMod

public class Dictionary
extends Mod
implements GeneralMod

Mod to associate a server-moderated hashtable with its object. This mod may be attached to a context, user or item.


Constructor Summary
Dictionary(String[] names, String[] values, OptBoolean persist)
          JSON-driven constructor.
 
Method Summary
 void delvar(User from, String[] names)
          Message handler for the 'delvar' message.
 JSONLiteral encode(EncodeControl control)
          Encode this mod for transmission or persistence.
 void setvar(User from, String[] names, String[] values)
          Message handle for the 'setvar' message.
 
Methods inherited from class org.elkoserver.server.context.Mod
attachTo, clone, context, ensureHolding, ensureInContext, ensureReachable, ensureSameContext, ensureSameUser, holder, isEphemeral, markAsChanged, markAsEphemeral, object
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dictionary

@JSONMethod(value={"names","values","persist"})
public Dictionary(String[] names,
                                  String[] values,
                                  OptBoolean persist)
JSON-driven constructor.

Parameters:
names - Array of variable names.
values - Parallel array of values for those variables.
persist - If true, make sure any changes get saved to disk; if false (the default), changes are ephemeral.
Method Detail

encode

public JSONLiteral encode(EncodeControl control)
Encode this mod for transmission or persistence.

Specified by:
encode in interface Encodable
Parameters:
control - Encode control determining what flavor of encoding should be done.
Returns:
a JSON literal representing this mod.

delvar

@JSONMethod(value="names")
public void delvar(User from,
                                   String[] names)
            throws MessageHandlerException
Message handler for the 'delvar' message.

This message is a request to delete of one or more of the variables from the set. If the operation is successful, a corresponding 'delvar' message is broadcast to the context.

Warning: This message is not secure. As implemented today, anyone can delete variables.

recv: { to:REF, op:"delvar", names:STR[] }
send: { to:REF, op:"delvar", names:STR[[ }

Parameters:
from - The user who sent the message.
names - Names of the variables to remove.
Throws:
MessageHandlerException - if 'from' is not in the same context as this mod.

setvar

@JSONMethod(value={"names","values"})
public void setvar(User from,
                                   String[] names,
                                   String[] values)
            throws MessageHandlerException
Message handle for the 'setvar' message.

This message is a request to change the value of one or more of the variables (or to assign a new variable). If the operation is successfull, a corresponding 'setvar' message is broadcast to the context.

Warning: This message is not secure. As implemented today, anyone can modify variables.

recv: { to:REF, op:"setvar", names:STR[], values:STR[] }
send: { to:REF, op:"setvar", names:STR[], values:STR[] }

Parameters:
from - The user who sent the message.
names - Names of the variables to assign.
values - The values to set them to. Each element of the array is the value for the corresponding element of 'names.
Throws:
MessageHandlerException - if 'from' is not in the same context as this mod.