|
Expresso 5-6 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.apache.struts.action.Action
com.jcorporate.expresso.core.controller.Controller
A sequence of interaction with a user is defined as a "Controller".
An Expresso controller is best thought of as a finite state machine. The only real difference is that because of the stateless nature of the web, anybody can reach any state with using the "state" parameter in the URL. Usually for a web deployment environment, you would derive your own controller from DBController, which adds a database-backed Security matrix to the controller's base capabilities. Controllers (and DBControllers) do not necessarily need to be run inside a servlet environment. If they never downcast their ControllerResponse object to ServletControllerResponse, the Controller can also be used in products such as Expresso Webservices, orSee the Expresso Developer's Guide for more information on creating and using a Controller.
A Controller takes a series of parameters (optional) and then provides a series of Blocks, Inputs, Outputs, and Transitions to the client
DBController,
SecureIfSetController,
Serialized Form| Field Summary | |
static String |
CONTROLLER_PARAM_KEY
key for putting controller into parameter map |
static String |
CTL_SUCC_CTL
|
static String |
CTL_SUCC_STATE
|
static String |
CTL_SUCC_TRAN
|
protected org.apache.log4j.Logger |
mLog
if subclass calls getLogger(), this will create logger with subclass name |
static String |
NEWSTATE_EXCEPTION_KEY
New state exception key |
static String |
ORIGINAL_URL_KEY
Controller original URL key |
static String |
REQUEST_KEY
Controller request key |
static String |
RESPONSE_KEY
Controller response key |
static String |
RETURN_TO_SENDER_TRAN
|
static String |
STATE_ERR_CTL
|
static String |
STATE_ERR_STATE
|
static String |
STATE_ERR_TRAN
|
static String |
STATE_PARAM_KEY
key for putting state into parameter map |
static String |
STATE_SUCC_CTL
|
static String |
STATE_SUCC_STATE
|
static String |
STATE_SUCC_TRAN
|
| Fields inherited from class org.apache.struts.action.Action |
ACTION_SERVLET_KEY, APPLICATION_KEY, DATA_SOURCE_KEY, defaultLocale, ERROR_KEY, EXCEPTION_KEY, FORM_BEANS_KEY, FORWARDS_KEY, LOCALE_KEY, MAPPING_KEY, MAPPINGS_KEY, MESSAGE_KEY, MESSAGES_KEY, MULTIPART_KEY, PLUG_INS_KEY, REQUEST_PROCESSOR_KEY, servlet, SERVLET_KEY, TRANSACTION_TOKEN_KEY |
| Constructor Summary | |
Controller()
Default constructor |
|
| Method Summary | |
protected void |
addFinalState(State newFinalState)
The constructor of the child object should call addFinalState to define the last state to be executed for this controller. |
protected void |
addPromptTransitions(State nextState,
ControllerResponse response)
If nextState is a prompt state (as determined by the addStatePairing method) then add a 'next' and 'previous' transitions as required. |
protected void |
addRegDomainParamtoSession(HttpServletRequest req,
ControllerRequest creq,
String regDomain)
??????????????????????? |
protected void |
addRequestedURLtoSession(HttpServletRequest req,
ControllerRequest creq)
|
protected void |
addState(State newState)
The constructor of the child object should call addState to define each of the states available in this method. |
protected void |
addStatePairing(State promptState,
State handleState,
String stateFormClass)
The constructor of the child object should call this method with a pairing of State objects. |
protected void |
endTimer(long beginTimer,
HttpServletRequest request)
Used for logging time of requests. |
org.apache.struts.action.ActionForward |
execute(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it). |
protected org.apache.struts.action.ActionForm |
findControllerForm(ControllerRequest request)
Return the Struts ActionForm associated with this controller as specified in the Struts config file. |
protected String |
generateToken(ControllerRequest request)
Generate a new transaction token, to be used for enforcing a single request for a particular transaction. |
protected org.apache.struts.action.ActionForward |
getActionForward(ServletControllerRequest req,
org.apache.struts.config.ActionConfig mapping,
ControllerResponse res)
Determine the forward appropriate for this controller/state, either from parameters or from configuration files, or from remapping based on past extensions like .xsl |
protected Transition |
getControllerChainingTransition()
Return the transition that will be executed once this controller completes without errors. |
protected Transition |
getControllerSecurityTransition()
Return the transition that will be executed if any state in this controller cannot be run because the user does not have sufficient authorization. |
State |
getFinalState()
Return the final state for this controller. |
String |
getInitialState()
Get the initial state in a controller. |
org.apache.log4j.Logger |
getLogger()
Call from subclass to log into Category with subclass name will create logger with subclass name as necessary. |
static String[] |
getParamValues(ServletControllerRequest request,
String paramName)
Fetches array of parameter values from underlying HTTP request; use this in a web app to access the underlying parameters in the HTTP request which have the same name; parameters with the same name are not reflected in the hashtable maintained by ControllerRequest; |
protected String |
getRequestURL(HttpServletRequest req)
recreate requested URL; never null, though could be empty string |
protected String |
getSchema()
Get the name of the schema object that this Controller belongs to |
Stack |
getSchemaHierarchy()
Deprecated. 7/04; v5.5. just name changed. see getSchemaStack |
protected Schema |
getSchemaInstance()
Retrieve a full instance of the Schema object that is associated with this controller |
Stack |
getSchemaStack()
Retrieve a stack of all schemas. hands out actual object instance; singleton for this controller. |
State |
getState(String stateName)
Return a specific state |
Hashtable |
getStates()
Return the hashtable of valid states for this controller |
protected String |
getString(String stringCode)
Convenience version, uses default locale of default db context IMPORTANT: in general, if there's a ControllerResponse object available, use ControllerResponse.getString(String) instead, this is able to return the local language by considering the user's locale. |
protected String |
getString(String stringCode,
Object[] args)
Convenience version, uses default locale of default db context IMPORTANT: In general, if there's a ControllerResponse object available, use ControllerResponse.getString(String) instead, this is able to return the local language by considering the user's locale. |
String |
getTitle()
Return the title of this Controller |
protected void |
handleException(HttpServletRequest req,
ControllerRequest creq,
String dbName,
String userName,
Throwable theException)
Handle an exception error that is not otherwise caught or handled by the Controller instance itself. |
static Controller |
instantiate(String className)
Factory method to create an Controller from it's name Do not call this function directly! |
protected boolean |
isFinalState(String newState)
Return True if the passed in state was added to this controller as a final state. |
protected boolean |
isHandleState(State nextState)
Return True if the passed in state was added to this controller as a handle state. |
protected boolean |
isPromptState(State nextState)
Return True if the passed in state was added to this controller as a prompt state. |
protected boolean |
isTokenValid(ControllerRequest request)
Return true if there is a transaction token stored in
the user's current session, and the value submitted as a request
parameter with this action matches it. |
protected StateForm |
loadStateForm(State nextState,
org.apache.struts.action.ActionForm controllerForm)
Return the state's form with data from the controller's form. |
ControllerResponse |
newState(String newState,
ControllerRequest myRequest)
This is the method where all of the real work of the controller is done. |
protected String |
nextHandleState(State nextState)
Return the name of the handle state that is associated with the passed in prompt state. |
protected String |
nextPromptState(State nextState)
Return the name of the prompt state that is 'next' to the passed in prompt state in the sequence for this controller. |
protected void |
populateStateForm(StateForm stateForm,
ControllerRequest request)
Populate the state form with any matching request parameters. |
protected void |
postPerform(State nextState,
ControllerRequest request,
ControllerResponse response)
Template Method, allowing a subclass to into actions after the invocation of any state in this controller. |
protected void |
prePerform(State nextState,
ControllerRequest request,
ControllerResponse response)
Template Method, allowing a subclass to do an action after any state in this controller is performed. |
protected String |
previousPromptState(State nextState)
Return the name of the prompt state that is 'previous' to the passed in prompt state in the sequence for this controller. |
protected void |
processRequestTransitions(State nextState,
ControllerRequest request)
This method picks up the following routing parameters from the current request and builds transition objects from them before the state is invoked. |
protected Transition |
processTransitions(ControllerRequest request,
ControllerResponse response,
State nextState)
This method is the traffic cop that determines which transition to execute after a state completes. |
void |
redirectRequest(ControllerRequest request,
ControllerResponse response,
String redirectURL)
redirect response so that URL changes in client browser |
protected void |
redirectRequest(HttpServletResponse response,
String redirectURL)
redirect response so that URL changes in client browser |
protected org.apache.struts.config.ForwardConfig |
remapFromExtension(org.apache.struts.config.ForwardConfig fwd,
org.apache.struts.config.ActionConfig mapping,
ServletControllerRequest req)
if the extension in the current forward is ".xsl" or ".xslt", remap the forward to "xml", and set a parameter for the xsl style sheet. |
protected void |
resetToken(ControllerRequest request)
Reset the saved transaction token in the user's session. |
protected void |
saveToken(ControllerRequest request)
Save a new transaction token in the user's current session, creating a new session if necessary. |
protected void |
setControllerChainingTransition(Transition newControllerChainingTransition)
Set the transition that will be executed when this controller completes successfully. |
protected void |
setControllerSecurityTransition(Transition newControllerSecurityTransition)
Set the transition that will be executed when a user attempts to run a state he doesn't have authorization on. |
ControllerResponse |
setCurrentState(String newState,
ControllerRequest params)
Convenience method to be able to access the state as a property from a JSP. |
void |
setInitialState(String newInitialState)
Set what state to invoke if no state parameter is set. |
protected void |
setSchema(Class schemaClass)
Identical to setSchema(String) but provides a typesafe way of passing parameters. |
protected void |
setSchema(String schemaClass)
Tell this Controller object what Schema it belongs to. |
void |
setupDefaultValues(String dbName)
Allows for DBCreate to set up proper default values for views, etc. |
protected void |
setupReturnToSender(State nextState,
ControllerRequest request)
This method is called before a state executes. |
protected void |
setupSubclassLog()
setup a subclass logger separately from the base controller logger. |
boolean |
stateAllowed(String newState,
ControllerRequest params)
Is this state allowed for the current user? |
protected void |
transition(String newState,
Class externalController,
ControllerRequest req,
ControllerResponse res)
convenience method for transition to other controller |
protected void |
transition(String newState,
ControllerRequest req,
ControllerResponse res)
|
protected void |
transition(String newState,
ControllerRequest req,
ControllerResponse res,
boolean clear)
Transition to an internal state. |
protected void |
unloadStateForm(StateForm stateForm,
org.apache.struts.action.ActionForm controllerForm)
Move the state's form data back into the controller's form. |
| Methods inherited from class org.apache.struts.action.Action |
execute, generateToken, getDataSource, getDataSource, getLocale, getResources, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, perform, perform, resetToken, saveErrors, saveMessages, saveToken, setLocale, setServlet, toHex |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected org.apache.log4j.Logger mLog
public static final String RESPONSE_KEY
public static final String ORIGINAL_URL_KEY
public static final String REQUEST_KEY
public static final String NEWSTATE_EXCEPTION_KEY
public static final String CTL_SUCC_TRAN
public static final String CTL_SUCC_CTL
public static final String CTL_SUCC_STATE
public static final String STATE_SUCC_TRAN
public static final String STATE_SUCC_CTL
public static final String STATE_SUCC_STATE
public static final String STATE_ERR_TRAN
public static final String STATE_ERR_CTL
public static final String STATE_ERR_STATE
public static final String RETURN_TO_SENDER_TRAN
public static final String STATE_PARAM_KEY
public static final String CONTROLLER_PARAM_KEY
| Constructor Detail |
public Controller()
| Method Detail |
protected void addFinalState(State newFinalState)
throws NonHandleableException
newFinalState - the new state to use as your final state.
NonHandleableException - if you send it an improper final state.
protected void addPromptTransitions(State nextState,
ControllerResponse response)
throws ControllerException
nextState - in this controller the new state addresponse - the ControllerResponse that these transitions will be
added to.
ControllerException - upon error.protected void addState(State newState)
newState - The State object to be added to the list of states for this
controller
protected void addStatePairing(State promptState,
State handleState,
String stateFormClass)
throws NonHandleableException
promptState - The state that is part of the 'prompting' workflowhandleState - The state that is part of the 'processing' workflowstateFormClass - The ActionForm name to use
NonHandleableException - if there's an error in pairing. Usually
caused by a java.lang.IllegalArumentException
protected org.apache.struts.action.ActionForm findControllerForm(ControllerRequest request)
throws ControllerException
request - The ControllerRequest object
ActionForm for this controller request
ControllerException - if unable to find the Controller Form.protected Transition getControllerChainingTransition()
protected Transition getControllerSecurityTransition()
public State getFinalState()
public String getInitialState()
state parameter specified in the requesting URL or
execution container.
protected final String getSchema()
protected Schema getSchemaInstance()
public Stack getSchemaHierarchy()
public Stack getSchemaStack()
public final State getState(String stateName)
stateName - The name of the state to retrieve
public final Hashtable getStates()
protected String getString(String stringCode)
stringCode - The properties file string code to retrieve
protected String getString(String stringCode,
Object[] args)
stringCode - The properties file string code to retrieveargs - The Object array for i18n formatting.
public String getTitle()
protected void handleException(HttpServletRequest req,
ControllerRequest creq,
String dbName,
String userName,
Throwable theException)
throws ServletException
req - The HTTPServletRequestcreq - The ControllerRequest ObjectdbName - The current data contextuserName - The currently logged in UsernametheException - The java.lang.Throwable object that
was caught
ServletException - upon fatal error for handling the exception
protected void addRequestedURLtoSession(HttpServletRequest req,
ControllerRequest creq)
throws ControllerException
ControllerExceptionprotected String getRequestURL(HttpServletRequest req)
protected void addRegDomainParamtoSession(HttpServletRequest req,
ControllerRequest creq,
String regDomain)
throws ControllerException
req - ?creq - ?regDomain - ?
ControllerException
public static Controller instantiate(String className)
throws ControllerException
ConfigManager.getControllerFactory()
.getInstance(java.lang.String) instead.
className - The classname of the controller to instantiated
ControllerException - upon construction failureprotected boolean isFinalState(String newState)
newState - the state name to use as the final state.
protected boolean isHandleState(State nextState)
nextState - the state name to check against
protected boolean isPromptState(State nextState)
nextState - the state name to check against
protected StateForm loadStateForm(State nextState,
org.apache.struts.action.ActionForm controllerForm)
throws ControllerException
nextState - The next state to usecontrollerForm - the ControllerForm as specified in the struts config file.
ControllerException - if there is an error instantiating the State Form
public ControllerResponse newState(String newState,
ControllerRequest myRequest)
throws ControllerException,
NonHandleableException
newState - The new state to transition tomyRequest - The calling controllerRequest object.
ControllerException - on Error
NonHandleableException - if the error should not be handled
by an error controller
protected void prePerform(State nextState,
ControllerRequest request,
ControllerResponse response)
throws ControllerException
nextState - the state to be performedrequest - the request objectresponse - the response object
ControllerException
protected void postPerform(State nextState,
ControllerRequest request,
ControllerResponse response)
throws ControllerException
nextState - the state to be performedrequest - the request objectresponse - the response object
ControllerExceptionprotected String nextHandleState(State nextState)
nextState - the next state to check against
protected String nextPromptState(State nextState)
nextState - the next state to check against
protected void endTimer(long beginTimer,
HttpServletRequest request)
beginTimer - The start execution timerequest - The HTTPServletRequest to instrument
public org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException,
ServletException
ActionForward instance describing where and how
control should be forwarded, or null if the response has
already been completed. Note, that if you wish to run a controller within
something other than a HTTP session, then call newState directly.
mapping - The ActionMapping used to select this instanceform - The optional ActionForm bean for this request (if any)request - The HTTP request we are processingresponse - The HTTP response we are creating
IOException - if an input/output error occurs
ServletException - if a servlet exception occurs
protected org.apache.struts.action.ActionForward getActionForward(ServletControllerRequest req,
org.apache.struts.config.ActionConfig mapping,
ControllerResponse res)
throws NonHandleableException,
ControllerException
req - the ServletControllerRequest objectmapping - the ActionConfig that defines the mappingres - the ControllerResponse object that has been handed back to
us by Controller.newState()
NonHandleableException - upon fatal error
ControllerException - upon error
protected org.apache.struts.config.ForwardConfig remapFromExtension(org.apache.struts.config.ForwardConfig fwd,
org.apache.struts.config.ActionConfig mapping,
ServletControllerRequest req)
throws ControllerException
fwd - The ForwardConfig objectmapping - the ActionConfig for the particular controller instancereq - the ServletControllerRequest for the request.
ControllerException - upon error
protected void redirectRequest(HttpServletResponse response,
String redirectURL)
throws IOException
response - The Servlet ResponseredirectURL - The URL to redirect the browser to.
IOException - upon browser error.
protected void populateStateForm(StateForm stateForm,
ControllerRequest request)
throws ControllerException
stateForm - The name of the state form to populaterequest - The source of the variables for the state form.
ControllerException - upon BeanUtils.populate() errorprotected String previousPromptState(State nextState)
nextState - The state to check against
protected void processRequestTransitions(State nextState,
ControllerRequest request)
throws ControllerException
nextState - the next state to check processrequest - The controllerRequest object
ControllerException - upon error.
protected Transition processTransitions(ControllerRequest request,
ControllerResponse response,
State nextState)
throws ControllerException,
NonHandleableException
request - The ControllerRequest Objectresponse - The ControllerResponse ObjectnextState - the state to transition to.
NonHandleableException - upon a fatal error.
ControllerException
protected void setControllerChainingTransition(Transition newControllerChainingTransition)
throws NonHandleableException
newControllerChainingTransition - The new transition for when the
controller completes successfully.
NonHandleableException - upon incorrect parameters.protected void setControllerSecurityTransition(Transition newControllerSecurityTransition)
newControllerSecurityTransition - To execute.
public ControllerResponse setCurrentState(String newState,
ControllerRequest params)
throws ControllerException,
NonHandleableException
newState - The newState to set to.params - The ControllerRequest object
ControllerException - upon error
NonHandleableException - upon fatal errorpublic void setInitialState(String newInitialState)
newInitialState - The state to use as the initial state.protected void setSchema(String schemaClass)
schemaClass - The classname of the Schema to associate with.protected void setSchema(Class schemaClass)
setSchema(com.jcorporate.expresso.core.ExpressoSchema
.class);
schemaClass - The Class of the schema to set
public void setupDefaultValues(String dbName)
throws DBException
dbName - the name of the db to add these values to.
DBException - upon error
protected void setupReturnToSender(State nextState,
ControllerRequest request)
throws ControllerException
nextState - = The state that is about to be executedrequest - The parsed ControllerRequest object
ControllerException - upon error.
public boolean stateAllowed(String newState,
ControllerRequest params)
throws ControllerException
newState - The name of the state being checkedparams - The ControllerRequestObject
ControllerException - upon error
protected void transition(String newState,
ControllerRequest req,
ControllerResponse res)
throws ControllerException,
NonHandleableException
ControllerException
NonHandleableException
protected void transition(String newState,
Class externalController,
ControllerRequest req,
ControllerResponse res)
throws ControllerException,
NonHandleableException
newState - the new state to transition toexternalController - the class of the external controllerreq - the ControllerRequest parameter that the state handler hasres - the ControllerResponse object that was passed to your state method
ControllerException - upon error
NonHandleableException - upon fatal error
protected void transition(String newState,
ControllerRequest req,
ControllerResponse res,
boolean clear)
throws ControllerException,
NonHandleableException
newState - the state to transition toreq - The ControllerRequest object that has been given your state
handlerres - The ControllerResponse object that has been given to your
state handlerclear - Should existing ControllerElements (Input/Output/Block/Transition)
be removed from the resulting ControllerResponse (set to true if that is the
desired behavior)
ControllerException - upon error
NonHandleableException - upon fatal error
protected void unloadStateForm(StateForm stateForm,
org.apache.struts.action.ActionForm controllerForm)
throws ControllerException
stateForm - The stateForm to unloadcontrollerForm - The associated controllerForm
ControllerException - upon error transferring the data between
the forms.
public void redirectRequest(ControllerRequest request,
ControllerResponse response,
String redirectURL)
throws IOException
request - The ControllerRquest object.response - The ControllerResponse objectredirectURL - The URL to redirect the browser to.
IOException - upon redirect error.public org.apache.log4j.Logger getLogger()
protected void setupSubclassLog()
protected String generateToken(ControllerRequest request)
request - The request we are processing
protected boolean isTokenValid(ControllerRequest request)
true if there is a transaction token stored in
the user's current session, and the value submitted as a request
parameter with this action matches it. Returns false
under any of the following circumstances:
request - The servlet request we are processing
generateToken(com.jcorporate.expresso.core.controller.ControllerRequest),
resetToken(com.jcorporate.expresso.core.controller.ControllerRequest),
saveToken(com.jcorporate.expresso.core.controller.ControllerRequest)protected void resetToken(ControllerRequest request)
request - The servlet request we are processingsaveToken(com.jcorporate.expresso.core.controller.ControllerRequest),
isTokenValid(com.jcorporate.expresso.core.controller.ControllerRequest)protected void saveToken(ControllerRequest request)
request - The servlet request we are processingresetToken(com.jcorporate.expresso.core.controller.ControllerRequest),
isTokenValid(com.jcorporate.expresso.core.controller.ControllerRequest)
public static String[] getParamValues(ServletControllerRequest request,
String paramName)
request - cast ControllerRequest to get required typeparamName - key to look for among all parameters
|
Expresso 5-6 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||