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     */
016    package org.opengion.hayabusa.taglib;
017    
018    import org.opengion.hayabusa.common.HybsSystemException;
019    
020    import static org.opengion.fukurou.util.StringUtil.nval ;
021    import org.opengion.fukurou.util.StringUtil;
022    import org.opengion.fukurou.process.HybsProcess;
023    import org.opengion.fukurou.process.Process_DBParam;
024    
025    import java.io.ObjectOutputStream;
026    import java.io.ObjectInputStream;
027    import java.io.IOException;
028    
029    /**
030     * MainProcess で実行される Processクラスを構築しますã?
031     *
032     * 親クラス(Process)は、org.opengion.fukurou.process パッケージの HybsProcess
033     * インターフェースを実è£?�—たクラスの、Process_****.java の **** 部åˆ?‚’æŒ?®šしますã?
034     * 共通的な パラメータは、このTagクラスに実è£?�—ますが、それぞれã?個別にå¿?¦�な
035     * パラメータは、ParamTag を使用してæŒ?®šしますã?
036     * こã?タグは、MainProcess タグのå†?ƒ¨にのみ、記述可能ですã?
037     *
038     * @og.formSample
039     * ●形式ï¼?lt;og:process processID="ZZZ" >
040     *             <og:param key="AAA" value="111" />
041     *         </og:process >
042     * ●body?šあã‚?EVAL_BODY_BUFFERED:BODYを評価しã?{@XXXX} を解析しまã�?
043     *
044     * ●Tag定義??
045     *   <og:process
046     *       processID        ○ã?TAG】リクエスト情報 に登録するキーをセãƒ?ƒˆしますã?(å¿??)
047     *       debug              【TAG】デバッグæƒ??をå?力するかどã�?�‹[true/false]を指定しまã�?初期値:false)
048     *   >   ... Body ...
049     *   </og:process>
050     *
051     * ●使用ä¾?
052     *     ä¸?ˆ¬çš?�ª変数の渡し方
053     *   <og:mainProcess >
054     *     <og:process processID="DBReader" >
055     *        <og:param key="dbid" value="FROM" />
056     *        <og:param key="sql"  value="select * from GE02" />
057     *     </og:process >
058     *     <og:process processID="DBWriter" >
059     *        <og:param key="dbid"  value="TO" />
060     *        <og:param key="table" value="GE02" />
061     *     </og:process >
062     *   </og:mainProcess >
063     *
064     *     BODY 部に記述した変数の渡し方
065     *     <og:process processID="DBReader" >
066     *        <og:param key="SQL" >
067     *              SELECT COUNT(*) FROM GEA03
068     *              WHERE SYSTEM_ID=[SYSTEM_ID]
069     *              AND   CLM=[CLM]
070     *              AND   FGJ = '1'
071     *        </og:param>
072     *     </og:process >
073     *
074     * @og.group リアルバッチ系
075     *
076     * @version  4.0
077     * @author       Kazuhiko Hasegawa
078     * @since    JDK5.0,
079     */
080    public class ProcessTag extends CommonTagSupport {
081            //* こã?プログラãƒ??VERSIONæ–?­—å?を設定しますã?       {@value} */
082            private static final String VERSION = "4.3.1.1 (2008/09/04)" ;
083    
084            private static final long serialVersionUID = 431120080904L ;
085    
086            private static final String PRCS = "org.opengion.fukurou.process.Process_" ;
087    
088            private String          processID       = null;
089            private transient HybsProcess   process         = null;
090    
091            /**
092             * Taglibの開始タグが見つかったときに処ç�?�™ã‚?doStartTag() ã‚?オーバã?ライドしますã?
093             *
094             * @og.rev 4.3.1.1 (2008/09/04) DBParam 使用時ã?、専用の初期化メソãƒ?ƒ‰を呼ぶ
095             *
096             * @return      後続å?ç�??æŒ?¤º( EVAL_BODY_BUFFERED )
097             */
098            @Override
099            public int doStartTag() {
100    //              process = (HybsProcess)StringUtil.newInstance( PRCS + processID );
101    //              if( process == null ) {
102    //                      String errMsg = "<b>æŒ?®šã? processID を持つ HybsProcess が見つかりませんã€?/b>"
103    //                                                              + "processID=" + processID ;
104    //                      throw new HybsSystemException( errMsg );
105    //              }
106    
107                    MainProcessTag mainProcess = (MainProcessTag)findAncestorWithClass( this,MainProcessTag.class );
108                    if( mainProcess == null ) {
109                            String errMsg = "<b>こã?タグは、MainProcessTagのå†??(要ç´?に記述してくださいã€?/b>"
110                                                                    + "processID=" + processID ;
111                            throw new HybsSystemException( errMsg );
112                    }
113    
114                    // 4.3.1.1 (2008/09/04) DBParam 使用時ã?、専用の初期化メソãƒ?ƒ‰を呼ぶ
115                    if( "DBParam".equals( processID ) ) {
116                            process = new Process_DBParam();
117                            ((Process_DBParam)process).setAppInfo( getApplicationInfo() );
118                    }
119                    else {
120                            process = (HybsProcess)StringUtil.newInstance( PRCS + processID );
121                    }
122    
123                    mainProcess.addProcess( process );
124    
125                    return ( EVAL_BODY_BUFFERED );          // Body を評価する
126            }
127    
128            /**
129             * タグリブオブジェクトをリリースしますã?
130             * キャãƒ?‚·ュされて再利用されるã?で、フィールドã?初期設定を行いますã?
131             *
132             */
133            @Override
134            protected void release2() {
135                    super.release2();
136                    processID       = null;
137                    process         = null;
138            }
139    
140            /**
141             * 【TAG】リクエスト情報 に登録するキーをセãƒ?ƒˆしますã?
142             *
143             * @og.tag
144             * processID は、org.opengion.fukurou.process.HybsProcess インターフェースを実è£?�—ã�?
145             * Process_**** クラスの **** を与えますã?
146             * これらã?、HybsProcess インターフェースを継承したサブクラスであるå¿?¦�がありますã?
147             * 標準で、org.opengion.fukurou.process 以下ã? Process_**** クラスがã?Process_**** 宣è¨?と
148             * して、定義されてã�?�¾すã?
149             * 属æ?クラス定義の {@link org.opengion.fukurou.process.HybsProcess HybsProcess} を参照願いますã?
150             * {@og.doc03Link process Process_**** クラス}
151             *
152             * @param       pid リクエスト情報に登録するキー
153             * @see         org.opengion.fukurou.process.HybsProcess  HybsProcessのサブクラス
154             */
155            public void setProcessID( final String pid ) {
156                    processID = nval( getRequestParameter( pid ),processID ) ;
157            }
158    
159            /**
160             * 親クラスに登録するキーをセãƒ?ƒˆしますã?
161             *
162             * @param       key             登録するキー
163             * @param       value   登録する値
164             */
165            protected void addParam( final String key,final String value ) {
166                    process.putArgument( key,value );
167            }
168    
169            /**
170             * シリアライズ用のカスタãƒ?‚·リアライズ書き込みメソãƒ?ƒ‰
171             *
172             * @og.rev 4.0.0.0 (2006/09/31) 新規追åŠ?
173             * @serialData
174             *
175             * @param       strm    ObjectOutputStreamオブジェクãƒ?
176             */
177            private void writeObject( final ObjectOutputStream strm ) throws IOException {
178                    strm.defaultWriteObject();
179            }
180    
181            /**
182             * シリアライズ用のカスタãƒ?‚·リアライズ読み込みメソãƒ?ƒ‰
183             *
184             * ここでは、transient 宣è¨?�•れたå†?ƒ¨変数のå†??初期化がå¿?¦�なフィールドã?み設定しますã?
185             *
186             * @og.rev 4.0.0.0 (2006/09/31) 新規追åŠ?
187             * @serialData
188             *
189             * @param       strm    ObjectInputStreamオブジェクãƒ?
190             * @see #release2()
191             */
192            private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException {
193                    strm.defaultReadObject();
194            }
195    
196            /**
197             * こã?オブジェクトã?æ–?­—å?表現を返しますã?
198             * 基本çš?�«ãƒ?ƒ�ãƒ?‚°目çš?�«使用しますã?
199             *
200             * @return こã?クラスのæ–?­—å?表現
201             */
202            @Override
203            public String toString() {
204                    return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
205                                    .println( "VERSION"                             ,VERSION                        )
206                                    .println( "processID"                   ,processID                      )
207                                    .fixForm().toString() ;
208            }
209    }