2.17.2: 2011-06-17

net.sf.basedb.util.overview.loader
Class BasicItemNodeLoaderFactory

java.lang.Object
  extended by net.sf.basedb.util.overview.loader.BasicItemNodeLoaderFactory
All Implemented Interfaces:
NodeLoaderFactory<BasicItem,Object>

public class BasicItemNodeLoaderFactory
extends Object
implements NodeLoaderFactory<BasicItem,Object>

Node loader factory implementation for BasicItem node loaders. The key used in createNodeLoader(Object) should normally be an Item object.

Version:
2.10
Author:
Nicklas
Last modified
$Date: 2010-11-18 08:26:30 +0100 (Thu, 18 Nov 2010) $

Field Summary
private  boolean autoLoadChildren
           
private static boolean debug
           
private  Map<Object,Class<? extends NodeLoader<? extends BasicItem>>> loaders
           
private static Logger log
           
private  boolean useNullLoader
           
 
Constructor Summary
BasicItemNodeLoaderFactory()
          Creates a new factory.
 
Method Summary
 NodeLoader<? extends BasicItem> createNodeLoader(Object key)
          Create a new node loader for loading nodes for the specified item type.
 boolean isAutoLoadingChildren()
          Get the auto load children setting.
protected  void registerCheckedNodeLoader(Object key, Class<? extends NodeLoader<? extends BasicItem>> loaderClass)
          Register a node loader implementation that you are sure fulfills the requirements.
protected  void registerDefaultNodeLoaders()
          Registers default item node loaders from BioSource to Experiment, etc.
 void registerNodeLoader(Object key, Class<? extends NodeLoader<? extends BasicItem>> loaderClass)
          Register a node loader implementation.
 void setAutoLoadChildren(boolean autoLoadChildren)
          Set a flag that determines if the factory should create node loaders that automatically loads child nodes or not.
 void setUseNullLoaderIfNotFound(boolean useNullLoader)
          Set a flag that determines if a NullNodeLoader should be used or if an ItemNotFoundException should be thrown if no registered node loader is found for a specific key.
 boolean useNullLoaderIfNotFound()
          Get the null loader setting.
 
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

loaders

private final Map<Object,Class<? extends NodeLoader<? extends BasicItem>>> loaders

autoLoadChildren

private boolean autoLoadChildren

useNullLoader

private boolean useNullLoader
Constructor Detail

BasicItemNodeLoaderFactory

public BasicItemNodeLoaderFactory()
Creates a new factory.

Method Detail

createNodeLoader

public NodeLoader<? extends BasicItem> createNodeLoader(Object key)
Create a new node loader for loading nodes for the specified item type. If no loader has been registered for the given item type, a NullNodeLoader is returned or an exception is thrown depending on the useNullLoaderIfNotFound() option.

Specified by:
createNodeLoader in interface NodeLoaderFactory<BasicItem,Object>
Parameters:
key - An Item object
Returns:
A node loader object
Throws:
ItemNotFoundException - If no node loader is found and the useNullLoaderIfNotFound() setting is false

registerNodeLoader

public void registerNodeLoader(Object key,
                               Class<? extends NodeLoader<? extends BasicItem>> loaderClass)
                        throws NoSuchMethodException,
                               ClassCastException
Register a node loader implementation. The implementation must have a public no-argument constructor. The given class is checked with ClassUtil.checkAndLoadClass(ClassLoader, String, boolean, Class...)

Parameters:
key - The item type the node loader handles
loaderClass - The class name of a class that implements NodeLoader, or null to unregister a node loader
Throws:
NoSuchMethodException - If the given class has no public no-argument constructor
ClassCastException - If the given class doesn't implement the NodeLoader interface

registerCheckedNodeLoader

protected void registerCheckedNodeLoader(Object key,
                                         Class<? extends NodeLoader<? extends BasicItem>> loaderClass)
Register a node loader implementation that you are sure fulfills the requirements. Eg. it must have a public no-argument constructor and implement the NodeLoader interface.

See Also:
registerNodeLoader(Object, Class)

setAutoLoadChildren

public void setAutoLoadChildren(boolean autoLoadChildren)
Set a flag that determines if the factory should create node loaders that automatically loads child nodes or not. If this flag has been set this factory will wrap the node loaders with a AutoChildNodeLoader.

This will generate a recursive pattern if the used node loader:

Parameters:
autoLoadChildren - TRUE to create node loaders that automatically loads children, FALSE otherwise

isAutoLoadingChildren

public boolean isAutoLoadingChildren()
Get the auto load children setting.

Returns:
TRUE if child nodes are automatically loaded, FALSE if not

useNullLoaderIfNotFound

public boolean useNullLoaderIfNotFound()
Get the null loader setting.

See Also:
setUseNullLoaderIfNotFound(boolean)

setUseNullLoaderIfNotFound

public void setUseNullLoaderIfNotFound(boolean useNullLoader)
Set a flag that determines if a NullNodeLoader should be used or if an ItemNotFoundException should be thrown if no registered node loader is found for a specific key.

Parameters:
useNullLoader - TRUE to use a NullNodeLoader, FALSE to throw an exception

registerDefaultNodeLoaders

protected void registerDefaultNodeLoaders()
Registers default item node loaders from BioSource to Experiment, etc.


2.17.2: 2011-06-17