org.specrunner.plugins.core.objects
Class AbstractPluginObject

java.lang.Object
  extended by org.specrunner.parameters.core.ParameterHolder
      extended by org.specrunner.plugins.core.AbstractPlugin
          extended by org.specrunner.plugins.core.AbstractPluginNamed
              extended by org.specrunner.plugins.core.AbstractPluginScoped
                  extended by org.specrunner.plugins.core.AbstractPluginTable
                      extended by org.specrunner.plugins.core.objects.AbstractPluginObject
All Implemented Interfaces:
IParameterHolder, IActionType, IParalelPlugin, IPlugin, ISleepPlugin, ITestPlugin, ITimedPlugin, IWaitPlugin
Direct Known Subclasses:
AbstractPluginObjectSelect, PluginInsert

public abstract class AbstractPluginObject
extends AbstractPluginTable

Generic object plugin. To write object plugins override method isMapped() and action(...). i.e. SpecRunner-Hibernate3 extends the object manipulation to save/update/delete data using Hibernate3 infra-structure.

Author:
Thiago Santos

Nested Class Summary
static class AbstractPluginObject.Field
          Hold column information.
 
Field Summary
protected  String creator
          Object creator name.
protected  IObjectCreator creatorInstance
          Object creator instance.
protected  List<AbstractPluginObject.Field> fields
          List of fields.
protected  Map<String,AbstractPluginObject.Field> generic
          List of generic definition fields.
protected  Map<String,Object> instances
          Mapping of identifiers to object instances.
protected  Map<String,String> keysBefore
          Mapping of key before processing to the ones after processing.
protected  String mapping
          The map of generic fields to be used as reference.
protected  String reference
          The identification fields.
protected  List<String> references
          The identification fields list.
protected  String separator
          Separator of identification attributes.
protected  String type
          Object class name.
protected  Class<?> typeInstance
          Object class.
 
Fields inherited from class org.specrunner.plugins.core.AbstractPlugin
FEATURE_CONDITION, FEATURE_NORMALIZED, FEATURE_SLEEP, FEATURE_THREADSAFE, FEATURE_TIMEOUT, FEATURE_WAIT
 
Constructor Summary
AbstractPluginObject()
           
 
Method Summary
protected abstract  void action(IContext context, Object instance, RowAdapter row, IResultSet result)
          This method can be and should be overridden to perform save, comparison, etc for updates.
protected  Object create(RowAdapter row)
          Create the object based on a row.
 void doEnd(IContext context, IResultSet result, TableAdapter table)
          Perform an ending action.
 String getCreator()
          Returns the object creator of embeddable objects.
 IObjectCreator getCreatorInstance()
          Object creator type.
 String getMapping()
          Return the map of field information.
 Object getObject(String key)
          Given a key, returns the corresponding object instance.
 String getReference()
          Sets the attribute which represents the keys of the entity.
 String getSeparator()
          Gets the string used to separate fields of reference. i.e. if reference='id,name' and separator='/', the object instance corresponding to a given line will be 'id/name'.
 String getType()
          The object type of the plugin. i.e.
 Class<?> getTypeInstance()
          Gets the corresponding class to type.
 void initialize(IContext context, TableAdapter table)
          Initialize helper.
protected abstract  boolean isMapped()
          Says if the instance show be mapped or not.
protected  void loadFields(IContext context, RowAdapter row, List<AbstractPluginObject.Field> list)
          Load fields based on th tags.
protected  void loadMapping(IContext context, TableAdapter table)
          Load mapping with predefined values.
 String makeKey(Object instance)
          Creates the key to be used for storing/recovering object information.
 void mapObject(Object instance, String keyBefore, String keyAfter)
          Maps the object using the keys before and after Hibernate saving.
 AbstractPluginObject merge(AbstractPluginObject old)
          Merge to equivalent plugins.
protected  boolean populate(Object instance, IContext context, RowAdapter row, IResultSet result)
          Populate the object instance with row information.
protected  void processLine(IContext context, RowAdapter row, IResultSet result)
          Process a given row.
 Object removeObject(String key)
          Remove an object from mapping.
protected  void setBoolean(Object instance, AbstractPluginObject.Field f, Object value)
          Sets a boolean to a field.
protected  void setChar(Object instance, AbstractPluginObject.Field f, Object value)
          Sets a char to a field.
 void setCreator(String creator)
          Sets the creator class.
 void setCreatorInstance(IObjectCreator creatorInstance)
          Sets the creator.
protected  void setDouble(Object instance, AbstractPluginObject.Field f, Object value)
          Sets a double to a field.
protected  void setEntity(Object instance, AbstractPluginObject.Field f, Object value)
          If there is some plugin of the object type specified in field, use the plugin object version.
protected  void setFloat(Object instance, AbstractPluginObject.Field f, Object value)
          Sets a float to a field.
protected  void setInteger(Object instance, AbstractPluginObject.Field f, Object value)
          Sets an integer to a field.
protected  void setLong(Object instance, AbstractPluginObject.Field f, Object value)
          Sets a long to a field.
 void setMapping(String mapping)
          Sets the object mapping.
protected  void setObject(Object instance, AbstractPluginObject.Field f, Object value)
          Sets an object to a field.
protected  void setObjectInformation()
          Set object and/or creator information.
 void setReference(String reference)
          Sets the references.
 void setSeparator(String separator)
          Sets identifier separator.
protected  void setShort(Object instance, AbstractPluginObject.Field f, Object value)
          Sets a short to a field.
 void setType(String type)
          Set the type.
 void setTypeInstance(Class<?> typeInstance)
          Sets the instance type.
protected  void setValue(RowAdapter row, Object instance, AbstractPluginObject.Field f, Object value)
          Set the field with the given value.
 
Methods inherited from class org.specrunner.plugins.core.AbstractPluginTable
doEnd, doStart, doStart, initialize, toString
 
Methods inherited from class org.specrunner.plugins.core.AbstractPluginScoped
getScope, saveGlobal, saveLocal, saveStrict, setScope
 
Methods inherited from class org.specrunner.plugins.core.AbstractPluginNamed
getName, setName
 
Methods inherited from class org.specrunner.plugins.core.AbstractPlugin
copy, getCondition, getConditionModel, getNormalized, getNormalized, getParent, getSleep, getSleepModel, getThreadsafe, getTimeout, getTimeoutModel, getWait, getWaitModel, setCondition, setConditionModel, setNormalized, setParent, setSleep, setSleepModel, setThreadsafe, setTimeout, setTimeoutModel, setWait, setWaitModel
 
Methods inherited from class org.specrunner.parameters.core.ParameterHolder
getParameters, setParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.specrunner.parameters.IParameterHolder
getParameters, setParameters
 
Methods inherited from interface org.specrunner.plugins.IActionType
getActionType
 

Field Detail

type

protected String type
Object class name.


typeInstance

protected Class<?> typeInstance
Object class.


creator

protected String creator
Object creator name.


creatorInstance

protected IObjectCreator creatorInstance
Object creator instance.


reference

protected String reference
The identification fields.


references

protected List<String> references
The identification fields list.


separator

protected String separator
Separator of identification attributes.


mapping

protected String mapping
The map of generic fields to be used as reference.


generic

protected Map<String,AbstractPluginObject.Field> generic
List of generic definition fields.


fields

protected List<AbstractPluginObject.Field> fields
List of fields.


keysBefore

protected Map<String,String> keysBefore
Mapping of key before processing to the ones after processing.


instances

protected Map<String,Object> instances
Mapping of identifiers to object instances.

Constructor Detail

AbstractPluginObject

public AbstractPluginObject()
Method Detail

getType

public String getType()
The object type of the plugin. i.e. type='system.entity.Person'.

Returns:
The type.

setType

public void setType(String type)
Set the type.

Parameters:
type - A new type.

getTypeInstance

public Class<?> getTypeInstance()
Gets the corresponding class to type.

Returns:
The class.

setTypeInstance

public void setTypeInstance(Class<?> typeInstance)
Sets the instance type.

Parameters:
typeInstance - A new type.

getCreator

public String getCreator()
Returns the object creator of embeddable objects.

Returns:
The creator class name.

setCreator

public void setCreator(String creator)
Sets the creator class.

Parameters:
creator - A new creator class name.

getCreatorInstance

public IObjectCreator getCreatorInstance()
Object creator type.

Returns:
The creator instance.

setCreatorInstance

public void setCreatorInstance(IObjectCreator creatorInstance)
Sets the creator.

Parameters:
creatorInstance - A new creator instance.

getReference

public String getReference()
Sets the attribute which represents the keys of the entity. These fields are used to create the instance key. i.e. if reference='id,name' is used, the 'id' attribute and 'name' attribute are used as the object key, separated by 'separator' field.

Returns:
The list of attribute references in the expected order.

setReference

public void setReference(String reference)
Sets the references.

Parameters:
reference - A new reference list.

getSeparator

public String getSeparator()
Gets the string used to separate fields of reference. i.e. if reference='id,name' and separator='/', the object instance corresponding to a given line will be 'id/name'.

Returns:
The keys separator.

setSeparator

public void setSeparator(String separator)
Sets identifier separator.

Parameters:
separator - The separator.

getMapping

public String getMapping()
Return the map of field information. For example, if there is a mapping for object City already defined in a file name '/city.html' or '/city.xml', just add map='/cities.html' to the tag.

Returns:
The mapping.

setMapping

public void setMapping(String mapping)
Sets the object mapping.

Parameters:
mapping - The mapping.

initialize

public void initialize(IContext context,
                       TableAdapter table)
                throws PluginException
Description copied from class: AbstractPluginTable
Initialize helper.

Overrides:
initialize in class AbstractPluginTable
Parameters:
context - The context.
table - The adapter.
Throws:
PluginException - On initialization errors.

loadMapping

protected void loadMapping(IContext context,
                           TableAdapter table)
                    throws PluginException
Load mapping with predefined values.

Parameters:
context - The context.
table - The table.
Throws:
PluginException - On mapping errors.

setObjectInformation

protected void setObjectInformation()
                             throws PluginException
Set object and/or creator information.

Throws:
PluginException - On setting errors.

doEnd

public void doEnd(IContext context,
                  IResultSet result,
                  TableAdapter table)
           throws PluginException
Description copied from class: AbstractPluginTable
Perform an ending action.

Overrides:
doEnd in class AbstractPluginTable
Parameters:
context - The context.
result - The result set.
table - The adapter.
Throws:
PluginException - On plugin errors.

loadFields

protected void loadFields(IContext context,
                          RowAdapter row,
                          List<AbstractPluginObject.Field> list)
                   throws PluginException
Load fields based on th tags.

Parameters:
context - The context.
row - The row.
list - List of fields.
Throws:
PluginException - On load errors.

isMapped

protected abstract boolean isMapped()
Says if the instance show be mapped or not.

Returns:
true, to map, false, otherwise.

processLine

protected void processLine(IContext context,
                           RowAdapter row,
                           IResultSet result)
                    throws Exception
Process a given row.

Parameters:
context - The context.
row - The row.
result - The result set.
Throws:
Exception - On processing errors.

create

protected Object create(RowAdapter row)
                 throws Exception
Create the object based on a row.

Parameters:
row - The row.
Returns:
The object corresponding to the row.
Throws:
Exception - On creation errors.

populate

protected boolean populate(Object instance,
                           IContext context,
                           RowAdapter row,
                           IResultSet result)
                    throws Exception
Populate the object instance with row information.

Parameters:
instance - The object instance.
context - The test context.
row - The row with attribute informations.
result - The result set.
Returns:
The object filled with row information.
Throws:
Exception - On population errors.

setValue

protected void setValue(RowAdapter row,
                        Object instance,
                        AbstractPluginObject.Field f,
                        Object value)
                 throws Exception
Set the field with the given value.

Parameters:
row - The row corresponding to the object.
instance - The object instance.
f - The field information.
value - The value to be set in instance for field 'f'.
Throws:
Exception - On set value erros.

setBoolean

protected void setBoolean(Object instance,
                          AbstractPluginObject.Field f,
                          Object value)
                   throws Exception
Sets a boolean to a field.

Parameters:
instance - The object instance.
f - The field information.
value - The value to be set.
Throws:
Exception - On setting errors.

setChar

protected void setChar(Object instance,
                       AbstractPluginObject.Field f,
                       Object value)
                throws Exception
Sets a char to a field.

Parameters:
instance - The object instance.
f - The field information.
value - The value to be set.
Throws:
Exception - On setting errors.

setShort

protected void setShort(Object instance,
                        AbstractPluginObject.Field f,
                        Object value)
                 throws Exception
Sets a short to a field.

Parameters:
instance - The object instance.
f - The field information.
value - The value to be set.
Throws:
Exception - On setting errors.

setInteger

protected void setInteger(Object instance,
                          AbstractPluginObject.Field f,
                          Object value)
                   throws Exception
Sets an integer to a field.

Parameters:
instance - The object instance.
f - The field information.
value - The value to be set.
Throws:
Exception - On setting errors.

setLong

protected void setLong(Object instance,
                       AbstractPluginObject.Field f,
                       Object value)
                throws Exception
Sets a long to a field.

Parameters:
instance - The object instance.
f - The field information.
value - The value to be set.
Throws:
Exception - On setting errors.

setFloat

protected void setFloat(Object instance,
                        AbstractPluginObject.Field f,
                        Object value)
                 throws Exception
Sets a float to a field.

Parameters:
instance - The object instance.
f - The field information.
value - The value to be set.
Throws:
Exception - On setting errors.

setDouble

protected void setDouble(Object instance,
                         AbstractPluginObject.Field f,
                         Object value)
                  throws Exception
Sets a double to a field.

Parameters:
instance - The object instance.
f - The field information.
value - The value to be set.
Throws:
Exception - On setting errors.

setEntity

protected void setEntity(Object instance,
                         AbstractPluginObject.Field f,
                         Object value)
                  throws Exception
If there is some plugin of the object type specified in field, use the plugin object version.

Parameters:
instance - The object instance.
f - The field metadata.
value - The value to be set.
Throws:
Exception - On set errors.

setObject

protected void setObject(Object instance,
                         AbstractPluginObject.Field f,
                         Object value)
                  throws Exception
Sets an object to a field.

Parameters:
instance - The object instance.
f - The field information.
value - The value to be set.
Throws:
Exception - On setting errors.

action

protected abstract void action(IContext context,
                               Object instance,
                               RowAdapter row,
                               IResultSet result)
                        throws Exception
This method can be and should be overridden to perform save, comparison, etc for updates.

Parameters:
context - Test context.
instance - The object instance.
row - The row adapter.
result - The result set.
Throws:
Exception - On action errors.

makeKey

public String makeKey(Object instance)
               throws Exception
Creates the key to be used for storing/recovering object information.

Parameters:
instance - The object instance.
Returns:
The key corresponding to the object.
Throws:
Exception - On key generation errors.

mapObject

public void mapObject(Object instance,
                      String keyBefore,
                      String keyAfter)
Maps the object using the keys before and after Hibernate saving.

Parameters:
instance - The object instance.
keyBefore - The key before saving.
keyAfter - The key after saving.

merge

public AbstractPluginObject merge(AbstractPluginObject old)
Merge to equivalent plugins.

Parameters:
old - Source of copy.
Returns:
The merged plugin.

getObject

public Object getObject(String key)
                 throws PluginException
Given a key, returns the corresponding object instance.

Parameters:
key - The object key.
Returns:
The object.
Throws:
PluginException - If object with the given key is not present in plugin.

removeObject

public Object removeObject(String key)
                    throws PluginException
Remove an object from mapping.

Parameters:
key - The key.
Returns:
The object removed.
Throws:
PluginException - On lookup errors.


Copyright © 2014. All rights reserved.