org.elkoserver.server.context
Class Mod

java.lang.Object
  extended by org.elkoserver.server.context.Mod
All Implemented Interfaces:
Cloneable, DispatchTarget, Encodable
Direct Known Subclasses:
Cap, Cartesian, Census, Chat, DeviceUserMod, Dictionary, Image, Invisible, Note, NoteMaker, PrivateChat, TalkOptions, TalkPrefs

public abstract class Mod
extends Object
implements Encodable, DispatchTarget, Cloneable

Abstract base class to facilitate implementation of application-specific mods that can be attached to basic objects (contexts, users, and items). This class implements basic services needed by or useful to all mods, regardless of application. Subclasses need to implement application-specific mod logic as well as the encode() method called for by the Encodable interface.


Constructor Summary
protected Mod()
          Base constructor.
 
Method Summary
 void attachTo(BasicObject object)
          Attach this mod to an object.
 Object clone()
          Clone this object.
 Context context()
          Obtain the context in which the object this mod is attached to is located, regardless of how deeply nested in containers the object might be.
protected  void ensureHolding(User who)
          Guard function to guarantee that an operation being attempted by a user is being applied to an object that that user is holding.
protected  void ensureInContext(User who)
          Guard function to guarantee that an operation being attempted by a user on an object that is contained by the user's context.
protected  void ensureReachable(User who)
          Guard function to guarantee that an operation being attempted by a user is being applied to an object that that user is allowed to reach (either because it is in the context or because the user is holding it).
protected  void ensureSameContext(User who)
          Guard function to guarantee that an operation being attempted by a user on an object is taking place in the same context as the object.
protected  void ensureSameUser(User who)
          Guard function to guarantee that an operation being attempted by a user is being applied to that same user.
protected  BasicObject holder()
          Obtain the user or context holding the object to which this mod is attached, regardless of how deeply nested in containers it might be.
 boolean isEphemeral()
          Test if this mod is ephemeral.
 void markAsChanged()
          Mark the object to which this mod is attached as having been changed and thus in need of checkpointing.
 void markAsEphemeral()
          Mark this mod as being ephemeral.
 BasicObject object()
          Obtain the object to which this mod is attached.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.elkoserver.json.Encodable
encode
 

Constructor Detail

Mod

protected Mod()
Base constructor.

Method Detail

attachTo

public void attachTo(BasicObject object)
Attach this mod to an object.

Only one mod of any given class may be attached to any given object.

Application code will not normally need to call this method, since it is called automatically when an object is loaded from persistent storage. However, certain specialized applications that synthesize objects directly will need to use this to attach the mods they have constructed to the objects they have constructed.

Parameters:
object - The object to which this mod is to be attached.

clone

public Object clone()
             throws CloneNotSupportedException
Clone this object.

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

ensureReachable

protected void ensureReachable(User who)
                        throws MessageHandlerException
Guard function to guarantee that an operation being attempted by a user is being applied to an object that that user is allowed to reach (either because it is in the context or because the user is holding it). If this mod is not attached to such an object, this method will throw a MessageHandlerException exception.

Parameters:
who - The user who is attempting the operation.
Throws:
MessageHandlerException - if the test fails.

ensureHolding

protected void ensureHolding(User who)
                      throws MessageHandlerException
Guard function to guarantee that an operation being attempted by a user is being applied to an object that that user is holding. If this mod is not attached to such an object, this method will throw a MessageHandlerException exception.

Parameters:
who - The user who is attempting the operation.
Throws:
MessageHandlerException - if the test fails.

ensureSameUser

protected void ensureSameUser(User who)
                       throws MessageHandlerException
Guard function to guarantee that an operation being attempted by a user is being applied to that same user. If this mod is not attached to that user, this method will throw a MessageHandlerException.

Parameters:
who - The user who is attempting the operation.
Throws:
MessageHandlerException - if the test fails.

ensureSameContext

protected void ensureSameContext(User who)
                          throws MessageHandlerException
Guard function to guarantee that an operation being attempted by a user on an object is taking place in the same context as the object. If this mod is not attached to an object in the same context as the user, this method will throw a MessageHandlerException.

Parameters:
who - The user who is attempting the operation.
Throws:
MessageHandlerException - if the test fails.

ensureInContext

protected void ensureInContext(User who)
                        throws MessageHandlerException
Guard function to guarantee that an operation being attempted by a user on an object that is contained by the user's context. If this mod is not attached to such an object, this method will throw a MessageHandlerException.

Parameters:
who - The user who is attempting the operation.
Throws:
MessageHandlerException - if the test fails.

holder

protected BasicObject holder()
Obtain the user or context holding the object to which this mod is attached, regardless of how deeply nested in containers it might be.

Returns:
the user or context in which the object that mod is attached to is located, at whatever level of container nesting, or null if it is not held by anything.

isEphemeral

public boolean isEphemeral()
Test if this mod is ephemeral. If a mod is ephemeral, its state is not persisted. A mod is made ephemeral by calling the markAsEphemeral() method.

Returns:
true if the mod is ephemeral, false if not.

markAsChanged

public void markAsChanged()
Mark the object to which this mod is attached as having been changed and thus in need of checkpointing.


markAsEphemeral

public void markAsEphemeral()
Mark this mod as being ephemeral.


object

public BasicObject object()
Obtain the object to which this mod is attached.

Returns:
the object to which this mod is attached.

context

public Context context()
Obtain the context in which the object this mod is attached to is located, regardless of how deeply nested in containers the object might be.

Returns:
the context in which this mod is located, or null if it is not in any context.