org.progeeks.tool.gen
Class ConditionalGenerator

java.lang.Object
  extended by org.progeeks.tool.gen.BaseDataGenerator
      extended by org.progeeks.tool.gen.ConditionalGenerator
All Implemented Interfaces:
DataGenerator

public class ConditionalGenerator
extends BaseDataGenerator

A DataGenerator that selects a sub-generator to generate data based on a set of conditions. The generator takes a map where both the keys and the values are DataGenerators. The DataGenerator.isDataValid(Object, DataGeneratorContext) method of the key DataGenerators is called on the interestProperty property from the proper object in the passed context (or the object itself if interestProperty is not set). If isDataValid returns true, then the DataGenerator.generateData(DataGeneratorContext) method of the value DataGenerator is invoked. A default generator can be set if no conditions match.

Version:
$Revision: 1.5 $
Author:
esword

Field Summary
protected static Log log
           
 
Fields inherited from class org.progeeks.tool.gen.BaseDataGenerator
allowNull, nullPercentage
 
Constructor Summary
ConditionalGenerator()
           
 
Method Summary
protected  java.lang.Object generateRealData(DataGeneratorContext context)
          Iterate over the keys in the conditionCheckers.
 java.util.Map getConditionCheckers()
           
 DataGenerator getDefaultGenerator()
           
 int getInterestLevel()
           
 java.lang.String getInterestProperty()
           
protected  java.lang.Object getReferenceObject(DataGeneratorContext context)
          Gets the appropriate reference from the context, and gets the value for the interestProperty if there is one.
 void setConditionCheckers(java.util.Map conditionCheckers)
           
 void setDefaultGenerator(DataGenerator defaultGenerator)
          Generator to be invoked if none of the conditions evaluate to true.
 void setInterestLevel(int interestLevel)
          The level in the passed context to use as the reference for the conditionCheckers.
 void setInterestProperty(java.lang.String interestProperty)
          The property within the referenced object that is to be evaluated by the conditionCheckers.
protected  boolean testData(java.lang.Object testItem, DataGeneratorContext context)
          Uses the same process as generateRealData for moving through the conditionCheckers and then invokes isDataValid on the value generator associated with whatever conditionChecker was matched.
 
Methods inherited from class org.progeeks.tool.gen.BaseDataGenerator
generateData, getAllowNull, getDataClass, getDataClazz, getEnforceResolvable, getNullPercentage, isDataValid, setAllowNull, setDataClass, setEnforceResolvable, setNullPercentage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final Log log
Constructor Detail

ConditionalGenerator

public ConditionalGenerator()
Method Detail

generateRealData

protected java.lang.Object generateRealData(DataGeneratorContext context)
Iterate over the keys in the conditionCheckers. If one returns true, use the associated value DataGenerator to generate the data.

Specified by:
generateRealData in class BaseDataGenerator

testData

protected boolean testData(java.lang.Object testItem,
                           DataGeneratorContext context)
Uses the same process as generateRealData for moving through the conditionCheckers and then invokes isDataValid on the value generator associated with whatever conditionChecker was matched.

Specified by:
testData in class BaseDataGenerator

getReferenceObject

protected java.lang.Object getReferenceObject(DataGeneratorContext context)
Gets the appropriate reference from the context, and gets the value for the interestProperty if there is one.

Parameters:
context -

getConditionCheckers

public java.util.Map getConditionCheckers()
Returns:
Returns the conditionCheckers.

getInterestLevel

public int getInterestLevel()
Returns:
Returns the interestLevel.

getInterestProperty

public java.lang.String getInterestProperty()
Returns:
Returns the interestProperty.

setConditionCheckers

public void setConditionCheckers(java.util.Map conditionCheckers)
Parameters:
conditionCheckers - The conditionCheckers to set. Should be a LinkedHashMap or other implementation with a logical order of iteration through the keys.

setInterestLevel

public void setInterestLevel(int interestLevel)
The level in the passed context to use as the reference for the conditionCheckers. Defaults to 0 (the last object to be added to the context).

Parameters:
interestLevel - The interestLevel to set.

setInterestProperty

public void setInterestProperty(java.lang.String interestProperty)
The property within the referenced object that is to be evaluated by the conditionCheckers. If this is not set, the referenced object itself will be evaluated. This is useful if multiple properties must meet a condition. The supplied conditionChecker generators can themselves be ComplexObjectGenerator with sub-generators that evaluate different properties.

Parameters:
interestProperty - The interestProperty to set.

getDefaultGenerator

public DataGenerator getDefaultGenerator()
Returns:
Returns the defaultGenerator.

setDefaultGenerator

public void setDefaultGenerator(DataGenerator defaultGenerator)
Generator to be invoked if none of the conditions evaluate to true.

Parameters:
defaultGenerator - The defaultGenerator to set.


Copyright © 2002-2003 Paul Speed. All Rights Reserved.