com.bbn.swede.core.dom
Class OASTDelta

java.lang.Object
  extended bycom.bbn.swede.core.dom.OASTDelta
All Implemented Interfaces:
IOASTDelta

public class OASTDelta
extends Object
implements IOASTDelta

Concrete implementation of the IOASTDelta interface. An OAST delta represents structural changes in a document's OWL abstract syntax tree between two discrete points in time.

Author:
jlerner

Field Summary
 
Fields inherited from interface com.bbn.swede.core.dom.IOASTDelta
CHANGED, DESCENDANT, INSERTED, REMOVED, REPLACED
 
Constructor Summary
OASTDelta(IOASTDelta other)
          Creates a deep copy of an OAST delta.
 
Method Summary
 void accept(IOASTDeltaVisitor visitor)
          Begins a preorder traversal starting with this delta.
 void combine(OASTDelta other)
          Merges the changes represented by a subsequent OAST delta into this one.
static IOASTDelta createInsertDelta(OASTNode nodeParent, OASTNode[] nodesInserted)
          Creates an OAST delta representing the insertion of one or more nodes.
static IOASTDelta createRemoveDelta(OASTNode[] nodesRemoved)
          Creates an OAST delta representing the removal of one or more nodes.
static IOASTDelta createReparseDelta(OASTNode[] nodesRemoved, OASTNode[] nodesInserted)
          Creates an OAST delta representing the results of a partial reparse.
static IOASTDelta createReplaceDelta(OASTNode removed, OASTNode inserted)
          Creates an OAST delta representing the replacement of one node with another node.
(package private)  void dump()
          Dumps a string representation of this delta and all deltas below it.
 IOASTDelta[] getChildren()
          Returns OAST deltas for all children of this node which were inserted, removed, replaced, or changed.
 IOASTDelta[] getChildren(int typeMask)
          Returns OAST deltas for all children of this node whose type matches the specified mask.
 IOASTDelta[] getDeltas(int typeMask)
          Searches the delta tree rooted at this delta for all changes matching a particular type mask.
 OASTNode getNodeAfter()
          Retrieves the node that is in the tree after the event that created this delta.
 OASTNode getNodeBefore()
          Retrieves the node that was in the tree before the event that created this delta.
 int getType()
          Returns the type of this OAST delta.
 boolean typeMatches(int typeMask)
          Indicates whether the delta's type matches a specified mask.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OASTDelta

public OASTDelta(IOASTDelta other)
Creates a deep copy of an OAST delta.

Parameters:
other - The delta to clone
Method Detail

createReparseDelta

public static IOASTDelta createReparseDelta(OASTNode[] nodesRemoved,
                                            OASTNode[] nodesInserted)

Creates an OAST delta representing the results of a partial reparse. This method is only designed for use with partial reparses and makes the following assumptions:

Parameters:
nodesRemoved - array of nodes removed before the reparse
nodesInserted - array of nodes created by the reparse
Returns:
A delta representing the removed and inserted nodes, rooted at the top of the OAST, or null if there is no net structural change.

createReplaceDelta

public static IOASTDelta createReplaceDelta(OASTNode removed,
                                            OASTNode inserted)
Creates an OAST delta representing the replacement of one node with another node.

Parameters:
removed - The node removed
inserted - The node replacing it
Returns:
A delta representing the removed and inserted nodes, rooted at the top of the OAST, or null if there is no net structural change.

createInsertDelta

public static IOASTDelta createInsertDelta(OASTNode nodeParent,
                                           OASTNode[] nodesInserted)
Creates an OAST delta representing the insertion of one or more nodes.

Parameters:
nodeParent - the node that will be the parent of the inserted nodes
nodesInserted - the inserted nodes
Returns:
A delta representing the node insertion, rooted at the top of the OAST.

createRemoveDelta

public static IOASTDelta createRemoveDelta(OASTNode[] nodesRemoved)
Creates an OAST delta representing the removal of one or more nodes. The removed nodes are assumed to share a common parent.

Parameters:
nodesRemoved - the removed nodes
Returns:
A delta representing the node removal, rooted at the top of the OAST.

getNodeBefore

public OASTNode getNodeBefore()
Description copied from interface: IOASTDelta
Retrieves the node that was in the tree before the event that created this delta. There is no before node for INSERTED or DESCENDANT deltas.

Specified by:
getNodeBefore in interface IOASTDelta
Returns:
The node as it existed before the event, or null if this is not applicable for the delta's type.

getNodeAfter

public OASTNode getNodeAfter()
Description copied from interface: IOASTDelta
Retrieves the node that is in the tree after the event that created this delta. There is no after node for REMOVED deltas.

Specified by:
getNodeAfter in interface IOASTDelta
Returns:
The node as it exists after the event, or null if this is not applicable for the delta's type.

getType

public int getType()
Description copied from interface: IOASTDelta
Returns the type of this OAST delta. The type will be one of INSERTED, REMOVED, CHANGED, REPLACED, or DESCENDANT.

Specified by:
getType in interface IOASTDelta
Returns:
the type of this OAST delta

accept

public void accept(IOASTDeltaVisitor visitor)
Description copied from interface: IOASTDelta
Begins a preorder traversal starting with this delta. The visitor's visit method will be called for this resource delta and, if it returns true, on this delta's children.

Specified by:
accept in interface IOASTDelta
Parameters:
visitor - The visitor to use for the traversal.

getChildren

public IOASTDelta[] getChildren()
Description copied from interface: IOASTDelta

Returns OAST deltas for all children of this node which were inserted, removed, replaced, or changed.

This is a convenience method, fully equivalent to:

getChildren(INSERTED | REMOVED | CHANGED | DESCENDANT)

Specified by:
getChildren in interface IOASTDelta
Returns:
the OAST deltas for all child nodes, or an empty array if no children were modified.

getChildren

public IOASTDelta[] getChildren(int typeMask)
Description copied from interface: IOASTDelta
Returns OAST deltas for all children of this node whose type matches the specified mask.

Specified by:
getChildren in interface IOASTDelta
Parameters:
typeMask - a type mask formed by a bitwise OR of IOASTDelta type constants
Returns:
the OAST deltas for all child nodes matching typeMask, or an empty array if no children match.

dump

void dump()
Dumps a string representation of this delta and all deltas below it.


combine

public void combine(OASTDelta other)
Merges the changes represented by a subsequent OAST delta into this one.

Parameters:
other - The subsequent delta to merge.

getDeltas

public IOASTDelta[] getDeltas(int typeMask)
Description copied from interface: IOASTDelta
Searches the delta tree rooted at this delta for all changes matching a particular type mask.

Specified by:
getDeltas in interface IOASTDelta
Parameters:
typeMask - The type mask.
Returns:
An array containing all deltas matching typeMask.

typeMatches

public boolean typeMatches(int typeMask)
Description copied from interface: IOASTDelta
Indicates whether the delta's type matches a specified mask.

Specified by:
typeMatches in interface IOASTDelta
Parameters:
typeMask - The type mask.
Returns:
true if this delta's type matches typeMask, false if not.


Copyright © 2004-2005 BBN Technologies. All Rights Reserved.