Package net.sf.basedb.util.overview.node
Class NodeFactory<I extends BasicItem>
java.lang.Object
net.sf.basedb.util.overview.node.NodeFactory<I>
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
- Last modified
- $Date: 2014-04-09 14:21:20 +0200 (on, 09 apr 2014) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate OverviewContext
private DbControl
private static final boolean
private static final Logger
private NodeNameGenerator<? super I>
private NodeValidator<? super I>
-
Constructor Summary
ConstructorDescriptionNodeFactory
(DbControl dc, OverviewContext context, NodeValidator<? super I> validator, NodeNameGenerator<? super I> nameGenerator) Create a node factory. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.createDeniedNode
(Node parentNode) Create a node representing an item that the logged in user is denied to access.createMissingNode
(Node parentNode) Create a node representing a missing item.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>
Get the node validator that is used by this factory.void
postValidateFolder
(Node folderNode, Node parentNode)
-
Field Details
-
log
-
debug
private static final boolean debug -
dc
-
context
-
validator
-
nameGenerator
-
-
Constructor Details
-
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 Details
-
getNodeValidator
Get the node validator that is used by this factory.- Returns:
- A node validator or null if no validator is used
-
createMissingNode
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
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
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
-
cloneCachedNode
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:
-
cacheNewNode
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:
-
postValidateFolder
-