2.17.2: 2011-06-17

net.sf.basedb.util.overview.node
Class NodeFactory<I extends BasicItem>

java.lang.Object
  extended by net.sf.basedb.util.overview.node.NodeFactory<I>

public class NodeFactory<I extends BasicItem>
extends Object

A node factory is responsible for creating item-type nodes. The primary function of a node factory is to interface with a NodeValidator to actually decide if a node should be created or not for a given item (which may be missing or the current user may be denied access).

Another function is to interface with the current OverviewContext and it's optional NodeCache so that we don't have to use resources for re-loading a deep sub-tree starting with an item that has already been loaded in another branch of the tree.

Version:
2.10
Author:
Nicklas
This class/package is not part of the Public API
This class is still being developed. It may change without notice in future versions of BASE.
Last modified
$Date: 2009-02-18 14:26:21 +0100 (Wed, 18 Feb 2009) $

Field Summary
private  OverviewContext context
           
private  DbControl dc
           
private static boolean debug
           
private static Logger log
           
private  NodeNameGenerator<? super I> nameGenerator
           
private  NodeValidator<? super I> validator
           
 
Constructor Summary
NodeFactory(DbControl dc, OverviewContext context, NodeValidator<? super I> validator, NodeNameGenerator<? super I> nameGenerator)
          Create a node factory.
 
Method Summary
protected  void cacheNewNode(Object cacheKey, Node node, ChildNodeDirection direction)
          Store a node in the node cache if the current overview context supports caching.
protected  Node cloneCachedNode(Object cacheKey, Node parentNode, ChildNodeDirection direction)
          Clones a cached node if the current context supports caching and another node with the given cache key already exists.
 Node createDeniedNode(Node parentNode)
          Create a node representing an item that the logged in user is denied to access.
 Node createMissingNode(Node parentNode)
          Create a node representing a missing item.
 Node createNode(I item, Object cacheKey, Node parentNode, ChildNodeDirection direction)
          Create a node representing an existing item.
private  Node createNode(I item, String name, String title, Object cacheKey, Node parentNode, ChildNodeDirection direction)
           
 NodeValidator<? super I> getNodeValidator()
          Get the node validator that is used by this factory.
 void postValidateFolder(Node folderNode, Node parentNode)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Logger log

debug

private static final boolean debug

dc

private DbControl dc

context

private OverviewContext context

validator

private NodeValidator<? super I extends BasicItem> validator

nameGenerator

private NodeNameGenerator<? super I extends BasicItem> nameGenerator
Constructor Detail

NodeFactory

public NodeFactory(DbControl dc,
                   OverviewContext context,
                   NodeValidator<? super I> validator,
                   NodeNameGenerator<? super I> nameGenerator)
Create a node factory. If a validator is specified it will be used to determine if a node should be created or not. Without a validator nodes are not created for missing items, only for existing item (including if access is denied)

Parameters:
dc - A DbControl to use if database access is needed
context - The current overview context
validator - An optional validator
nameGenerator - A name generator to use for node name and title generation
Method Detail

getNodeValidator

public NodeValidator<? super I> getNodeValidator()
Get the node validator that is used by this factory.

Returns:
A node validator or null if no validator is used

createMissingNode

public Node createMissingNode(Node parentNode)
Create a node representing a missing item. A node is only created if a validator is present and it's NodeValidator.preMissingItem(DbControl, OverviewContext, Node) method returns TRUE.

Parameters:
parentNode - The parent node
Returns:
The new node, or null if no node was created

createDeniedNode

public Node createDeniedNode(Node parentNode)
Create a node representing an item that the logged in user is denied to access. A node is created if no validator is present or if the validator's NodeValidator.preDeniedItem(DbControl, OverviewContext, Node) method returns TRUE.

Parameters:
parentNode - The parent node
Returns:
The new node, or null if no node was created

createNode

public Node createNode(I item,
                       Object cacheKey,
                       Node parentNode,
                       ChildNodeDirection direction)
Create a node representing an existing item. A node is created if no validator is present or if the validator's NodeValidator.preValidate(DbControl, OverviewContext, Object, Node) method returns TRUE.

Parameters:
item - The item to attach to the node
cacheKey - An optional cache key
parentNode - The parent node
direction - The direction to use when loading the node's children
Returns:
The new node, or null if no node was created

createNode

private Node createNode(I item,
                        String name,
                        String title,
                        Object cacheKey,
                        Node parentNode,
                        ChildNodeDirection direction)

cloneCachedNode

protected Node cloneCachedNode(Object cacheKey,
                               Node parentNode,
                               ChildNodeDirection direction)
Clones a cached node if the current context supports caching and another node with the given cache key already exists. This method wraps the given cacheKey with a DirectionalCacheKey since the loading direction will affect the children of a node.

Parameters:
cacheKey - The cache key to use for node lookup
parentNode - The node that should be the parent of the cloned node
direction - The direction we are loading child nodes in
Returns:
The new (cloned) node, or null if no cached node was found
See Also:
OverviewContext.getNodeCache()

cacheNewNode

protected void cacheNewNode(Object cacheKey,
                            Node node,
                            ChildNodeDirection direction)
Store a node in the node cache if the current overview context supports caching.

Parameters:
cacheKey - The cache key
node - The node to store
direction - The direction we are loading child nodes in
See Also:
OverviewContext.getNodeCache()

postValidateFolder

public void postValidateFolder(Node folderNode,
                               Node parentNode)

2.17.2: 2011-06-17