jp.terasoluna.fw.web.struts.actions
Class AbstractBLogicAction<P>

java.lang.Object
  extended by org.apache.struts.action.Action
      extended by jp.terasoluna.fw.web.struts.actions.ActionEx
          extended by jp.terasoluna.fw.web.struts.actions.AbstractBLogicAction<P>
Type Parameters:
P - Specify the JavaBean which is input value to the business logic.
Direct Known Subclasses:
BLogicAction

public abstract class AbstractBLogicAction<P>
extends ActionEx

Abstract class to invoke the business logic.

This is the abstract class in which the functionalities common for the action class, are consolidated. This action class invokes the business logic. All the action classes which invoke the business logic are implemented by inheriting this class. BLogicAction also inherits this class. Following is the list of provided functionalities.

  1. Fetches the business logic class name from the action settings of struts-config.xml.
  2. Generates JavaBean which is the input information to business logic.
  3. Executes the doExecuteBLogic() method which is the entry point of the inherited class.
  4. Processes BLogicResult after the successful completion of business logic.

After setting the business logic in the Bean definition file, action class which invokes the business logic, is executed. In the following example, the settings to invoke business logic, SampleBLogic from SampleAction are shown. Configuration example of struts-config.xml is also shown below.

Settings of Bean definition file

 <bean name="/SampleAction" scope="prototype"
   class="jp.terasoluna.sample1.actions.SampleAction">
   <property name="sampleBLogic">
     <ref bean="SampleBLogic"></ref>
   </property>
 </bean>
 <bean id="SampleBLogic"
   class="jp.terasoluna.sample1.blogic.SampleBLogic">
 </bean>
 

Settings of struts-config.xml

  <action path="/SampleAction"
    name="_sampleForm"
    validate="true"
    scope="session"
    input="/sample.jsp">
    <forward name="success" path="/sampleSCR.do"/>
    <forward name="failure" path="/errorSCR.do"/>
  </action>
 

For the usage and settings related details of BLogicResult, refer to BLogicIOPlugIn, BLogicResult and AbstractBLogicMapper.

When the business logic execution fails and message needs to be set, store the message in the BLogicResult as shown below.

 public BLogicResult doExecuteBLogic(ParamsBean params) {

     // Generates BLogicResult.
     BLogicResult result = new BLogicResult();
     ...
     //Business logic
     ...
     //Error condition
     if (// Error processing ) {
         // Sets the information which needs to be mapped in Web tier.
         ...
         return result;
     } else {
         // Error occurs in the business logic
         // BLogicMessages are generated
         BLogicMessages messages = new BLogicMessages();
         // Store BLogicMessage as the message of GROUP_ERROR group
         messages.add("GROUP_ERROR", new BLogicMessage("message.error.sample", "sample"));
         // Set BLogicMessages in the BLogicResult
         result.setErrors(messages);
         // Specify "failure" in the execution result
         result.setResultString("failure");
         return result;
     }
 }
 

As shown in the following example, "request" or the "session" can be specified in the "saveMessageScope" of <property> element as the storage location of BLogicMessages. If the property definition is omitted, the BLogicMessages are stored in "request".

 <bean name="/SampleAction" scope="prototype"
   class="jp.terasoluna.sample1.actions.SampleAction">
   <property name="sampleBLogic">
     <ref bean="SampleBLogic"></ref>
   </property>
   <property name="saveMessageScope" value="session"/>
 </bean>
 

See Also:
BLogicAction, BLogicIOPlugIn, BLogicResult, AbstractBLogicMapper, BLogicMapper, BLogicMessage, BLogicMessages

Field Summary
protected static java.lang.String BLOGIC_FORM_ILLEGAL_ERROR
          Error code when the error occurs in the settings of extended action form.
protected static java.lang.String BLOGIC_MAPPING_ILLEGAL_ERROR
          Error code when the error ocurs in the settings of the extended action mapping.
protected static java.lang.String BLOGIC_RESOURCES_ILLEGAL_ERROR
          Error code when the error occursin the settings of the extended action resource.
protected static java.lang.String BLOGIC_RESULT_NULL_ERROR
          Error code when BLogicResult is returned as null.
private static org.apache.commons.logging.Log log
          Log class.
protected static java.lang.String NULL_MAPPER_KEY
          Error code when AbstractBLogicMapper is null.
private  java.lang.String saveMessageScope
          Message storage scope. Specify "request" or "session" as the storage location of the BLogicMessages generated in the busness logic.
 
Fields inherited from class jp.terasoluna.fw.web.struts.actions.ActionEx
FORWARD_TXTOKEN_ERROR
 
Fields inherited from class org.apache.struts.action.Action
defaultLocale, servlet
 
Constructor Summary
AbstractBLogicAction()
           
 
Method Summary
protected  org.apache.struts.action.ActionMessages convertMessages(BLogicMessages blogicMessages)
          Store the contents of BLogicMessages again in the ActionMessages.
 org.apache.struts.action.ActionForward doExecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          executes the business logic.
abstract  BLogicResult doExecuteBLogic(P param)
          Abstract method to execute business logic. To be implemented in the subclass.
protected  void evaluateBLogicResult(BLogicResult result, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionMappingEx mappingEx)
          Evaluates BLogicResult and reflect the result of Web tier object.
protected  BLogicIO getBLogicIO(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
          Fetches BLogicIO.
protected  AbstractBLogicMapper getBLogicMapper(javax.servlet.http.HttpServletRequest req)
          Fetches BLogicMapper instance.
protected  P getBLogicParams(ActionMappingEx mapping, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Generates and returns params.
protected  boolean isErrorsEmpty(BLogicResult result)
          Returns true when the error information stored in the BLogicResult is null or empty.
protected  void postDoExecuteBLogic(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, P params, BLogicResult result)
          Processing after executing the business logic.
protected  void preDoExecuteBLogic(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, P params)
          Processing before executing business logic.
protected  void processBLogicResult(BLogicResult result, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionMappingEx mappingEx)
          Reflects the result to the Web tier object from BLogicResult.
 void setSaveMessageScope(java.lang.String saveMessageScope)
          Sets message storage scope.
 
Methods inherited from class jp.terasoluna.fw.web.struts.actions.ActionEx
addErrors, addMessages, execute, isSaveToken, isTokenCheck, processTokenCheck, setSaveToken, setTokenCheck
 
Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log class


BLOGIC_FORM_ILLEGAL_ERROR

protected static final java.lang.String BLOGIC_FORM_ILLEGAL_ERROR
Error code when the error occurs in the settings of extended action form.

See Also:
Constant Field Values

BLOGIC_MAPPING_ILLEGAL_ERROR

protected static final java.lang.String BLOGIC_MAPPING_ILLEGAL_ERROR
Error code when the error occurs in the settings of extended action mapping.

See Also:
Constant Field Values

BLOGIC_RESOURCES_ILLEGAL_ERROR

protected static final java.lang.String BLOGIC_RESOURCES_ILLEGAL_ERROR
Error code when the error occurs in the settings of extended action resource.

See Also:
Constant Field Values

BLOGIC_RESULT_NULL_ERROR

protected static final java.lang.String BLOGIC_RESULT_NULL_ERROR
Error code when the BLogicResult is returned as null.

See Also:
Constant Field Values

NULL_MAPPER_KEY

protected static final java.lang.String NULL_MAPPER_KEY
Error code when AbstractBLogicMapper is null.

See Also:
Constant Field Values

saveMessageScope

private java.lang.String saveMessageScope
Message storage scope. Specify "request" or "session" as the storage location of the BLogicMessages generated in the busness logic.

Constructor Detail

AbstractBLogicAction

public AbstractBLogicAction()
Method Detail

setSaveMessageScope

public void setSaveMessageScope(java.lang.String saveMessageScope)
Sets message storage scope.

Parameters:
saveMessageScope - Message storage scope

doExecute

public org.apache.struts.action.ActionForward doExecute(org.apache.struts.action.ActionMapping mapping,
                                                        org.apache.struts.action.ActionForm form,
                                                        javax.servlet.http.HttpServletRequest request,
                                                        javax.servlet.http.HttpServletResponse response)
                                                 throws java.lang.Exception
Executes business logic.

Perform the following processes which are commonly required to execute the business logic.

Specified by:
doExecute in class ActionEx
Parameters:
mapping - Action mapping
form - Form
request - Request
response - Response
Returns:
Action forward
Throws:
java.lang.Exception - Unexepected exception thrown from the subclass

preDoExecuteBLogic

protected void preDoExecuteBLogic(javax.servlet.http.HttpServletRequest request,
                                  javax.servlet.http.HttpServletResponse response,
                                  P params)
                           throws java.lang.Exception
Processing before executing the business logic.

Parameters:
request - Request
response - Response
params - Parameter(JavaBean)
Throws:
java.lang.Exception - Unexpected exception

postDoExecuteBLogic

protected void postDoExecuteBLogic(javax.servlet.http.HttpServletRequest request,
                                   javax.servlet.http.HttpServletResponse response,
                                   P params,
                                   BLogicResult result)
                            throws java.lang.Exception
Processing after executing the business logic.

This process is executed only when exception has not occurred in the business logic.

Parameters:
request - Request
response - Response
params - Parameter(JavaBean)
result - Business logic executon result
Throws:
java.lang.Exception - Unexpected exception

evaluateBLogicResult

protected void evaluateBLogicResult(BLogicResult result,
                                    javax.servlet.http.HttpServletRequest request,
                                    javax.servlet.http.HttpServletResponse response,
                                    ActionMappingEx mappingEx)
Evaluates BLogicResult and reflects the result to the Web tier object.

Parameters:
result - BLogicResult instance
request - HTTP request
response - HTTP response
mappingEx - Extended action mapping

processBLogicResult

protected void processBLogicResult(BLogicResult result,
                                   javax.servlet.http.HttpServletRequest request,
                                   javax.servlet.http.HttpServletResponse response,
                                   ActionMappingEx mappingEx)
Reflects the result to Web tier object from BLogicResult.

Parameters:
result - BLogicResult instance
request - HTTP request
response - HTTP response
mappingEx - Extended action mapping

convertMessages

protected org.apache.struts.action.ActionMessages convertMessages(BLogicMessages blogicMessages)
Store the contents of BLogicMessages in the ActionMessages again.

Parameters:
blogicMessages - BLogicMessages instance
Returns:
ActionMessages

doExecuteBLogic

public abstract BLogicResult doExecuteBLogic(P param)
                                      throws java.lang.Exception
Abstract method to execute the business logic. To be implemented in the subclass.

Parameters:
param - Business logic input information
Returns:
Business logic outputinformation
Throws:
java.lang.Exception - Unexpected exception

isErrorsEmpty

protected boolean isErrorsEmpty(BLogicResult result)
Returns true when the error information stored in BLogicResult is null or empty.

Parameters:
result - Business logic execution result
Returns:
true when the LogicMessages are null or empty

getBLogicMapper

protected AbstractBLogicMapper getBLogicMapper(javax.servlet.http.HttpServletRequest req)
Fetches BLogicMapper instance.

Parameters:
req - HTTP request
Returns:
BLogicMapper instance

getBLogicParams

protected P getBLogicParams(ActionMappingEx mapping,
                            javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws java.lang.Exception
Generates and returns params.

Parameters:
mapping - Action mapping
request - HTTP request
response - HTTP response
Returns:
Business logic input information
Throws:
java.lang.Exception - Unexpected exception

getBLogicIO

protected BLogicIO getBLogicIO(org.apache.struts.action.ActionMapping mapping,
                               javax.servlet.http.HttpServletRequest request)
Fetches BLogicIO.

Parameters:
mapping - Action mapping
request - HTTP request
Returns:
Business logic I/O information