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 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 Details

  • 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 needed
      context - The current overview context
      validator - An optional validator
      nameGenerator - A name generator to use for node name and title generation
  • Method Details

    • 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:
    • 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:
    • postValidateFolder

      public void postValidateFolder(Node folderNode, Node parentNode)