OSDN Git Service

Ver8.5.2.0
[opengion/opengionV8.git] / uap / webapps / gf / src / org / opengion / fukurou / process / AbstractProcess.java
1 /*
2  * Copyright (c) 2009 The openGion Project.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific language
14  * governing permissions and limitations under the License.
15  */
16 package org.opengion.fukurou.process;
17
18 import org.opengion.fukurou.util.Argument;
19 import org.opengion.fukurou.system.HybsConst;                           // 6.1.0.0 (2014/12/26) refactoring
20
21 import java.util.Map;
22
23 /**
24  * AbstractProcess は、ChainProcess インターフェースを実装した、Abstract クラスです。
25  * ChainProcess を用いて、順次、バッチプロセスを実行することができます。
26  *
27  * @version  4.0
28  * @author   Kazuhiko Hasegawa
29  * @since    JDK5.0,
30  */
31 public abstract class AbstractProcess implements HybsProcess {
32
33         /** システムの改行コードを設定します。*/
34         protected static final String CR                 = HybsConst.CR;                        // 6.1.0.0 (2014/12/26) refactoring
35         /** StringBilderなどの初期値を設定します。 {@value} */
36         protected static final int BUFFER_MIDDLE = HybsConst.BUFFER_MIDDLE;     // 6.1.0.0 (2014/12/26) refactoring
37         /** StringBilderなどの初期値を設定します。 {@value} */
38         protected static final int BUFFER_LARGE  = HybsConst.BUFFER_LARGE;      // 6.1.0.0 (2014/12/26) refactoring
39
40         /** データ検索時のフェッチサイズを設定します。     {@value} */
41         protected static final int DB_BATCH_SIZE  = HybsConst.DB_BATCH_SIZE;    // 6.9.4.1 (2018/04/09)
42
43         /** タブセパレータ */
44         public static final char TAB = '\t';    // 6.0.2.5 (2014/10/31) タブ区切り文字を char 化します。
45
46         private final Argument argments ;
47         private LoggerProcess logger    ;
48
49         /**
50          * コンストラクター
51          *
52          * @param       name                    このクラス(サブクラス)のクラス名称
53          * @param   MUST_PROPARTY       必須チェックMap
54          * @param   USABLE_PROPARTY     整合性チェックMap
55          */
56         public AbstractProcess( final String name , final Map<String,String> MUST_PROPARTY ,final Map<String,String> USABLE_PROPARTY ) {
57                 argments = new Argument( name ) ;
58                 argments.setMustProparty( MUST_PROPARTY );
59                 argments.setUsableProparty( USABLE_PROPARTY );
60         }
61
62         /**
63          * 引数形式を解析する 引数オブジェクトに、引数を設定します。
64          * Argument の文字列から、引数かプロパティをセットします。
65          * [プロパティ]のキー部の大文字・小文字は、厳格に判定しています。
66          * Argument の文字列には、タイプがあります。
67          *
68          * [コメント]  : # で始まる引数で、使用されません。(登録もされません。)
69          * [引数]      : #,-,= 以外で始まる通常の文字列。登録の順番が指定されます。
70          * [プロパティ]: - で始まり、キーと値を=で区切っているパラメータです。順序は無関係。
71          *
72          * @param   arg 引数
73          */
74         @Override       // HybsProcess
75         public void putArgument( final String arg ) {
76                 argments.putArgument( arg ) ;
77         }
78
79         /**
80          * Argument の文字列から、プロパティをセットします。
81          * [プロパティ]のキー部の大文字・小文字は、厳格に判定しています。
82          * このメソッドは、引数 や コメントの判断を行いません。プロパティ のみ
83          * 設定されるものとして、処理します。
84          * プロパティの key=val が初めから分割されている場合の簡易メソッドです。
85          *
86          * @param   key キー
87          * @param   val 値
88          */
89         @Override       // HybsProcess
90         public void putArgument( final String key,final String val ) {
91                 argments.putArgument( key,val ) ;
92         }
93
94         /**
95          * 引数形式を解析する 引数オブジェクトを返します。
96          *
97          * @return      引数オブジェクト
98          */
99         public Argument getArgument() {
100                 return argments ;
101         }
102
103         /**
104          * ディスプレイにメッセージを表示します。
105          *
106          * @param       msg     表示するメッセージ
107          */
108         @Override       // HybsProcess
109         public void println( final String msg ) {
110                 if( logger != null ) {
111                         logger.println( msg ) ;
112                 }
113         }
114
115         /**
116          * ディスプレイにメッセージを表示します。
117          *
118          * @param       msg     表示するメッセージ
119          */
120         @Override       // HybsProcess
121         public void logging( final String msg ) {
122                 if( logger != null ) {
123                         logger.logging( msg ) ;
124                 }
125         }
126
127         /**
128          * ディスプレイ出力する LoggerProcess オブジェクトをセットします。
129          *
130          * @param logger LoggerProcessオブジェクト
131          */
132         @Override       // HybsProcess
133         public final void setLoggerProcess( final LoggerProcess logger ) {
134                 this.logger = logger ;
135         }
136
137         /**
138          * エラー発生時に、RuntimeException を throw するか、ログ出力します。
139          * 引数に、エラーメッセージを指定します。
140          * isAbend引数は、RuntimeException を throw するか、ログ出力するかを指定する
141          * 引数です。true で、RuntimeException を throw し、false で、ログ出力
142          * のみとします。(つまり、継続処理されます。)
143          *
144          * @og.rev 6.3.1.1 (2015/07/10) RuntimeException を throwする機能を追加
145          *
146          * @param       errMsg  エラーメッセージ
147          * @param       isAbend 異常発生時に、処理を中断(true)するか、継続(false)するか
148          */
149         public void throwException( final String errMsg , final boolean isAbend ) {
150                 throwException( errMsg,null,isAbend );
151         }
152
153         /**
154          * エラー発生時に、RuntimeException を throw するか、ログ出力します。
155          * 引数に、エラーメッセージと、発生元 Throwable を指定します。
156          * 発生元 Throwable が null の場合は、エラーメッセージのみで throw します。
157          * isAbend引数は、RuntimeException を throw するか、ログ出力するかを指定する
158          * 引数です。true で、RuntimeException を throw し、false で、ログ出力
159          * のみとします。(つまり、継続処理されます。)
160          *
161          * @og.rev 6.3.1.1 (2015/07/10) RuntimeException を throwする機能を追加
162          *
163          * @param       errMsg  エラーメッセージ
164          * @param       th              発生元 Throwable
165          * @param       isAbend 異常発生時に、処理を中断(true)するか、継続(false)するか
166          */
167         public void throwException( final String errMsg,final Throwable th,final boolean isAbend ) {
168                 if( isAbend ) {
169                         throw th == null ? new RuntimeException( errMsg ) : new RuntimeException( errMsg,th );
170                 }
171                 else {
172                         logging( "=================================================================" );
173                         if( errMsg != null ) { logging( errMsg ); }
174                         if( th     != null ) { logging( th.getMessage() ); }
175                 }
176         }
177
178         /**
179          * プロセスの内容表示を行います。
180          * Argument#toString() を呼び出しています。
181          *
182          * @return 内容表示
183          */
184         @Override       // Object
185         public String toString() {
186                 return argments.toString();
187         }
188 }