viper.api.impl
Class EventfulNodeHelper

java.lang.Object
  extended byviper.api.impl.EventfulNodeHelper
All Implemented Interfaces:
EventfulNode, Node, TransactionalNode
Direct Known Subclasses:
AttrConfigImpl, AttributeImpl, ConfigImpl, DescriptorImpl, SourcefileImpl, ViperDataImpl

public abstract class EventfulNodeHelper
extends java.lang.Object
implements TransactionalNode

An abstract viper node class.

Author:
davidm

Nested Class Summary
 
Nested classes inherited from class viper.api.extensions.TransactionalNode
TransactionalNode.Transaction
 
Field Summary
protected  java.lang.String childNodeType
           
protected  boolean notifyingListeners
           
 
Constructor Summary
EventfulNodeHelper()
           
 
Method Summary
 void addChild(Node n)
          (Optional) Adds a child in some arbitrary position.
 void addChild(Node n, boolean undoable)
          Adds a child node, but returns an undoable or non-undoable event according to the parameter.
 void addNodeListener(NodeListener nl)
          Adds a listener for changes to the node or its children.
 TransactionalNode.Transaction begin(java.lang.String uri)
          Starts a transaction on this node.
 void fireMajorNodeChanged(MajorNodeChangeEvent mnce)
          Fires the given major node change event, combining several other changes into one.
 void fireMinorNodeChanged(MinorNodeChangeEvent mnce)
          Fires the given minor node change event, indicating that some aspect of the node has changed.
 void fireNodeChanged(NodeChangeEvent nce)
          Fires the given node change event, indicating that some of the children of the node have been added or removed.
protected abstract  java.util.logging.Logger getLogger()
           
 ViperData getRoot()
          Gets the root of the tree.
 boolean hasListeners()
          Tests to see if any listeners are attached to the current node.
protected abstract  void helpSetChild(int i, Node n, TransactionalNode.Transaction t, boolean insert)
          Replace the child at index i with the given node.
 boolean isNotifyingListeners()
           
 boolean isWriteLocked()
          Tests to see if set will work.
protected abstract  void postHelpSetChild(int i, Node n, TransactionalNode.Transaction t, boolean insert)
          Invoked after the event has been generated for the corresponding helpSetChild call.
 void removeChild(int i)
          (Optional) Remove child at offset i.
 void removeChild(int i, boolean undoable)
          Removes the specified child, emitting an undoable or non-undoable version of the event as requested.
 void removeChild(Node n)
          (Optional) Remove child n.
 void removeNodeListener(NodeListener nl)
          Adds a listener for changes to the node or its children.
 void setChild(int i, Node n)
          (Optional) Sets the child at i to n.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface viper.api.Node
getChild, getChildren, getNumberOfChildren, getParent, hasChild, indexOf
 

Field Detail

childNodeType

protected java.lang.String childNodeType

notifyingListeners

protected boolean notifyingListeners
Constructor Detail

EventfulNodeHelper

public EventfulNodeHelper()
Method Detail

hasListeners

public boolean hasListeners()
Tests to see if any listeners are attached to the current node.

Returns:
false when no listeners are attached

addNodeListener

public void addNodeListener(NodeListener nl)
Description copied from interface: EventfulNode
Adds a listener for changes to the node or its children.

Specified by:
addNodeListener in interface EventfulNode
Parameters:
nl - the node listener to add
See Also:
EventfulNode.addNodeListener(viper.api.extensions.NodeListener)

removeNodeListener

public void removeNodeListener(NodeListener nl)
Description copied from interface: EventfulNode
Adds a listener for changes to the node or its children.

Specified by:
removeNodeListener in interface EventfulNode
Parameters:
nl - the node listener to add
See Also:
EventfulNode.removeNodeListener(viper.api.extensions.NodeListener)

getRoot

public ViperData getRoot()
Description copied from interface: Node
Gets the root of the tree.

Specified by:
getRoot in interface Node
Returns:
the node at the root of the tree.
See Also:
Node.getRoot()

getLogger

protected abstract java.util.logging.Logger getLogger()

fireNodeChanged

public void fireNodeChanged(NodeChangeEvent nce)
Description copied from interface: EventfulNode
Fires the given node change event, indicating that some of the children of the node have been added or removed. This probably shouldn't be part of the interface, but instead on an Abstract type.

Specified by:
fireNodeChanged in interface EventfulNode
Parameters:
nce - the change event
See Also:
EventfulNode.fireNodeChanged(viper.api.extensions.NodeChangeEvent)

isWriteLocked

public boolean isWriteLocked()
Tests to see if set will work.

Returns:

fireMinorNodeChanged

public void fireMinorNodeChanged(MinorNodeChangeEvent mnce)
Description copied from interface: EventfulNode
Fires the given minor node change event, indicating that some aspect of the node has changed. This probably shouldn't be part of the interface, but instead on an Abstract type.

Specified by:
fireMinorNodeChanged in interface EventfulNode
Parameters:
mnce - the change event
See Also:
EventfulNode.fireMinorNodeChanged(viper.api.extensions.MinorNodeChangeEvent)

fireMajorNodeChanged

public void fireMajorNodeChanged(MajorNodeChangeEvent mnce)
Description copied from interface: EventfulNode
Fires the given major node change event, combining several other changes into one. This probably shouldn't be part of the interface, but instead on an Abstract type.

Specified by:
fireMajorNodeChanged in interface EventfulNode
Parameters:
mnce - the change event
See Also:
EventfulNode.fireMajorNodeChanged(viper.api.extensions.MajorNodeChangeEvent)

helpSetChild

protected abstract void helpSetChild(int i,
                                     Node n,
                                     TransactionalNode.Transaction t,
                                     boolean insert)
Replace the child at index i with the given node. If insert is set, makes the child at index i the given node and shifts i to i+1, i+1 to i+2, and so on. This should not generate an event.

Parameters:
i - the index to insert/set
n - the node to insert
t - the transaction associated with the event, if it exists. Otherwise, it is null.
insert - true if the node should be inserted, false if the current node i should be replaced

postHelpSetChild

protected abstract void postHelpSetChild(int i,
                                         Node n,
                                         TransactionalNode.Transaction t,
                                         boolean insert)
Invoked after the event has been generated for the corresponding helpSetChild call. This is useful if you need to order your events. This should not generate an event.

Parameters:
i - the index to insert/set
n - the node to insert
t - the transaction associated with the event, if it exists. Otherwise, it is null.
insert - true if the node should be inserted, false if the current node i should be replaced

addChild

public void addChild(Node n)
Description copied from interface: Node
(Optional) Adds a child in some arbitrary position.

Specified by:
addChild in interface Node
Parameters:
n - the node to add
See Also:
Node.addChild(viper.api.Node)

setChild

public void setChild(int i,
                     Node n)
Description copied from interface: Node
(Optional) Sets the child at i to n.

Specified by:
setChild in interface Node
Parameters:
i - the index of the child to replace
n - the new value of the child
See Also:
Node.setChild(int, viper.api.Node)

removeChild

public void removeChild(int i)
Description copied from interface: Node
(Optional) Remove child at offset i.

Specified by:
removeChild in interface Node
Parameters:
i - child to remove
See Also:
Node.removeChild(int)

removeChild

public void removeChild(Node n)
Description copied from interface: Node
(Optional) Remove child n.

Specified by:
removeChild in interface Node
Parameters:
n - child to remove.
See Also:
Node.removeChild(viper.api.Node)

addChild

public void addChild(Node n,
                     boolean undoable)
Adds a child node, but returns an undoable or non-undoable event according to the parameter.

Parameters:
n - the node to add
undoable - whether to allow undo
See Also:
Node.addChild(viper.api.Node)

removeChild

public void removeChild(int i,
                        boolean undoable)
Removes the specified child, emitting an undoable or non-undoable version of the event as requested.

Parameters:
i - the index of the child to remove
undoable - whether to allow undoing the event

begin

public TransactionalNode.Transaction begin(java.lang.String uri)
Description copied from interface: TransactionalNode
Starts a transaction on this node.

Specified by:
begin in interface TransactionalNode
Parameters:
uri - an identifier to associate with the transaction; useful for logging
Returns:
the Transaction object associated with the new transaction.
See Also:
TransactionalNode.begin(java.lang.String)

isNotifyingListeners

public boolean isNotifyingListeners()
Specified by:
isNotifyingListeners in interface EventfulNode
Returns: