gumbo.util.relation
Class AbstractRelation

java.lang.Object
  |
  +--gumbo.util.AbstractDisposable
        |
        +--gumbo.util.AbstractDelegatable
              |
              +--gumbo.util.AbstractDelegatable.Serial
                    |
                    +--gumbo.util.relation.AbstractRelation
All Implemented Interfaces:
Delegatable, Disposable, Relation, java.io.Serializable
Direct Known Subclasses:
AbstractAssociate, AbstractTreeNode, TestRelation

public abstract class AbstractRelation
extends AbstractDelegatable.Serial
implements Relation, java.io.Serializable

A full implementation of the Relation interface, with serialization. Serialization includes this relation and its relationship, but not its relation event listeners. The default Disposable implementation nulls the delegator reference and disconnects any relation event listeners. Subclasses should override implDispose() to also disconnect this relation from any adjacent relations to maintain consistency in the relationship.

Concrete relations generally implement specific connection types and mutators. Typically, a chain of responsibility is established such that a specific check calls a more general check, and so on. Checking can enforce compatibility and mutability constraints actively and/or passively. Active enforcement involves changing the state of this relation to conform (such as automaticaly setting a dead relation's relationship). Passive enforcement throws an exception if a non-conformance is detected (a relation involved in the connection is dead).

The most general check for relation connection is provided here by checkRelation(). For example, in a tree node, the addChild() mutator would call checkAddChild() to check the specific mutation, which would call checkChild() to check the specific connection, which would call checkRelation() to check the general connection. Depending on the type of delegation used for the relation, check methods may use relation or delegator parameters.

Version:
$Revision: 1.3 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class gumbo.util.AbstractDelegatable
AbstractDelegatable.Serial
 
Constructor Summary
AbstractRelation(Relationship relationship)
          Creates an instance with an uninitialized delegator.
 
Method Summary
 boolean canFindRelation(java.lang.Object delegator)
          Convenience method that returns true if a relation corresponding to a delegator can be found in this relation's relationship.
protected  void checkClearedRelationship(Relationship relationship)
          Called by the system after clearing this relation's relationship.
protected  void checkRelation(Relation relation)
          Called by subclasses to check a relation and its delegator before connecting it to this relation.
protected  void checkSettingRelationship(Relationship relationship)
          Called by the system before setting this relation's relationship.
 Relation findRelation(java.lang.Object delegator)
          Convenience method for getting the relation corresponding to a delegator in this relation's relationship.
 ConnectionField.EventOut getAddedConnectionOut()
          Sends a connection involving this relation after the connection is created.
 Relationship getRelationship()
          Gets the relationship that this relation belongs to.
 ConnectionField.EventOut getRemovingConnectionOut()
          Sends a connection involving this relation before the connection is destroyed.
protected  void implDispose()
          Called during disposal while the base class is still valid.
protected  void initedDelegator()
          If the relationship is not null, calls its implAddRelation(this).
 void setRelationship(Relationship relationship)
          Ignores no change in relationship, calls checkClearedRelationship() after setting the relationship null, and checkSettingRelationship() before setting it non-null.
 java.lang.String toString()
           
 
Methods inherited from class gumbo.util.AbstractDelegatable
getDelegator, initDelegator, initingDelegator, isDelegatorInited
 
Methods inherited from class gumbo.util.AbstractDisposable
dispose, isDisposed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gumbo.util.relation.Relation
implReadConnections, implWriteConnections
 
Methods inherited from interface gumbo.util.Disposable
dispose, isDisposed
 
Methods inherited from interface gumbo.util.Delegatable
getDelegator, initDelegator, isDelegatorInited
 

Constructor Detail

AbstractRelation

public AbstractRelation(Relationship relationship)
Creates an instance with an uninitialized delegator. Must call initDelegator() before using this delegate, such as new AbstractRelation(r).initDelegator(d).

Parameters:
relationship - This relation's relationship. Null if none (a dead relation).
Method Detail

checkRelation

protected void checkRelation(Relation relation)
Called by subclasses to check a relation and its delegator before connecting it to this relation. Implementors should chain to the super method, and throw an exception if the relation is incompatible. The default implementation thows an exception if relation is null, then calls checkDelegator() with the relation's delegator (assumes other relations must be like this one).

Parameters:
relation - The relation. Possibly null or this relation (self-connection).

checkSettingRelationship

protected void checkSettingRelationship(Relationship relationship)
Called by the system before setting this relation's relationship. Default implementation: Relationship changes must be from null to non-null.

Parameters:
relationship - The new relationship. Never null.

checkClearedRelationship

protected void checkClearedRelationship(Relationship relationship)
Called by the system after clearing this relation's relationship. Default implementation: Disposes this relation (to assure that it is isolated from all other relations).

Parameters:
relationship - The old relationship. Never null.

setRelationship

public void setRelationship(Relationship relationship)
Ignores no change in relationship, calls checkClearedRelationship() after setting the relationship null, and checkSettingRelationship() before setting it non-null.

Specified by:
setRelationship in interface Relation
Parameters:
relationship - The relationship. Null if none (dead).

getRelationship

public Relationship getRelationship()
Description copied from interface: Relation
Gets the relationship that this relation belongs to.

Specified by:
getRelationship in interface Relation
Returns:
The relationship. If null, this relation is dead; if non-null it is live.

canFindRelation

public boolean canFindRelation(java.lang.Object delegator)
Description copied from interface: Relation
Convenience method that returns true if a relation corresponding to a delegator can be found in this relation's relationship.

Specified by:
canFindRelation in interface Relation
Parameters:
delegator - The delegator. Returns false if null.
Returns:
The result. False if this relation is not in a relationship or delegator is null.

findRelation

public Relation findRelation(java.lang.Object delegator)
Description copied from interface: Relation
Convenience method for getting the relation corresponding to a delegator in this relation's relationship.

Specified by:
findRelation in interface Relation
Parameters:
delegator - The delegator. Never null.
Returns:
The delegator's relation. Never null.

getAddedConnectionOut

public final ConnectionField.EventOut getAddedConnectionOut()
Description copied from interface: Relation
Sends a connection involving this relation after the connection is created. Never null.

Specified by:
getAddedConnectionOut in interface Relation

getRemovingConnectionOut

public final ConnectionField.EventOut getRemovingConnectionOut()
Description copied from interface: Relation
Sends a connection involving this relation before the connection is destroyed. Never null.

Specified by:
getRemovingConnectionOut in interface Relation

initedDelegator

protected void initedDelegator()
If the relationship is not null, calls its implAddRelation(this).

Overrides:
initedDelegator in class AbstractDelegatable

implDispose

protected void implDispose()
Called during disposal while the base class is still valid. Default implementation: Removes this relation from its relationship and disposes its relation event nodes. Implentors can assume disposal loops are blocked, should disconnect and/or dispose any relations (while this object is still valid), and then call super.implDispose() to properly dispose this super class.

Overrides:
implDispose in class AbstractDelegatable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object