P
- ビジネスロジックへの入力値となるJavaBeanを指定するpublic abstract class AbstractBLogicAction<P> extends ActionEx
ビジネスロジックの起動を行うアクションクラスに共通する機能を 集約した抽象クラスである。全てのビジネスロジック起動アクションクラスは このクラスを継承して実装する。 BLogicActionもこのクラスを継承している。 提供する機能一覧は下記のとおりである。
ビジネスロジック起動アクションクラスは、 Bean定義ファイルにて起動するビジネスロジックを設定した上で、 実行する。 下記の例は、ビジネスロジックであるSampleBLogicをSampleActionから 起動するための設定である。 あわせてstruts-config.xmlの設定例も以下に示す。
Bean定義ファイルの設定
<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>
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>
また、ビジネスロジックの実行に失敗した場合などで、 メッセージを設定したい際は、次のようにBLogicResultにメッセージを格納する。
public BLogicResult doExecuteBLogic(ParamsBean params) {
// BLogicResultを生成する。
BLogicResult result = new BLogicResult();
・・・
//ビジネスロジック
・・・
//エラー判定
if (// エラー判定処理 ) {
// Web層にに反映すべき情報を設定する。
・・・
return result;
} else {
// ビジネスロジック内のエラーが発生
// BLogicMessagesを生成
BLogicMessages messages = new BLogicMessages();
// GROUP_ERRORグループのメッセージとして、BLogicMessageを格納
messages.add("GROUP_ERROR", new BLogicMessage("message.error.sample", "sample"));
// エラー用BLogicMessagesをBLogicResultに設定
result.setErrors(messages);
// 実行結果に"failure"を指定
result.setResultString("failure");
return result;
}
}
下記のように、<property>要素の"saveMessageScope"に、
ビジネスロジック内で生成したBLogicMessagesの保存先を
"request"または"session"のいずれかで指定することができる。
プロパティ定義を省略した場合は"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>
修飾子とタイプ | フィールドと説明 |
---|---|
protected static String |
BLOGIC_FORM_ILLEGAL_ERROR
拡張アクションフォーム設定エラー時のエラーコード。
|
protected static String |
BLOGIC_MAPPING_ILLEGAL_ERROR
拡張アクションマッピング設定エラー時のエラーコード。
|
protected static String |
BLOGIC_RESOURCES_ILLEGAL_ERROR
拡張アクションリソース設定エラー時のエラーコード。
|
protected static String |
BLOGIC_RESULT_NULL_ERROR
BLogicResultがnullで返却された時のエラーコード。
|
protected static String |
NULL_MAPPER_KEY
AbstractBLogicMapperがnullだった場合のエラーコード。
|
FORWARD_TXTOKEN_ERROR
コンストラクタと説明 |
---|
AbstractBLogicAction() |
修飾子とタイプ | メソッドと説明 |
---|---|
protected org.apache.struts.action.ActionMessages |
convertMessages(BLogicMessages blogicMessages)
BLogicMessagesの内容を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)
ビジネスロジックを実行する。
|
abstract BLogicResult |
doExecuteBLogic(P param)
ビジネスロジック実行抽象メソッド。
|
protected void |
evaluateBLogicResult(BLogicResult result,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
ActionMappingEx mappingEx)
BLogicResultの評価、Web層のオブジェクトへの結果反映を行う。
|
protected BLogicIO |
getBLogicIO(org.apache.struts.action.ActionMapping mapping,
javax.servlet.http.HttpServletRequest request)
BLogicIOを取得する。
|
protected AbstractBLogicMapper |
getBLogicMapper(javax.servlet.http.HttpServletRequest req)
BLogicMapperインスタンスを取得する。
|
protected P |
getBLogicParams(ActionMappingEx mapping,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
paramsを生成し、返却する。
|
protected boolean |
isErrorsEmpty(BLogicResult result)
BLogicResultに格納されているエラー情報が
nullであるか空であるとき、trueを返却する。
|
protected void |
postDoExecuteBLogic(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
P params,
BLogicResult result)
ビジネスロジックの実行後処理。
|
protected void |
preDoExecuteBLogic(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
P params)
ビジネスロジックの実行前処理。
|
protected void |
processBLogicResult(BLogicResult result,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
ActionMappingEx mappingEx)
BLogicResultからWeb層のオブジェクトへの結果反映を行う。
|
void |
setSaveMessageScope(String saveMessageScope)
メッセージ保存先スコープを設定する。
|
addErrors, addMessages, execute, isSaveToken, isTokenCheck, processTokenCheck, setSaveToken, setTokenCheck
addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
protected static final String BLOGIC_FORM_ILLEGAL_ERROR
protected static final String BLOGIC_MAPPING_ILLEGAL_ERROR
protected static final String BLOGIC_RESOURCES_ILLEGAL_ERROR
protected static final String BLOGIC_RESULT_NULL_ERROR
public void setSaveMessageScope(String saveMessageScope)
saveMessageScope
- メッセージ保存先スコープ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 Exception
ビジネスロジックの実行に必要な下記の共通処理を行う。
protected void preDoExecuteBLogic(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, P params) throws Exception
request
- リクエストresponse
- レスポンスparams
- パラメータ(JavaBean)Exception
- 予期しない例外protected void postDoExecuteBLogic(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, P params, BLogicResult result) throws Exception
ビジネスロジックで例外が発生しなかった場合のみ、実行される。
request
- リクエストresponse
- レスポンスparams
- パラメータ(JavaBean)result
- ビジネスロジック実行結果Exception
- 予期しない例外protected void evaluateBLogicResult(BLogicResult result, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionMappingEx mappingEx)
result
- BLogicResultインスタンスrequest
- HTTPリクエストresponse
- HTTPレスポンスmappingEx
- 拡張アクションマッピングprotected void processBLogicResult(BLogicResult result, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionMappingEx mappingEx)
result
- BLogicResultインスタンスrequest
- HTTPリクエストresponse
- HTTPレスポンスmappingEx
- 拡張アクションマッピングprotected org.apache.struts.action.ActionMessages convertMessages(BLogicMessages blogicMessages)
blogicMessages
- BLogicMessagesインスタンスpublic abstract BLogicResult doExecuteBLogic(P param) throws Exception
param
- ビジネスロジック入力情報Exception
- 予期しない例外protected boolean isErrorsEmpty(BLogicResult result)
result
- ビジネスロジック実行結果protected AbstractBLogicMapper getBLogicMapper(javax.servlet.http.HttpServletRequest req)
req
- HTTPリクエストprotected P getBLogicParams(ActionMappingEx mapping, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception
mapping
- アクションマッピングrequest
- HTTPリクエストresponse
- HTTPレスポンスException
- 予期しない例外protected BLogicIO getBLogicIO(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
mapping
- アクションマッピングrequest
- HTTPリクエストCopyright © 2014. All Rights Reserved.