Package net.sf.basedb.util.overview.node
Class NodeFactory<I extends BasicItem>
- java.lang.Object
-
- 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 aNodeValidator
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 optionalNodeCache
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
- Last modified
- $Date: 2014-04-09 14:21:20 +0200 (on, 09 apr 2014) $
-
-
Field Summary
Fields Modifier and Type Field Description private OverviewContext
context
private DbControl
dc
private static boolean
debug
private static org.slf4j.Logger
log
private NodeNameGenerator<? super I>
nameGenerator
private NodeValidator<? super I>
validator
-
Constructor Summary
Constructors Constructor Description NodeFactory(DbControl dc, OverviewContext context, NodeValidator<? super I> validator, NodeNameGenerator<? super I> nameGenerator)
Create a node factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
-
-
-
Field Detail
-
log
private static final org.slf4j.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 neededcontext
- The current overview contextvalidator
- An optional validatornameGenerator
- 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'sNodeValidator.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'sNodeValidator.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'sNodeValidator.preValidate(DbControl, OverviewContext, Object, Node)
method returns TRUE.- Parameters:
item
- The item to attach to the nodecacheKey
- An optional cache keyparentNode
- The parent nodedirection
- 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 aDirectionalCacheKey
since the loading direction will affect the children of a node.- Parameters:
cacheKey
- The cache key to use for node lookupparentNode
- The node that should be the parent of the cloned nodedirection
- 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 keynode
- The node to storedirection
- The direction we are loading child nodes in- See Also:
OverviewContext.getNodeCache()
-
-