Expresso 5-5-0

com.jcorporate.expresso.services.controller.dbmaint
Class DynamicCmd

java.lang.Object
  extended bycom.jcorporate.expresso.core.controller.State
      extended bycom.jcorporate.expresso.services.controller.dbmaint.DynamicCmd
All Implemented Interfaces:
Cloneable, Serializable
Direct Known Subclasses:
GetBase, ListBase, UpdateBase, ViewBlob

public abstract class DynamicCmd
extends State

Base class for all command classes. This class provides the execute() method which all subclasses need to override. IT does some basic functionality that all the DBMaint states need, such as load the given DBObject as specified.

Version:
$Revision: 1.34 $ $Date: 2003/10/27 19:10:40 $
Author:
Michael Nash, contributions by Kevin King et al
See Also:
Serialized Form

Field Summary
protected  boolean countTotalRecords
          Allows counting total records to be skipped so we can improve performance on large tables.
static String masterObjKey
          If we are handing master/detail DB objects, then the block containing /* the transitions to navigate the master/detail records is stored in session /* under this key
protected  boolean showNext
          Flag to determine if we need to show the 'next page' icon
protected  boolean showPrev
          Flag to determine if we need to show the 'previous page' icon
 
Fields inherited from class com.jcorporate.expresso.core.controller.State
NOTEMPTY_MASK, secure
 
Constructor Summary
DynamicCmd()
          Default constructor
DynamicCmd(String code, String descrip)
          Constructor most often used
 
Method Summary
protected  void addParams(Transition t)
          Add the fields, details, search and dbobj parameters to a given transition object
protected  String decode(String orig)
          Remove %20 from a string replacing it with spaces
protected  String getControllerName()
          Retrieve the name of the controller we use.
protected  DBObject getCurrentDBObj()
          Deprecated. Since Expresso 5.1 Use getDataObject() for compatibility with AutoDBObject, JoinedDataObject, etc. Will be removed in Expresso 5.2
protected  DataObject getDataObject()
          Retrieve the data object
protected  String getFieldsParam()
          Return the "decoded" 'fields' parameter, consisting of a series of pipe-delimited fields and values
protected  Map getFixedFields()
          Fixed fields are a hastable of field values keyed to field names that should not be modified.
protected  String getKeyParameter(DataObject srcDBObj)
          Create a key parameter for locating the DBObject.
protected  DataObject getMyDataObject()
          Retrieves an instance of my dataobject instance.
 int getPageNumber()
          Returns the current page number as specified in the 'page' parameter
protected  String getSearchParam()
          Return the "decoded" search parameter, consisting of a series of fields and values pipe-delimited
protected  void initializeDBObj()
          Given a class name that contains a DBObject, instantiate an instance of the object & return it.
protected  boolean isKeyField(String fieldName)
          Base class Is this field a key in the given database object?
protected  DataObject retrieveMyDBObject()
          Retrieves the DBObject as specified in the criteria key fields passed to the DBMaint controller.
 void run(ControllerRequest newParams, ControllerResponse newResponse)
          All of the sub-classes of DynamicCmd extend the run method to perform their functionality.
protected  void setFields(DataObject myDBObj, String fieldPairs)
          Sets the fields in the production environment.
protected  void setFieldsParam(String newParam)
          Set a encoded 'fields' parameter, consisting of a series of pipe-delimited fields and values
protected  void setMyDataObject(DataObject myDBObj)
          Set the 'myDBObj' variable which is, in turn, used by the rest of the DBMaint controller.
protected  void setSearchParam(String newParam)
           
protected  void showBlobViewLink(String fieldName, DataObject dbobj, Input myElement, String controller)
          Create a link that is nested to myElement that is for displaying a BLOB field.
protected  void showEditLink(String fieldName, String oneFieldValue, DataObject currentRecord, Output myElement)
          Show the edit link as often used by the List state or updateupdate state.
protected  void showEditLink(String fieldName, String oneFieldValue, DataObject currentRecord, Output myElement, String controller)
          Write a hyperlink command that allows edit of the current key
protected  void showOptions()
          Display a small table of icons giving the user the option to proceed directly to a search, add, or list function from this form.
protected  void showUserName(String theDescrip)
           
 
Methods inherited from class com.jcorporate.expresso.core.controller.State
add, addAutoInput, addAutoInput, addAutoInput, addBlock, addError, addInput, addOptionalParameter, addOutput, addParameter, addParameter, addParameter, addParameter, addParameter, addRequiredParameter, addRequiredParameters, addTransition, autoValidate, autoValidate, calculateHandlerName, checkMask, checkParamMasks, clearFormCache, clone, equals, getAttribute, getController, getControllerRequest, getControllerResponse, getDataContext, getDBController, getDBName, getDescription, getErrors, getErrorState, getErrorTransition, getFileName, getFormCache, getHandlerName, getInitParameter, getName, getObjectParameter, getOptionalParameters, getOptionalParametersList, getParameter, getParameters, getPatternMatcher, getRequiredParametersList, getResponse, getReturnToSender, getSession, getStateFormClass, getString, getString, getSuccessTransition, getUid, getUser, isFileParameter, isParameter, isSecure, perform, saveErrors, setController, setDescription, setErrorState, setErrorTransition, setFormCache, setHandlerName, setMask, setMask, setMaskError, setName, setResponse, setReturnToSender, setSecure, setStateFormClass, setSuccessTransition, toString, transition, validate
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

showNext

protected boolean showNext
Flag to determine if we need to show the 'next page' icon


showPrev

protected boolean showPrev
Flag to determine if we need to show the 'previous page' icon


masterObjKey

public static String masterObjKey
If we are handing master/detail DB objects, then the block containing /* the transitions to navigate the master/detail records is stored in session /* under this key


countTotalRecords

protected boolean countTotalRecords
Allows counting total records to be skipped so we can improve performance on large tables.

Constructor Detail

DynamicCmd

public DynamicCmd()
Default constructor


DynamicCmd

public DynamicCmd(String code,
                  String descrip)
Constructor most often used

Parameters:
code - The internal name of the state
descrip - The friendly name of the state
Method Detail

setSearchParam

protected void setSearchParam(String newParam)
Parameters:
newParam - The new searching paramter String

getSearchParam

protected String getSearchParam()
                         throws ControllerException
Return the "decoded" search parameter, consisting of a series of fields and values pipe-delimited

Returns:
The decoded URL serach parameter
Throws:
ControllerException - upon error

setFieldsParam

protected void setFieldsParam(String newParam)
Set a encoded 'fields' parameter, consisting of a series of pipe-delimited fields and values

Parameters:
newParam - ??

getFieldsParam

protected String getFieldsParam()
                         throws ControllerException
Return the "decoded" 'fields' parameter, consisting of a series of pipe-delimited fields and values

Returns:
The fields Parameter as java.lang.String
Throws:
ControllerException

getFixedFields

protected Map getFixedFields()
                      throws ControllerException

Fixed fields are a hastable of field values keyed to field names that should not be modified. The Input of a fixed field should be rendered read only.

The fields that are fixed can be defined in the 'fields' parameter by specifying which fields should be fixed. This is useful for master/ detail relationship specifications

Returns:
java.util.Map
Throws:
ControllerException

decode

protected String decode(String orig)
Remove %20 from a string replacing it with spaces

Parameters:
orig - Original string
Returns:
String Result string with %20 replaced by spaces

run

public void run(ControllerRequest newParams,
                ControllerResponse newResponse)
         throws ControllerException,
                NonHandleableException
All of the sub-classes of DynamicCmd extend the run method to perform their functionality.

This part of run is an important part in the it adds what is known as the 'nav block' to the jsp pages. It also loads a dbobject into memory corresponding to the dbobject specified by the DBMaint parameters

Overrides:
run in class State
Parameters:
newParams - The ControllerRequest object
newResponse - The ControllerResponse object
Throws:
ControllerException
NonHandleableException - upon fatal error

isKeyField

protected boolean isKeyField(String fieldName)
                      throws DBException,
                             ControllerException
Base class Is this field a key in the given database object?

Parameters:
fieldName - The name of the field to check
Returns:
boolean True if the fieldname is a key field for the current object
Throws:
DBException - If unable to determine if the field is a key due to other errors
ControllerException

showOptions

protected void showOptions()
                    throws DBException,
                           ControllerException

Display a small table of icons giving the user the option to proceed directly to a search, add, or list function from this form. Only the functions this user are allowed to do are shown

If the record being displayed is a 'detail' record, then 'search' and 'fields' paramters are added. This helps specify the criteria (meaning all items here must have the same key as the master

*

Throws:
DBException - If an error occurrs determining what functions this user is allowed to perform
ControllerException

showUserName

protected void showUserName(String theDescrip)
                     throws ControllerException
Parameters:
theDescrip - The Page header to add as String
Throws:
ControllerException

initializeDBObj

protected void initializeDBObj()
                        throws ControllerException
Given a class name that contains a DBObject, instantiate an instance of the object & return it. Also associates the current user name (from the session) with the object so that requests to maniupluate the object can be passed through appropriate security (If the DBObject is of type SecuredDBObject)

Throws:
ControllerException - if the object cannot be created or set up

getCurrentDBObj

protected DBObject getCurrentDBObj()
                            throws ControllerException
Deprecated. Since Expresso 5.1 Use getDataObject() for compatibility with AutoDBObject, JoinedDataObject, etc. Will be removed in Expresso 5.2

Return the current database object. It is an error to request this if the current database object is not initialized

Returns:
the appropriate DBObject
Throws:
ControllerException - if there is no dbobject associated with the controller state

getDataObject

protected DataObject getDataObject()
                            throws ControllerException
Retrieve the data object

Returns:
the current DataObject for this state
Throws:
ControllerException - upon exception

getPageNumber

public int getPageNumber()
                  throws ControllerException
Returns the current page number as specified in the 'page' parameter

Returns:
integer representing the current page number
Throws:
ControllerException

setFields

protected void setFields(DataObject myDBObj,
                         String fieldPairs)
                  throws DBException
Sets the fields in the production environment.

Parameters:
myDBObj - the data object to set the fields to
fieldPairs - the piped field name|field value parameters
Throws:
DBException - upon error

addParams

protected void addParams(Transition t)
                  throws ControllerException
Add the fields, details, search and dbobj parameters to a given transition object

Parameters:
t - The Transition to add the appropriate parameters to.
Throws:
ControllerException - upon error

showEditLink

protected void showEditLink(String fieldName,
                            String oneFieldValue,
                            DataObject currentRecord,
                            Output myElement)
                     throws DBException,
                            ControllerException
Show the edit link as often used by the List state or updateupdate state.

Parameters:
fieldName - the name of the field to render as a link
oneFieldValue - the field's value
currentRecord - the current data object that the field should be retrieved from.
myElement - the output element that is going to be decorated
Throws:
DBException - upon data access error
ControllerException - upon controller error

showBlobViewLink

protected void showBlobViewLink(String fieldName,
                                DataObject dbobj,
                                Input myElement,
                                String controller)
                         throws DBException,
                                ControllerException
Create a link that is nested to myElement that is for displaying a BLOB field.

Parameters:
fieldName - The name of the field to render the link for.
dbobj - The DBobject that the field nests in.
myElement - The Input object that is getting the nested Transition
controller - The name of the controller to link to
Throws:
DBException
ControllerException

showEditLink

protected void showEditLink(String fieldName,
                            String oneFieldValue,
                            DataObject currentRecord,
                            Output myElement,
                            String controller)
                     throws DBException,
                            ControllerException
Write a hyperlink command that allows edit of the current key

Parameters:
fieldName - The name of the field to have the hyperlink
oneFieldValue - The value of the field
currentRecord - A DBObject of the current record
myElement - The cell in the table representing the current field of the current record
controller - the name of the controller to use for the edit link (may be null)
Throws:
DBException - If the information to build the link cannot be retrieved from the database object
ControllerException

getKeyParameter

protected String getKeyParameter(DataObject srcDBObj)
                          throws ControllerException
Create a key parameter for locating the DBObject. Used in generating transitions

Parameters:
srcDBObj - the DBObject to generate the key for.
Returns:
java.lang.String, the pipe delimited URL encoded keys
Throws:
ControllerException - upon error getting the keys for the DBObject

retrieveMyDBObject

protected DataObject retrieveMyDBObject()
                                 throws DBException,
                                        ControllerException
Retrieves the DBObject as specified in the criteria key fields passed to the DBMaint controller.

Returns:
DataObject requested by the request parameters
Throws:
DBException - if unable to retrieve the object
ControllerException - for non-database related errors

setMyDataObject

protected void setMyDataObject(DataObject myDBObj)
Set the 'myDBObj' variable which is, in turn, used by the rest of the DBMaint controller. Use this in derived classes to directly manipulate the dbobject.

Parameters:
myDBObj - the new dataobject to set.

getMyDataObject

protected DataObject getMyDataObject()
Retrieves an instance of my dataobject instance. Use this in derived classes to directly access the 'myDataObject' variable.

Returns:
DataObject instance.

getControllerName

protected String getControllerName()
                            throws ControllerException
Retrieve the name of the controller we use. This is much faster than getController().getClass().getName() because we precalc things once.

Returns:
java.lang.String
Throws:
ControllerException - upon error

Expresso 5-5-0

Please see www.jcorporate.com for information about new Expresso releases.