storage.memory
Class memContent

java.lang.Object
  extended bystorage.memory.memContent
All Implemented Interfaces:
storage.memory.MemContentI
Direct Known Subclasses:
memMapContent

public abstract class memContent
extends java.lang.Object
implements storage.memory.MemContentI

The base class for all of the Content classes in this package. The create and ingest methods act as static abstract constructors for these classes, using the NodeType to determine which class to construct.


Field Summary
protected  java.util.Set allContents
           
protected  CacheMap nodeContents
          Cache for all NodeContent instances created using this memContent.
 
Constructor Summary
protected memContent()
           
 
Method Summary
protected  Node assignNode(NodeContent c, java.lang.Object property, Node node)
          Called whenever a Node value is assigned anywhere in memContent.
static memContent create(NodeType t)
          Create a new instance of the given type.
protected abstract  NodeContent createNodeContent(Node n, Capability cap, storage.framework.RepoServices s)
          Create a NodeContent object with the memContent, and the given Node, Capability, and RepoServices.
protected  NodeContent findNodeContent(Node n)
          If a NodeContent record already exists (in canonical cache), return it.
 java.lang.Object getValue(java.lang.Object idx, NodeContent c)
          Access the property value, given a property.
static memContent ingest(Content c)
           
 NodeContent.Editor initEdit(Node n, storage.framework.RepoServices f)
           
 memOperator invert(memOperator op, NodeContent c)
          Compute the inverse of an Operator.
 Operator invert(Operator op, NodeContent c)
          Produce an Operator that would undo the application of op on this Content.
 boolean isValidProperty(java.lang.Object property)
          Check for the validity of a given property value.
 void modify(memOperator op, NodeContent c)
          Apply an Operator to this content object.
 NodeContent nodeContent(Node n, storage.framework.RepoServices f, Capability cap)
          Maybe create a NodeContent object that matches this memContent with the given Node.
 java.util.Iterator properties()
          A sequence of all of the properties currently indexing the contents if this Content.
protected  void rememberNodeContent(NodeContent c, boolean canonical)
          Store a Node->NodeContent pair in the cache.
protected  Node seatNode(NodeContent c, Node node)
          Ensure that any Node references are within the current Repository.
 int size()
          The number of properties contained in this Content object.
 NodeType type()
          The type of this Content object.
 Getter value(java.lang.Object obj, NodeContent c)
          A generic Getter for property values, given a property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nodeContents

protected final CacheMap nodeContents
Cache for all NodeContent instances created using this memContent.


allContents

protected final java.util.Set allContents
Constructor Detail

memContent

protected memContent()
Method Detail

create

public static memContent create(NodeType t)
Create a new instance of the given type.

Parameters:
t - the NodeType of the object that will be created
Returns:
a new memContent object with the given type

ingest

public static memContent ingest(Content c)

getValue

public final java.lang.Object getValue(java.lang.Object idx,
                                       NodeContent c)
                                throws PropertyConstraintFailure
Description copied from interface: storage.memory.MemContentI
Access the property value, given a property.

Will throw an exception if the property type is invalid, but not if the property is not available in this Node's content. This way, a value Getter can be established in anticipation of the addition of a property.

Specified by:
getValue in interface storage.memory.MemContentI
Parameters:
idx - the Object that identifies this property
Returns:
the value of the property
Throws:
PropertyConstraintFailure

modify

public void modify(memOperator op,
                   NodeContent c)
            throws InvalidOperator,
                   ConstraintFailure
Apply an Operator to this content object. Invokes the double-dispatch applyTo method of the memOperator.

Specified by:
modify in interface storage.memory.MemContentI
Parameters:
op - the memOperator to apply this content to
Throws:
InvalidOperator
ConstraintFailure

invert

public Operator invert(Operator op,
                       NodeContent c)
                throws InvalidOperator,
                       ConstraintFailure
Description copied from interface: storage.memory.MemContentI
Produce an Operator that would undo the application of op on this Content.

Specified by:
invert in interface storage.memory.MemContentI
Throws:
InvalidOperator
ConstraintFailure

invert

public memOperator invert(memOperator op,
                          NodeContent c)
                   throws InvalidOperator,
                          ConstraintFailure
Compute the inverse of an Operator.

Returns:
a memOperator that represents the inverse operation.
Throws:
InvalidOperator
ConstraintFailure

findNodeContent

protected NodeContent findNodeContent(Node n)
If a NodeContent record already exists (in canonical cache), return it.

Parameters:
n - a Node reference
Returns:
a NodeContent record if one has already been created

rememberNodeContent

protected void rememberNodeContent(NodeContent c,
                                   boolean canonical)
Store a Node->NodeContent pair in the cache. Later on it will be recoverable from findNodeContent(Node).

Parameters:
c - a NodeContent reference
canonical - if this is the canonical reference, then store in the special index as well.

createNodeContent

protected abstract NodeContent createNodeContent(Node n,
                                                 Capability cap,
                                                 storage.framework.RepoServices s)
Create a NodeContent object with the memContent, and the given Node, Capability, and RepoServices.

Parameters:
n - a Node associated with this memContent
cap - a Capability restricting access to operations
s - the RepoServices needed to manage Txns and create Nodes
Returns:
a new NodeContent object

initEdit

public NodeContent.Editor initEdit(Node n,
                                   storage.framework.RepoServices f)

nodeContent

public NodeContent nodeContent(Node n,
                               storage.framework.RepoServices f,
                               Capability cap)
Maybe create a NodeContent object that matches this memContent with the given Node. We require the Node, a set of RepoServices and an optional Capability.

Parameters:
n - the Node that this content is associated with
cap - a Capability restricting access (or null for default).
Returns:
a NodeContent object or null if not allowed

seatNode

protected Node seatNode(NodeContent c,
                        Node node)
Ensure that any Node references are within the current Repository.

Parameters:
node - the Node being referenced
c - the NodeContent context for this reference
Returns:
a "seated" reference to the given Node

assignNode

protected Node assignNode(NodeContent c,
                          java.lang.Object property,
                          Node node)
Called whenever a Node value is assigned anywhere in memContent. This takes care of accessing the Node.bareNode(), ensuring that the reference stored is in the same repository, and then that all indices are properly updated.

Parameters:
c - the NodeContent context for this assignment
property - the property being assigned
node - the Node being assigned as the value for property
Returns:
the Node pointer ultimately assigned

type

public NodeType type()
The type of this Content object.

Necessarily a NodeType type, and always a specific instance of MapType, RecordType or SequenceType.


size

public int size()
The number of properties contained in this Content object.


properties

public java.util.Iterator properties()
A sequence of all of the properties currently indexing the contents if this Content.


isValidProperty

public boolean isValidProperty(java.lang.Object property)
Check for the validity of a given property value.

Parameters:
property - the property to be checked
Returns:
true if that value can be used as a property of this Node

value

public Getter value(java.lang.Object obj,
                    NodeContent c)
A generic Getter for property values, given a property.

Will throw an exception if the property type is invalid, but not if the property is not available in this Node's content. This way, a value Getter can be established in anticipation of the addition of a property.

Parameters:
obj - the Object that identifies this property