org.progeeks.tool.gen
Class BaseDataGenerator

java.lang.Object
  extended by org.progeeks.tool.gen.BaseDataGenerator
All Implemented Interfaces:
DataGenerator
Direct Known Subclasses:
BooleanGenerator, CollectionGenerator, ComplexObjectGenerator, ConditionalGenerator, DateGenerator, EqualsGenerator, GroupMemberGenerator, MapGenerator, NumberGenerator, StringGenerator, StringListGenerator

public abstract class BaseDataGenerator
extends java.lang.Object
implements DataGenerator

Base class for other data generators. Handles generation of and testing for nulls when null is an allowed value. Also checks that objects passed to isDataValid are of the same type as dataClass if dataClass can be resolved into a regular class (i.e. it's not a MetaClass).

Version:
$Revision: 1.6 $
Author:
esword

Field Summary
protected  boolean allowNull
           
protected static Log log
           
protected  float nullPercentage
           
 
Constructor Summary
BaseDataGenerator()
           
 
Method Summary
 java.lang.Object generateData(DataGeneratorContext context)
          Handles null generation case.
protected abstract  java.lang.Object generateRealData(DataGeneratorContext context)
          Left for sub-classes.
 boolean getAllowNull()
           
 java.lang.String getDataClass()
           
 java.lang.Class getDataClazz()
           
protected  boolean getEnforceResolvable()
           
 float getNullPercentage()
           
 boolean isDataValid(java.lang.Object testItem, DataGeneratorContext context)
          Handles check for if testItem is null and if that is allowed.
 void setAllowNull(boolean allowNull)
           
 void setDataClass(java.lang.String dataClass)
          The full java class name or a MetaClass name of the objects to create
protected  void setEnforceResolvable(boolean enforceKnownClass)
          Enforce that the dataClassName should be resolvable (i.e. is a known Java class).
 void setNullPercentage(float nullPercentage)
           
protected abstract  boolean testData(java.lang.Object testItem, DataGeneratorContext context)
          Left for sub-classes.
 
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

allowNull

protected boolean allowNull

nullPercentage

protected float nullPercentage
Constructor Detail

BaseDataGenerator

public BaseDataGenerator()
Method Detail

generateData

public java.lang.Object generateData(DataGeneratorContext context)
Handles null generation case. If not null, invokes generateRealData(DataGeneratorContext).

Specified by:
generateData in interface DataGenerator

generateRealData

protected abstract java.lang.Object generateRealData(DataGeneratorContext context)
Left for sub-classes. Subclasses should usually not return null from this.


isDataValid

public boolean isDataValid(java.lang.Object testItem,
                           DataGeneratorContext context)
Handles check for if testItem is null and if that is allowed. Also check if it is of the proper class (if possible). If those succeed, invokes sub-classes testData.

Specified by:
isDataValid in interface DataGenerator

testData

protected abstract boolean testData(java.lang.Object testItem,
                                    DataGeneratorContext context)
Left for sub-classes. Subclasses do not have to check for null.


getDataClass

public java.lang.String getDataClass()
Specified by:
getDataClass in interface DataGenerator
Returns:
Returns the dataClass.

setDataClass

public void setDataClass(java.lang.String dataClass)
The full java class name or a MetaClass name of the objects to create

Specified by:
setDataClass in interface DataGenerator
Parameters:
dataClass - The dataClass to set.

getDataClazz

public java.lang.Class getDataClazz()

getAllowNull

public boolean getAllowNull()
Specified by:
getAllowNull in interface DataGenerator
Returns:
Returns the allowNull.

setAllowNull

public void setAllowNull(boolean allowNull)
Specified by:
setAllowNull in interface DataGenerator
Parameters:
allowNull - The allowNull to set.

getNullPercentage

public float getNullPercentage()
Specified by:
getNullPercentage in interface DataGenerator
Returns:
Returns the nullPercentage.

setNullPercentage

public void setNullPercentage(float nullPercentage)
Specified by:
setNullPercentage in interface DataGenerator
Parameters:
nullPercentage - The nullPercentage to set.

getEnforceResolvable

protected boolean getEnforceResolvable()

setEnforceResolvable

protected void setEnforceResolvable(boolean enforceKnownClass)
Enforce that the dataClassName should be resolvable (i.e. is a known Java class). Subclasses can set in the constructor. Default is true

Parameters:
enforceKnownClass -


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