org.norther.tammi.spray.db.step
Class RepositoryStepAction

java.lang.Object
  extended by org.norther.tammi.spray.loader.task.Action
      extended by org.norther.tammi.spray.loader.task.ActionEvent
          extended by org.norther.tammi.spray.template.step.FlowStepAction
              extended by org.norther.tammi.spray.template.step.NextStepAction
                  extended by org.norther.tammi.spray.template.step.FormStepAction
                      extended by org.norther.tammi.spray.db.step.RepositoryStepAction
All Implemented Interfaces:
Serializable, Task, StepFlowConstants
Direct Known Subclasses:
DictionaryAction, SelectionStepAction

public class RepositoryStepAction
extends FormStepAction

A flow step action for repository based actions.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
static Object NULL_PK
          The null primary key.
static Object ROOT_PK
          The root primary key.
 
Fields inherited from interface org.norther.tammi.spray.template.flow.StepFlowConstants
ADAPTABLE_STATE, DISPOSABLE_STATE, EXPLICIT_STATE, FINISHED_STATE, HELP_PIPE_PROPERTY, QUALIFIED_STATE, READ_ONLY_STATE, REPOSITORY_PROPERTY, SELECTABLE_STATE
 
Constructor Summary
RepositoryStepAction()
          Constructs a new flow step action.
 
Method Summary
 boolean add1NForeignReferences(Object node, String className, String fkField, Object[] fks, Persister persister, FilterChain chain)
          Adds foreign references to 1:n relations.
 boolean add1NNullReferences(String className, String fkField, Object[] fks, Persister persister, FilterChain chain)
          Adds null references to 1:n relations.
 boolean add1NObjectReferences(Object node, String relField, String fkField, Object[] fks, Persister persister, FilterChain chain)
          Adds object references to 1:n relations.
 boolean addAttributeValues(Object node, String field, Persister persister, FilterChain chain, List result)
          Adds attribute values to a list.
 boolean addToRelationMap(Object node, String relField, Persister persister, FilterChain chain, ConcurrentMap result)
          Adds to a map of referenced objects.
 Variable createVariable(Class clazz, FilterChain chain)
          Creates a new variable MBean instance of the specified class.
 Variable createVariable(String type, FilterChain chain)
          Creates a new variable MBean instance of the specified type.
 Variable deleteVariable(Variable var, Persister persister, FilterChain chain)
          Deletes a variable and its dependencies.
 Object getAttributeValue(Object node, String field, Persister persister, FilterChain chain)
          Gets an attribute value.
 List getAttributeValues(Object node, String field, Persister persister, FilterChain chain)
          Gets a list of attribute values.
protected  BeanRepositoryClient getBeanRepositoryClient(FilterChain chain)
          Gets the bean repository client.
 String getConnectionKey(ServletRequest request, ServletResponse response, FilterChain chain)
          Gets the default connection key.
 Object getEndReference(Object node, String relField, Persister persister, FilterChain chain)
          Gets the end node.
 Introspector getIntrospector(ServletRequest request, ServletResponse response, FilterChain chain)
          Gets a localized introspector.
 Object getKeyAttributeValue(Object node, Persister persister, FilterChain chain)
          Gets the primary key value.
 Object[] getKeyAttributeValues(Object node, Persister persister, FilterChain chain)
          Gets the primary key values.
 LoaderMBean getLoader(FilterChain chain)
          Gets the loader for dynamic class loading.
 Object getNextReference(Object node, int index, String relField, Persister persister, FilterChain chain)
          Gets an indexed node.
 Object getNextReference(Object node, String relField, Persister persister, FilterChain chain)
          Gets the next referenced node.
 List getNextReferences(Object node, String relField, Persister persister, FilterChain chain)
          Gets a list of referenced nodes.
 Persister getPersister(ServletRequest request, ServletResponse response, FilterChain chain)
          Gets the default persister.
 Persister getPersister(ServletRequest request, ServletResponse response, FilterChain chain, StepFlowContext context)
          Gets the context specific persister.
 Persister getPersister(String key, ServletRequest request, ServletResponse response, FilterChain chain)
          Gets the specified persister.
static List getPostDependencies(String className)
          Gets the post-dependencies of the named class.
static List getPreDependencies(String className)
          Gets the pre-dependencies of the named class.
protected  MultiRepositoryClient getRepositoryClient(FilterChain chain)
          Gets the repository client.
 String getResourceKey(ServletRequest request, ServletResponse response, FilterChain chain)
          Gets the resource connection key.
 Object getRootReference(Object node, String relField, Persister persister, FilterChain chain)
          Gets the root node.
 List getRootReferences(Object node, String relField, Persister persister, FilterChain chain)
          Gets the root nodes.
 Variable insertVariable(Variable var, Persister persister, FilterChain chain)
          Inserts a new variable by exporting the specified one.
 boolean isNullPK(Object pk, FilterChain chain)
          Checks whether the specified pk is a null key.
 boolean isRelatedTo(Variable node, String relField, Object xpk, Persister persister, FilterChain chain)
          Checks whether the specified key is related to the specified node.
 boolean isRootPK(Object pk, FilterChain chain)
          Checks whether the specified pk is a root key.
 void setAttributeValue(Object node, String field, Object value, boolean forced, Persister persister, FilterChain chain)
          Sets an attribute value with a forced option.
 void setAttributeValue(Object node, String field, Object value, Persister persister, FilterChain chain)
          Sets an attribute value.
 void setKeyAttributeValue(Object node, Object value, Persister persister, FilterChain chain)
          Sets the primary key value.
 void setKeyAttributeValues(Object node, Object[] values, Persister persister, FilterChain chain)
          Sets the primary key values.
 Object[] setMNForeignReferences(Object node, String indirection, String fkField1, String fkField2, Object[] fks, Persister persister, FilterChain chain)
          Sets foreign references in m:n relations.
 Object[] setMNObjectReferences(Object node, String relField, String indirection, String fkField1, String fkField2, Object[] fks, Persister persister, FilterChain chain)
          Sets object references in m:n relations.
static void setPostDependencies(String className, List deps)
          Sets the post-dependencies of the named class.
static void setPreDependencies(String className, List deps)
          Sets the pre-dependencies of the named class.
 Class toClass(String className, FilterChain chain)
          Converts a class name into the corresponding class.
 Variable updateVariable(Variable var, Persister persister, FilterChain chain)
          Updates an edited variable by exporting the specified one.
 
Methods inherited from class org.norther.tammi.spray.template.step.FormStepAction
disableNextStep, enableNextStep, isStepFinished, parseUploadedFile, parseUploadedFile, setStepFinished, submit, submitCancelStep, submitFinishStep, submitNextStep, submitPreviousStep, submitRenewForm, submitResetForm, submitUpdateForm, update, update
 
Methods inherited from class org.norther.tammi.spray.template.step.NextStepAction
submitBackStep
 
Methods inherited from class org.norther.tammi.spray.template.step.FlowStepAction
checkPermission, checkPermission, done, execute, execute, finish, forward, getPermissibleRoles, getSignature, include, initialize, initialize, prepare, pushError, submit, submitOpenHelp
 
Methods inherited from class org.norther.tammi.spray.loader.task.ActionEvent
getAction, getAction, getAction, invoke
 
Methods inherited from class org.norther.tammi.spray.loader.task.Action
find, getFilter, getMBeanServer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_PK

public static final Object NULL_PK
The null primary key.


ROOT_PK

public static final Object ROOT_PK
The root primary key.

Constructor Detail

RepositoryStepAction

public RepositoryStepAction()
Constructs a new flow step action.

Method Detail

getPreDependencies

public static List getPreDependencies(String className)
Gets the pre-dependencies of the named class.

Parameters:
className - the class name.
Returns:
a list of dependencies or null.

setPreDependencies

public static void setPreDependencies(String className,
                                      List deps)
Sets the pre-dependencies of the named class.

Parameters:
className - the class name.
deps - a list of dependencies or null.

getPostDependencies

public static List getPostDependencies(String className)
Gets the post-dependencies of the named class.

Parameters:
className - the class name.
Returns:
a list of dependencies or null.

setPostDependencies

public static void setPostDependencies(String className,
                                       List deps)
Sets the post-dependencies of the named class.

Parameters:
className - the class name.
deps - a list of dependencies or null.

getConnectionKey

public String getConnectionKey(ServletRequest request,
                               ServletResponse response,
                               FilterChain chain)
                        throws Exception
Gets the default connection key.

Parameters:
request - the request.
response - the response.
chain - the filter chain.
Returns:
the default persister.
Throws:
Exception - on errors.

getResourceKey

public String getResourceKey(ServletRequest request,
                             ServletResponse response,
                             FilterChain chain)
                      throws Exception
Gets the resource connection key.

Parameters:
request - the request.
response - the response.
chain - the filter chain.
Returns:
the default persister.
Throws:
Exception - on errors.

toClass

public Class toClass(String className,
                     FilterChain chain)
              throws ClassNotFoundException
Converts a class name into the corresponding class.

Parameters:
className - the class name.
chain - the filter chain.
Returns:
the corresponding class.
Throws:
ClassNotFoundException - if not found.

getLoader

public LoaderMBean getLoader(FilterChain chain)
Gets the loader for dynamic class loading.

Parameters:
chain - the filter chain.
Returns:
the loader.
Throws:
IllegalStateException - if not found.

getIntrospector

public Introspector getIntrospector(ServletRequest request,
                                    ServletResponse response,
                                    FilterChain chain)
Gets a localized introspector.

Parameters:
request - the request.
response - the response.
chain - the filter chain.
Returns:
the introspector.

getPersister

public Persister getPersister(ServletRequest request,
                              ServletResponse response,
                              FilterChain chain)
                       throws Exception
Gets the default persister.

Parameters:
request - the request.
response - the response.
chain - the filter chain.
Returns:
the default persister.
Throws:
Exception - on errors.

getPersister

public Persister getPersister(String key,
                              ServletRequest request,
                              ServletResponse response,
                              FilterChain chain)
                       throws Exception
Gets the specified persister.

Parameters:
key - the connection key to apply.
request - the request.
response - the response.
chain - the filter chain.
Returns:
the specified persister.
Throws:
Exception - on errors.

getPersister

public Persister getPersister(ServletRequest request,
                              ServletResponse response,
                              FilterChain chain,
                              StepFlowContext context)
                       throws Exception
Gets the context specific persister.

Parameters:
request - the request.
response - the response.
chain - the filter chain.
context - the flow context.
Returns:
the default persister.
Throws:
Exception - on errors.

isNullPK

public boolean isNullPK(Object pk,
                        FilterChain chain)
Checks whether the specified pk is a null key.

Parameters:
pk - the pk to check.
chain - the filter chain.
Returns:
true for a null key, false otherwise.

isRootPK

public boolean isRootPK(Object pk,
                        FilterChain chain)
Checks whether the specified pk is a root key.

Parameters:
pk - the pk to check.
chain - the filter chain.
Returns:
true for a root key, false otherwise.

createVariable

public Variable createVariable(String type,
                               FilterChain chain)
                        throws Exception
Creates a new variable MBean instance of the specified type.

Parameters:
type - the type of the variable.
chain - the filter chain.
Returns:
the variable MBean instance.
Throws:
Exception - on errors.

createVariable

public Variable createVariable(Class clazz,
                               FilterChain chain)
                        throws Exception
Creates a new variable MBean instance of the specified class.

Parameters:
clazz - the class of the variable.
chain - the filter chain.
Returns:
the variable MBean instance.
Throws:
Exception - on errors.

insertVariable

public Variable insertVariable(Variable var,
                               Persister persister,
                               FilterChain chain)
                        throws Exception
Inserts a new variable by exporting the specified one.

Parameters:
var - the variable to insert.
persister - the persister.
chain - the filter chain.
Returns:
the inserted variable.
Throws:
Exception - on errors.

updateVariable

public Variable updateVariable(Variable var,
                               Persister persister,
                               FilterChain chain)
                        throws Exception
Updates an edited variable by exporting the specified one.

Parameters:
var - the variable to update.
persister - the persister.
chain - the filter chain.
Returns:
the updated variable.
Throws:
Exception - on errors.

deleteVariable

public Variable deleteVariable(Variable var,
                               Persister persister,
                               FilterChain chain)
                        throws Exception
Deletes a variable and its dependencies.

Parameters:
var - the variable to delete.
persister - the persister.
chain - the filter chain.
Returns:
the deleted variable.
Throws:
Exception - on errors.

getKeyAttributeValue

public Object getKeyAttributeValue(Object node,
                                   Persister persister,
                                   FilterChain chain)
                            throws Exception
Gets the primary key value.

Parameters:
node - the node object.
persister - the persister.
chain - the filter chain.
Returns:
the PK value.
Throws:
Exception - on errors.

setKeyAttributeValue

public void setKeyAttributeValue(Object node,
                                 Object value,
                                 Persister persister,
                                 FilterChain chain)
                          throws Exception
Sets the primary key value.

Parameters:
node - the node object.
value - the PK value.
persister - the persister.
chain - the filter chain.
Throws:
Exception - on errors.

getKeyAttributeValues

public Object[] getKeyAttributeValues(Object node,
                                      Persister persister,
                                      FilterChain chain)
                               throws Exception
Gets the primary key values.

Parameters:
node - the node object.
persister - the persister.
chain - the filter chain.
Returns:
the PK values.
Throws:
Exception - on errors.

setKeyAttributeValues

public void setKeyAttributeValues(Object node,
                                  Object[] values,
                                  Persister persister,
                                  FilterChain chain)
                           throws Exception
Sets the primary key values.

Parameters:
node - the node object.
values - the PK values.
persister - the persister.
chain - the filter chain.
Throws:
Exception - on errors.

getAttributeValue

public Object getAttributeValue(Object node,
                                String field,
                                Persister persister,
                                FilterChain chain)
                         throws Exception
Gets an attribute value.

Parameters:
node - the node object.
field - the attribute field(s).
persister - the persister.
chain - the filter chain.
Returns:
the attribute value.
Throws:
Exception - on errors.

setAttributeValue

public void setAttributeValue(Object node,
                              String field,
                              Object value,
                              Persister persister,
                              FilterChain chain)
                       throws Exception
Sets an attribute value.

Parameters:
node - the node object.
field - the attribute field(s).
value - the attribute value.
persister - the persister.
chain - the filter chain.
Throws:
Exception - on errors.

setAttributeValue

public void setAttributeValue(Object node,
                              String field,
                              Object value,
                              boolean forced,
                              Persister persister,
                              FilterChain chain)
                       throws Exception
Sets an attribute value with a forced option.

Parameters:
node - the node object.
field - the attribute field(s).
value - the attribute value.
forced - if true, forces the setting.
persister - the persister.
chain - the filter chain.
Throws:
Exception - on errors.

getAttributeValues

public List getAttributeValues(Object node,
                               String field,
                               Persister persister,
                               FilterChain chain)
                        throws Exception
Gets a list of attribute values.

Parameters:
node - the node object.
field - the attribute field(s).
persister - the persister.
chain - the filter chain.
Returns:
a list of attribute values.
Throws:
Exception - on errors.

addAttributeValues

public boolean addAttributeValues(Object node,
                                  String field,
                                  Persister persister,
                                  FilterChain chain,
                                  List result)
                           throws Exception
Adds attribute values to a list.

Parameters:
node - the node object.
field - the attribute field(s).
persister - the persister.
chain - the filter chain.
result - a list of attribute values.
Returns:
true if added, false otherwise.
Throws:
Exception - on errors.

getEndReference

public Object getEndReference(Object node,
                              String relField,
                              Persister persister,
                              FilterChain chain)
                       throws Exception
Gets the end node.

Parameters:
node - the node object.
relField - the relation field.
persister - the persister.
chain - the filter chain.
Returns:
the referenced node or null.
Throws:
Exception - on errors.

getRootReference

public Object getRootReference(Object node,
                               String relField,
                               Persister persister,
                               FilterChain chain)
                        throws Exception
Gets the root node.

Parameters:
node - the node object.
relField - the relation field.
persister - the persister.
chain - the filter chain.
Returns:
the referenced node or null.
Throws:
Exception - on errors.

getRootReferences

public List getRootReferences(Object node,
                              String relField,
                              Persister persister,
                              FilterChain chain)
                       throws Exception
Gets the root nodes.

Parameters:
node - the node object.
relField - the relation field.
persister - the persister.
chain - the filter chain.
Returns:
a read-only list of referenced nodes.
Throws:
Exception - on errors.

getNextReference

public Object getNextReference(Object node,
                               String relField,
                               Persister persister,
                               FilterChain chain)
                        throws Exception
Gets the next referenced node.

Parameters:
node - the node object.
relField - the relation field.
persister - the persister.
chain - the filter chain.
Returns:
the referenced node or null.
Throws:
Exception - on errors.

getNextReference

public Object getNextReference(Object node,
                               int index,
                               String relField,
                               Persister persister,
                               FilterChain chain)
                        throws Exception
Gets an indexed node.

Parameters:
node - the node object.
index - the index.
relField - the relation field.
persister - the persister.
chain - the filter chain.
Returns:
the referenced node or null.
Throws:
Exception - on errors.

getNextReferences

public List getNextReferences(Object node,
                              String relField,
                              Persister persister,
                              FilterChain chain)
                       throws Exception
Gets a list of referenced nodes.

Parameters:
node - the node object.
relField - the relation field.
persister - the persister.
chain - the filter chain.
Returns:
a read-only list of referenced nodes.
Throws:
Exception - on errors.

isRelatedTo

public boolean isRelatedTo(Variable node,
                           String relField,
                           Object xpk,
                           Persister persister,
                           FilterChain chain)
                    throws Exception
Checks whether the specified key is related to the specified node.

Parameters:
node - the node variable.
relField - the relation field.
xpk - the primary key to check.
persister - the persister.
chain - the filter chain.
Returns:
true if referenced, otherwise false.
Throws:
Exception - on errors.

addToRelationMap

public boolean addToRelationMap(Object node,
                                String relField,
                                Persister persister,
                                FilterChain chain,
                                ConcurrentMap result)
                         throws Exception
Adds to a map of referenced objects.

Parameters:
node - the node object.
relField - the relation field.
persister - the persister.
chain - the filter chain.
result - the result map.
Returns:
true if added, false otherwise.
Throws:
Exception - on errors.

add1NNullReferences

public boolean add1NNullReferences(String className,
                                   String fkField,
                                   Object[] fks,
                                   Persister persister,
                                   FilterChain chain)
                            throws Exception
Adds null references to 1:n relations.

Parameters:
className - the data class name.
fkField - the foreign key field.
fks - an array of new foreign keys or identities.
persister - the persister.
chain - the filter chain.
Returns:
true if references were added.
Throws:
Exception - on errors.

add1NForeignReferences

public boolean add1NForeignReferences(Object node,
                                      String className,