2.17.2: 2011-06-17

net.sf.basedb.util.overview.validator
Class BasicItemNodeValidatorFactory

java.lang.Object
  extended by net.sf.basedb.util.overview.validator.BasicItemNodeValidatorFactory
All Implemented Interfaces:
NodeValidatorFactory<BasicItem,Object>

public class BasicItemNodeValidatorFactory
extends Object
implements NodeValidatorFactory<BasicItem,Object>

Node validator factory implementation for BasicItem node validators. The key used in createNodeValidator(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 disabled
           
private  boolean useNullValidator
           
private  Map<Object,Class<? extends NodeValidator<? extends BasicItem>>> validators
           
 
Constructor Summary
BasicItemNodeValidatorFactory()
          Creates a new factory.
 
Method Summary
 NodeValidator<? extends BasicItem> createNodeValidator(Object key)
          Create a new node validator that can validate nodes with items of the specified item type.
 boolean isDisabled()
          Check if node validation has been disabled.
protected  void registerCheckedNodeValidator(Object key, Class<? extends NodeValidator<? extends BasicItem>> validatorClass)
          Register a node loader implementation that you are sure fulfills the requirements.
protected  void registerDefaultNodeValidators()
          Registers default item node validators from BioSource to Experiment, etc.
 void registerNodeValidator(Item key, Class<? extends NodeValidator<? extends BasicItem>> validatorClass)
          Register a node validator implementation.
 void setDisabled(boolean disabled)
          Disable/enabled node validation programmatically.
 void setUsNullValidatorIfNotFound(boolean useNullValidator)
          Set a flag that determines if a NullNodeValidator should be used or if an ItemNotFoundException should be thrown if no registered node validator is found for a specific key.
 boolean useNullValidatorIfNotFound()
          Get the null validator setting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

validators

private final Map<Object,Class<? extends NodeValidator<? extends BasicItem>>> validators

useNullValidator

private boolean useNullValidator

disabled

private boolean disabled
Constructor Detail

BasicItemNodeValidatorFactory

public BasicItemNodeValidatorFactory()
Creates a new factory.

Method Detail

isDisabled

public boolean isDisabled()
Description copied from interface: NodeValidatorFactory
Check if node validation has been disabled.

Specified by:
isDisabled in interface NodeValidatorFactory<BasicItem,Object>
Returns:
TRUE if validation has been disabled

setDisabled

public void setDisabled(boolean disabled)
Description copied from interface: NodeValidatorFactory
Disable/enabled node validation programmatically. When a node validator factory is disabled the NodeValidatorFactory.createNodeValidator(Object) should return null or a NullNodeValidator for all requests.

Specified by:
setDisabled in interface NodeValidatorFactory<BasicItem,Object>
Parameters:
disabled - TRUE to disable node validation

createNodeValidator

public NodeValidator<? extends BasicItem> createNodeValidator(Object key)
Create a new node validator that can validate nodes with items of the specified item type. If no validator has been registered for the given item type, a NullNodeValidator is returned or an exception is thrown depending on the useNullValidatorIfNotFound() option.

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

useNullValidatorIfNotFound

public boolean useNullValidatorIfNotFound()
Get the null validator setting.

See Also:
setUsNullValidatorIfNotFound(boolean)

setUsNullValidatorIfNotFound

public void setUsNullValidatorIfNotFound(boolean useNullValidator)
Set a flag that determines if a NullNodeValidator should be used or if an ItemNotFoundException should be thrown if no registered node validator is found for a specific key.

Parameters:
useNullValidator - TRUE to use an NullNodeValidator, FALSE to throw an exception

registerNodeValidator

public void registerNodeValidator(Item key,
                                  Class<? extends NodeValidator<? extends BasicItem>> validatorClass)
                           throws NoSuchMethodException,
                                  ClassCastException
Register a node validator 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 validator handles
validatorClass - The class name of a class that implements NodeValidator, or null to unregister an existig validator
Throws:
NoSuchMethodException - If the given class has no public no-argument constructor
ClassCastException - If the given class doesn't implement the NodeValidator interface

registerCheckedNodeValidator

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

See Also:
registerNodeValidator(Item, Class)

registerDefaultNodeValidators

protected void registerDefaultNodeValidators()
Registers default item node validators from BioSource to Experiment, etc.


2.17.2: 2011-06-17