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.fukurou.process; 017 018import org.opengion.fukurou.util.Argument; 019import org.opengion.fukurou.system.HybsConst; // 6.1.0.0 (2014/12/26) refactoring 020 021import java.util.Map; 022 023/** 024 * AbstractProcess は、ChainProcess インターフェースを実装した、Abstract クラスです。 025 * ChainProcess を用いて、順次、バッチプロセスを実行することができます。 026 * 027 * @version 4.0 028 * @author Kazuhiko Hasegawa 029 * @since JDK5.0, 030 */ 031public abstract class AbstractProcess implements HybsProcess { 032 033 /** システムの改行コードを設定します。*/ 034 protected static final String CR = HybsConst.CR; // 6.1.0.0 (2014/12/26) refactoring 035 /** StringBilderなどの初期値を設定します。 {@value} */ 036 protected static final int BUFFER_MIDDLE = HybsConst.BUFFER_MIDDLE; // 6.1.0.0 (2014/12/26) refactoring 037 /** StringBilderなどの初期値を設定します。 {@value} */ 038 protected static final int BUFFER_LARGE = HybsConst.BUFFER_LARGE; // 6.1.0.0 (2014/12/26) refactoring 039 040 /** データ検索時のフェッチサイズを設定します。 {@value} */ 041 protected static final int DB_BATCH_SIZE = HybsConst.DB_BATCH_SIZE; // 6.9.4.1 (2018/04/09) 042 043 /** タブセパレータ */ 044 public static final char TAB = '\t'; // 6.0.2.5 (2014/10/31) タブ区切り文字を char 化します。 045 046 private final Argument argments ; 047 private LoggerProcess logger ; 048 049 /** 050 * コンストラクター 051 * 052 * @param name このクラス(サブクラス)のクラス名称 053 * @param MUST_PROPARTY 必須チェックMap 054 * @param USABLE_PROPARTY 整合性チェックMap 055 */ 056 public AbstractProcess( final String name , final Map<String,String> MUST_PROPARTY ,final Map<String,String> USABLE_PROPARTY ) { 057 argments = new Argument( name ) ; 058 argments.setMustProparty( MUST_PROPARTY ); 059 argments.setUsableProparty( USABLE_PROPARTY ); 060 } 061 062 /** 063 * 引数形式を解析する 引数オブジェクトに、引数を設定します。 064 * Argument の文字列から、引数かプロパティをセットします。 065 * [プロパティ]のキー部の大文字・小文字は、厳格に判定しています。 066 * Argument の文字列には、タイプがあります。 067 * 068 * [コメント] : # で始まる引数で、使用されません。(登録もされません。) 069 * [引数] : #,-,= 以外で始まる通常の文字列。登録の順番が指定されます。 070 * [プロパティ]: - で始まり、キーと値を=で区切っているパラメータです。順序は無関係。 071 * 072 * @param arg 引数 073 */ 074 public void putArgument( final String arg ) { 075 argments.putArgument( arg ) ; 076 } 077 078 /** 079 * Argument の文字列から、プロパティをセットします。 080 * [プロパティ]のキー部の大文字・小文字は、厳格に判定しています。 081 * このメソッドは、引数 や コメントの判断を行いません。プロパティ のみ 082 * 設定されるものとして、処理します。 083 * プロパティの key=val が初めから分割されている場合の簡易メソッドです。 084 * 085 * @param key キー 086 * @param val 値 087 */ 088 public void putArgument( final String key,final String val ) { 089 argments.putArgument( key,val ) ; 090 } 091 092 /** 093 * 引数形式を解析する 引数オブジェクトを返します。 094 * 095 * @return 引数オブジェクト 096 */ 097 public Argument getArgument() { 098 return argments ; 099 } 100 101 /** 102 * ディスプレイにメッセージを表示します。 103 * 104 * @param msg 表示するメッセージ 105 */ 106 public void println( final String msg ) { 107 if( logger != null ) { 108 logger.println( msg ) ; 109 } 110 } 111 112 /** 113 * ディスプレイにメッセージを表示します。 114 * 115 * @param msg 表示するメッセージ 116 */ 117 public void logging( final String msg ) { 118 if( logger != null ) { 119 logger.logging( msg ) ; 120 } 121 } 122 123 /** 124 * ディスプレイ出力する LoggerProcess オブジェクトをセットします。 125 * 126 * @param logger LoggerProcessオブジェクト 127 */ 128 public final void setLoggerProcess( final LoggerProcess logger ) { 129 this.logger = logger ; 130 } 131 132 /** 133 * エラー発生時に、RuntimeException を throw するか、ログ出力します。 134 * 引数に、エラーメッセージを指定します。 135 * isAbend引数は、RuntimeException を throw するか、ログ出力するかを指定する 136 * 引数です。true で、RuntimeException を throw し、false で、ログ出力 137 * のみとします。(つまり、継続処理されます。) 138 * 139 * @og.rev 6.3.1.1 (2015/07/10) RuntimeException を throwする機能を追加 140 * 141 * @param errMsg エラーメッセージ 142 * @param isAbend 異常発生時に、処理を中断(true)するか、継続(false)するか 143 */ 144 public void throwException( final String errMsg , final boolean isAbend ) { 145 throwException( errMsg,null,isAbend ); 146 } 147 148 /** 149 * エラー発生時に、RuntimeException を throw するか、ログ出力します。 150 * 引数に、エラーメッセージと、発生元 Throwable を指定します。 151 * 発生元 Throwable が null の場合は、エラーメッセージのみで throw します。 152 * isAbend引数は、RuntimeException を throw するか、ログ出力するかを指定する 153 * 引数です。true で、RuntimeException を throw し、false で、ログ出力 154 * のみとします。(つまり、継続処理されます。) 155 * 156 * @og.rev 6.3.1.1 (2015/07/10) RuntimeException を throwする機能を追加 157 * 158 * @param errMsg エラーメッセージ 159 * @param th 発生元 Throwable 160 * @param isAbend 異常発生時に、処理を中断(true)するか、継続(false)するか 161 */ 162 public void throwException( final String errMsg,final Throwable th,final boolean isAbend ) { 163 if( isAbend ) { 164 throw th == null ? new RuntimeException( errMsg ) : new RuntimeException( errMsg,th ); 165 } 166 else { 167 logging( "=================================================================" ); 168 if( errMsg != null ) { logging( errMsg ); } 169 if( th != null ) { logging( th.getMessage() ); } 170 } 171 } 172 173 /** 174 * プロセスの内容表示を行います。 175 * Argument#toString() を呼び出しています。 176 * 177 * @return 内容表示 178 */ 179 @Override 180 public String toString() { 181 return argments.toString(); 182 } 183}