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 @Override // HybsProcess 075 public void putArgument( final String arg ) { 076 argments.putArgument( arg ) ; 077 } 078 079 /** 080 * Argument の文字列から、プロパティをセットします。 081 * [プロパティ]のキー部の大文字・小文字は、厳格に判定しています。 082 * このメソッドは、引数 や コメントの判断を行いません。プロパティ のみ 083 * 設定されるものとして、処理します。 084 * プロパティの key=val が初めから分割されている場合の簡易メソッドです。 085 * 086 * @param key キー 087 * @param val 値 088 */ 089 @Override // HybsProcess 090 public void putArgument( final String key,final String val ) { 091 argments.putArgument( key,val ) ; 092 } 093 094 /** 095 * 引数形式を解析する 引数オブジェクトを返します。 096 * 097 * @return 引数オブジェクト 098 */ 099 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}