001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.hayabusa.taglib; 017 018import org.opengion.hayabusa.common.HybsSystemException; 019import org.opengion.fukurou.process.HybsProcess; 020import org.opengion.fukurou.process.Process_DBParam; 021import org.opengion.fukurou.util.StringUtil; 022import org.opengion.fukurou.util.ToString; // 6.1.1.0 (2015/01/17) 023 024import static org.opengion.fukurou.util.StringUtil.nval ; 025 026/** 027 * MainProcess で実行される Processクラスを構築します。 028 * 029 * 親クラス(Process)は、org.opengion.fukurou.process パッケージの HybsProcess 030 * インターフェースを実装したクラスの、Process_****.java の **** 部分を指定します。 031 * 共通的な パラメータは、このTagクラスに実装しますが、それぞれ、個別に必要な 032 * パラメータは、ParamTag を使用して指定します。 033 * このタグは、MainProcess タグの内部にのみ、記述可能です。 034 * 035 * @og.formSample 036 * ●形式:<og:process processID="ZZZ" > 037 * <og:param key="AAA" value="111" /> 038 * </og:process > 039 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します) 040 * 041 * ●Tag定義: 042 * <og:process 043 * processID ○【TAG】リクエスト情報 に登録するキーをセットします(必須)。 044 * caseKey 【TAG】このタグ自体を利用するかどうかの条件キーを指定します(初期値:null) 045 * caseVal 【TAG】このタグ自体を利用するかどうかの条件値を指定します(初期値:null) 046 * caseNN 【TAG】指定の値が、null/ゼロ文字列 でない場合(Not Null=NN)は、このタグは使用されます(初期値:判定しない) 047 * caseNull 【TAG】指定の値が、null/ゼロ文字列 の場合は、このタグは使用されます(初期値:判定しない) 048 * caseIf 【TAG】指定の値が、true/TRUE文字列の場合は、このタグは使用されます(初期値:判定しない) 049 * debug 【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false) 050 * > ... Body ... 051 * </og:process> 052 * 053 * ●使用例 054 * 一般的な変数の渡し方 055 * <og:mainProcess > 056 * <og:process processID="DBReader" > 057 * <og:param key="dbid" value="FROM" /> 058 * <og:param key="sql" value="select * from GE02" /> 059 * </og:process > 060 * <og:process processID="DBWriter" > 061 * <og:param key="dbid" value="TO" /> 062 * <og:param key="table" value="GE02" /> 063 * </og:process > 064 * </og:mainProcess > 065 * 066 * BODY 部に記述した変数の渡し方 067 * <og:process processID="DBReader" > 068 * <og:param key="SQL" > 069 * SELECT COUNT(*) FROM GEA03 070 * WHERE SYSTEM_ID=[SYSTEM_ID] 071 * AND CLM=[CLM] 072 * AND FGJ = '1' 073 * </og:param> 074 * </og:process > 075 * 076 * @og.group リアルバッチ系 077 * 078 * @version 4.0 079 * @author Kazuhiko Hasegawa 080 * @since JDK5.0, 081 */ 082public class ProcessTag extends CommonTagSupport { 083 /** このプログラムのVERSION文字列を設定します。 {@value} */ 084 private static final String VERSION = "6.4.2.0 (2016/01/29)" ; 085 private static final long serialVersionUID = 642020160129L ; 086 087 private static final String PRCS = "org.opengion.fukurou.process.Process_" ; 088 089 private transient HybsProcess process ; 090 private String processID ; 091 092 /** 093 * デフォルトコンストラクター 094 * 095 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 096 */ 097 public ProcessTag() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 098 099 /** 100 * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。 101 * 102 * @og.rev 4.3.1.1 (2008/09/04) DBParam 使用時は、専用の初期化メソッドを呼ぶ 103 * @og.rev 6.3.4.0 (2015/08/01) caseKey,caseVal,caseNN,caseNull,caseIf 属性対応 104 * 105 * @return 後続処理の指示( EVAL_BODY_BUFFERED ) 106 */ 107 @Override 108 public int doStartTag() { 109 if( !useTag() ) { return SKIP_BODY ; } // 6.3.4.0 (2015/08/01) 110 111 final MainProcessTag mainProcess = (MainProcessTag)findAncestorWithClass( this,MainProcessTag.class ); 112 if( mainProcess == null ) { 113 final String errMsg = "<b>" + getTagName() + "タグは、MainProcessTagの内側(要素)に記述してください。</b>" 114 + "processID=" + processID ; 115 throw new HybsSystemException( errMsg ); 116 } 117 118 // 4.3.1.1 (2008/09/04) DBParam 使用時は、専用の初期化メソッドを呼ぶ 119 if( "DBParam".equals( processID ) ) { 120 process = new Process_DBParam(); 121 ((Process_DBParam)process).setAppInfo( getApplicationInfo() ); 122 } 123 else { 124 process = (HybsProcess)StringUtil.newInstance( PRCS + processID ); 125 } 126 127 mainProcess.addProcess( process ); 128 129 return EVAL_BODY_BUFFERED ; // Body を評価する 130 } 131 132 /** 133 * タグリブオブジェクトをリリースします。 134 * キャッシュされて再利用されるので、フィールドの初期設定を行います。 135 * 136 */ 137 @Override 138 protected void release2() { 139 super.release2(); 140 processID = null; 141 process = null; 142 } 143 144 /** 145 * 【TAG】リクエスト情報 に登録するキーをセットします。 146 * 147 * @og.tag 148 * processID は、org.opengion.fukurou.process.HybsProcess インターフェースを実装した 149 * Process_**** クラスの **** を与えます。 150 * これらは、HybsProcess インターフェースを継承したサブクラスである必要があります。 151 * 標準で、org.opengion.fukurou.process 以下の Process_**** クラスが、Process_**** 宣言 と 152 * して、定義されています。 153 * 属性クラス定義の {@link org.opengion.fukurou.process.HybsProcess HybsProcess} を参照願います。 154 * {@og.doc03Link process Process_**** クラス} 155 * 156 * @param pid リクエスト情報に登録するキー 157 * @see org.opengion.fukurou.process.HybsProcess HybsProcessのサブクラス 158 */ 159 public void setProcessID( final String pid ) { 160 processID = nval( getRequestParameter( pid ),processID ) ; 161 } 162 163 /** 164 * 親クラスに登録するキーをセットします。 165 * 166 * @param key 登録するキー 167 * @param value 登録する値 168 */ 169 protected void addParam( final String key,final String value ) { 170 process.putArgument( key,value ); 171 } 172 173 /** 174 * このオブジェクトの文字列表現を返します。 175 * 基本的にデバッグ目的に使用します。 176 * 177 * @return このクラスの文字列表現 178 * @og.rtnNotNull 179 */ 180 @Override 181 public String toString() { 182 return ToString.title( this.getClass().getName() ) 183 .println( "VERSION" ,VERSION ) 184 .println( "processID" ,processID ) 185 .fixForm().toString() ; 186 } 187}