org.jplate.foundation.node.impl.defaults
Class DefaultBranchNode<BC,LC>

java.lang.Object
  extended by org.jplate.foundation.node.impl.AbstractNode<BC,LC>
      extended by org.jplate.foundation.node.impl.defaults.DefaultBranchNode<BC,LC>
Type Parameters:
BC - The branch context representing data type stored in branches.
LC - The leaf context representing data type stored in leaves.
All Implemented Interfaces:
java.io.Serializable, FormattableIfc, VisitableIfc<NodeVisitorIfc<BC,LC>>, BranchNodeIfc<BC,LC>, NodeIfc<BC,LC>

public final class DefaultBranchNode<BC,LC>
extends AbstractNode<BC,LC>
implements BranchNodeIfc<BC,LC>

Default implementation of BranchNodeIfc. Child node manipulation can be threadsafe by using an implementation of ListFactoryIfc that returns synchronized List's. However, mutating the context is not thread safe.

Modifications:
    $Date: 2008-12-02 12:32:45 -0500 (Tue, 02 Dec 2008) $
    $Revision: 479 $
    $Author: sfloess $
    $HeadURL: https://jplate.svn.sourceforge.net/svnroot/jplate/trunk/src/dev/java/org/jplate/foundation/node/impl/defaults/DefaultBranchNode.java $
    

See Also:
ListFactoryIfc, Serialized Form

Field Summary
private  java.util.List<NodeIfc<BC,LC>> _childList
          Child nodes.
private  BC _context
          Self's context.
private  org.apache.commons.logging.Log _log
          Used for logging.
private  NodeFactoryIfc<BC,LC> _nodeFactory
          Used to create child branch nodes.
static java.lang.String LIST_FACTORY_IS_NULL_MSG
          Denotes the list factory is null.
static java.lang.String NODE_FACTORY_IS_NULL_MSG
          Denotes the node factory is null.
private static long serialVersionUID
          For serialization purposes.
 
Constructor Summary
DefaultBranchNode()
          Default constructor.
DefaultBranchNode(BranchNodeIfc<BC,LC> parent)
          This constructor sets the parent.
DefaultBranchNode(BranchNodeIfc<BC,LC> parent, ListFactoryIfc<NodeIfc<BC,LC>> listFactory, NodeFactoryIfc<BC,LC> nodeFactory)
          This constructor sets the parent, context and factories for self.
DefaultBranchNode(ListFactoryIfc<NodeIfc<BC,LC>> listFactory)
          This constructor sets the factories for self.
DefaultBranchNode(ListFactoryIfc<NodeIfc<BC,LC>> listFactory, NodeFactoryIfc<BC,LC> nodeFactory)
          This constructor sets the factories for self.
DefaultBranchNode(NodeFactoryIfc<BC,LC> nodeFactory)
          This constructor sets the factories for self.
 
Method Summary
 void accept(NodeVisitorIfc<BC,LC> nodeVisitor)
          Allows visitor to perform operations on self.
 BranchNodeIfc<BC,LC> appendNewBranch(BC branchContext)
          Append a new child branch node.
 LeafNodeIfc<BC,LC> appendNewLeaf(LC leafContext)
          Append a new child leaf node.
 java.util.Collection<NodeIfc<BC,LC>> getChildren()
          Return the children of self.
 BC getContext()
          Returns the context.
 BranchNodeIfc<BC,LC> insertNewBranch(BC branchContext, int index)
          Insert a new child branch node at index.
 LeafNodeIfc<BC,LC> insertNewLeaf(LC leafContext, int index)
          Insert a new child leaf node at index.
 BranchNodeIfc<BC,LC> prependNewBranch(BC branchContext)
          Prepend a new child branch node.
 LeafNodeIfc<BC,LC> prependNewLeaf(LC leafContext)
          Prepend a new child leaf node.
 NodeIfc<BC,LC> removeNode(int index)
          Remove the child node at index.
 boolean removeNode(NodeIfc<BC,LC> node)
          Remove a child node.
 void setContext(BC context)
          Sets the context.
 java.lang.String toString()
          Returns the string representation of self.
 java.lang.String toString(java.lang.String prepend)
          Returns a string representation of self prepending prepend to each line.
 
Methods inherited from class org.jplate.foundation.node.impl.AbstractNode
getParent, getSource, setSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jplate.foundation.node.NodeIfc
getParent, getSource, setSource
 

Field Detail

serialVersionUID

private static final long serialVersionUID
For serialization purposes.

See Also:
Constant Field Values

NODE_FACTORY_IS_NULL_MSG

public static final java.lang.String NODE_FACTORY_IS_NULL_MSG
Denotes the node factory is null.

See Also:
Constant Field Values

LIST_FACTORY_IS_NULL_MSG

public static final java.lang.String LIST_FACTORY_IS_NULL_MSG
Denotes the list factory is null.

See Also:
Constant Field Values

_log

private final transient org.apache.commons.logging.Log _log
Used for logging.


_childList

private final java.util.List<NodeIfc<BC,LC>> _childList
Child nodes.


_nodeFactory

private final transient NodeFactoryIfc<BC,LC> _nodeFactory
Used to create child branch nodes.


_context

private BC _context
Self's context.

Constructor Detail

DefaultBranchNode

public DefaultBranchNode(BranchNodeIfc<BC,LC> parent,
                         ListFactoryIfc<NodeIfc<BC,LC>> listFactory,
                         NodeFactoryIfc<BC,LC> nodeFactory)
This constructor sets the parent, context and factories for self.

Parameters:
parent - The parent of self. It can be null (meaning no parent).
listFactory - The factory that can create a List for use to hold child nodes.
nodeFactory - The factory that can create child leaf nodes.
Throws:
java.lang.IllegalArgumentException - If listFactory, or nodeFactory, are null.
See Also:
List, ContextFactoryIfc, FactoryIfc

DefaultBranchNode

public DefaultBranchNode(ListFactoryIfc<NodeIfc<BC,LC>> listFactory,
                         NodeFactoryIfc<BC,LC> nodeFactory)
This constructor sets the factories for self.

Parameters:
listFactory - The factory that can create a List for use to hold child nodes.
nodeFactory - The factory that can create child leaf nodes.
Throws:
java.lang.IllegalArgumentException - If listFactory, or nodeFactory, are null.
See Also:
List

DefaultBranchNode

public DefaultBranchNode(ListFactoryIfc<NodeIfc<BC,LC>> listFactory)
This constructor sets the factories for self.

Parameters:
listFactory - The factory that can create a List for use to hold child nodes.
Throws:
java.lang.IllegalArgumentException - If listFactory, is null.

DefaultBranchNode

public DefaultBranchNode(NodeFactoryIfc<BC,LC> nodeFactory)
This constructor sets the factories for self.

Parameters:
nodeFactory - The factory that can create child leaf nodes.
Throws:
java.lang.IllegalArgumentException - If nodeFactory, is null.

DefaultBranchNode

public DefaultBranchNode(BranchNodeIfc<BC,LC> parent)
This constructor sets the parent.

Parameters:
parent - is the parent branch node of self.

DefaultBranchNode

public DefaultBranchNode()
Default constructor.

Method Detail

toString

public java.lang.String toString()
Returns the string representation of self.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of self.

toString

public java.lang.String toString(java.lang.String prepend)
Returns a string representation of self prepending prepend to each line.

Specified by:
toString in interface FormattableIfc
Parameters:
prepend - The text to prepend to each line as defined in the return value.
Returns:
A string representation of self who has prepend prepended to each line.

accept

public void accept(NodeVisitorIfc<BC,LC> nodeVisitor)
            throws VisitException
Allows visitor to perform operations on self.

Specified by:
accept in interface VisitableIfc<NodeVisitorIfc<BC,LC>>
Parameters:
nodeVisitor - The object who will perform an operation on self.
Throws:
VisitException - If any problems arise performing an operation on self.

setContext

public void setContext(BC context)
Sets the context.

Specified by:
setContext in interface BranchNodeIfc<BC,LC>
Parameters:
context - The new context.

getContext

public BC getContext()
Returns the context.

Specified by:
getContext in interface BranchNodeIfc<BC,LC>
Returns:
The context.

appendNewLeaf

public LeafNodeIfc<BC,LC> appendNewLeaf(LC leafContext)
Append a new child leaf node.

Specified by:
appendNewLeaf in interface BranchNodeIfc<BC,LC>
Parameters:
leafContext - The data stored in the return value.
Returns:
The newly appended child leaf node.

appendNewBranch

public BranchNodeIfc<BC,LC> appendNewBranch(BC branchContext)
Append a new child branch node.

Specified by:
appendNewBranch in interface BranchNodeIfc<BC,LC>
Parameters:
branchContext - The data stored in the return value.
Returns:
The newly appended branch node.

prependNewLeaf

public LeafNodeIfc<BC,LC> prependNewLeaf(LC leafContext)
Prepend a new child leaf node.

Specified by:
prependNewLeaf in interface BranchNodeIfc<BC,LC>
Parameters:
leafContext - The data stored in the return value.
Returns:
The newly prepended child leaf node.

prependNewBranch

public BranchNodeIfc<BC,LC> prependNewBranch(BC branchContext)
Prepend a new child branch node.

Specified by:
prependNewBranch in interface BranchNodeIfc<BC,LC>
Parameters:
branchContext - The data stored in the return value.
Returns:
the newly prepended child branch node.

insertNewLeaf

public LeafNodeIfc<BC,LC> insertNewLeaf(LC leafContext,
                                        int index)
Insert a new child leaf node at index.

Specified by:
insertNewLeaf in interface BranchNodeIfc<BC,LC>
Parameters:
leafContext - The data stored in the return value.
index - The index for which the return value will be inserted.
Returns:
the newly inserted child leaf node.

insertNewBranch

public BranchNodeIfc<BC,LC> insertNewBranch(BC branchContext,
                                            int index)
Insert a new child branch node at index.

Specified by:
insertNewBranch in interface BranchNodeIfc<BC,LC>
Parameters:
branchContext - The data stored in the return value.
index - The index for which the return value will be inserted.
Returns:
the newly prepended child branch node.

removeNode

public NodeIfc<BC,LC> removeNode(int index)
Remove the child node at index.

Specified by:
removeNode in interface BranchNodeIfc<BC,LC>
Parameters:
index - The index of the child node to remove.
Returns:
The removed node.

removeNode

public boolean removeNode(NodeIfc<BC,LC> node)
Remove a child node.

Specified by:
removeNode in interface BranchNodeIfc<BC,LC>
Parameters:
node - The child node to remove.
Returns:
true if node was found and removed false if not.

getChildren

public java.util.Collection<NodeIfc<BC,LC>> getChildren()
Return the children of self. Implementations are encouraged to return an Collections.unmodifiableCollection(java.util.Collection).

Specified by:
getChildren in interface BranchNodeIfc<BC,LC>
Returns:
The children nodes as a Collection.