gumbo.util
Interface Delegatable

All Known Subinterfaces:
Associate, GraphicSpaceRoot, Relation, TreeNode
All Known Implementing Classes:
AbstractAssociate, AbstractDelegatable, AbstractGraphicSpaceRoot, AbstractRelation, AbstractTreeNode, Delegatables.DelegatableImm, Delegatables.DelegatableWrapper, Relations.RelationImm, Relations.RelationWrapper, TreeNodes.TreeNodeImm, TreeNodes.TreeNodeWrapper

public interface Delegatable

A base interface allowing (but not requiring) this object to serve as a delegate for some other delegator. Typically used by delegates providing a "navigable" service for its delegator. A navigable service is one that provides access to other instances of a service, such as nodes in a data tree. In such a case a delegator is interested in accessing other delegators, not the delegate service instances.

If a delegator wants to replace a delegate it simply replaces the old delegate reference with the new one. Assuming that only the delegator references the old delegate there is no need to "dispose" the delegate. This may not be the case for navigational delegates, however. To assure that a delegate will be disposed it can implement Disposable.

In situations where delegation may be nested it is left to the implementor to decide, and the documention to describe, whether the delegator returned by getDelegator() is the immediate delegator (as in a delegation chain) or some "ultimate" delegator (the root delegator in a chain, or some other object outside the chain).

Version:
$Revision: 1.13 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.

Method Summary
 java.lang.Object getDelegator()
          Gets the delegator of this delegate, as set by initDelegator().
 Delegatable initDelegator(java.lang.Object delegator)
          Used by delegators and serialization to initialize this delegate's delegator reference.
 boolean isDelegatorInited()
          Returns true if initDelegator() has been called and the initialization is still valid; otherwise, returns false.
 

Method Detail

initDelegator

public Delegatable initDelegator(java.lang.Object delegator)
Used by delegators and serialization to initialize this delegate's delegator reference. Re-initialization with the same value is allowed. Throws an exception if initialization fails for any reason.

Parameters:
delegator - Reference to the delegator. If self-delegation is allowed and the delegator is null, this object is the delegator (which facilitates inline construction).
Returns:
Reference to this delegatable (which facilitates inline construction).
Throws:
java.lang.IllegalStateException - Delegator is different from the initial one.

isDelegatorInited

public boolean isDelegatorInited()
Returns true if initDelegator() has been called and the initialization is still valid; otherwise, returns false.

Returns:
The result.

getDelegator

public java.lang.Object getDelegator()
Gets the delegator of this delegate, as set by initDelegator(). Throws an exception if isDelegatorInited() is false.

Returns:
Reference to the delegator. Possibly this delegate (self delegation) but never null.
Throws:
java.lang.IllegalStateException - Must first call initDelegator(), or initialization is no longer valid.