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.report; 017 018import java.util.concurrent.ConcurrentMap; // 6.4.3.3 (2016/03/04) 019 020import org.opengion.fukurou.util.Shell; 021import org.opengion.hayabusa.common.HybsSystem; 022import org.opengion.hayabusa.db.DBTableModel; 023import static org.opengion.fukurou.system.HybsConst.CR; // 6.1.0.0 (2014/12/26) refactoring 024import static org.opengion.fukurou.system.HybsConst.BUFFER_MIDDLE; // 6.1.0.0 (2014/12/26) refactoring 025 026/** 027 * RFIDPrintPoint インターフェース のデフォルト実装クラスです。 028 * execute() をオーバーライドして、各種RFIDシステムに対応して下さい。 029 * 030 * @og.group 帳票システム 031 * 032 * @version 4.0 033 * @author Masakazu Takahashi 034 * @since JDK6.0, 035 */ 036public abstract class AbstractRFIDPrintPointService implements RFIDPrintPointService { 037 038 /** エラーメッセージ */ 039 protected final StringBuilder errMsg = new StringBuilder( BUFFER_MIDDLE ); // エラーメッセージ 040 041 /** カラム定義 */ protected String ykno ; 042 /** カラム定義 */ protected String systemId ; 043 /** カラム定義 */ protected String fgrun ; 044 /** カラム定義 */ protected String hostName ; 045 /** カラム定義 */ protected String prtName ; 046 /** カラム定義 */ protected DBTableModel table ; 047 /** カラム定義 */ protected String prgdir ; 048 /** カラム定義 */ protected String prgfile ; 049 /** カラム定義 */ protected String outdir ; 050 // 6.4.3.1 (2016/02/12) 作成元のMapを、HashMap から ConcurrentHashMap に置き換え。 051 /** カラム定義 */ protected ConcurrentMap<String, String[]> rfidLayout; // 6.4.3.3 (2016/03/04) 052 /** カラム定義 */ protected String prtid ; // 5.4.3.0 (2011/12/26) 053 /** カラム定義 */ protected String portnm ; // 5.4.3.1 (2011/12/27) 054 /** カラム定義 */ protected String listid ; // 5.4.3.4 (2012/01/12) 055 /** カラム定義 */ protected String layoutFile ; // 5.4.3.9 (2012/01/25) 056 057 /** カラム定義 */ protected String fgkan = GE50Access.FG_ERR2; // 初期値はアプリエラー 058 /** カラム定義 */ protected String shellCmd ; 059 060 private static final int TIMEOUT = HybsSystem.sysInt( "REPORT_DAEMON_TIMEOUT" ); //Shellタイムアウト 6.3.9.1 (2015/11/27) private static final化 061 062 /** 063 * デフォルトコンストラクター 064 * 065 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 066 */ 067 protected AbstractRFIDPrintPointService() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 068 069 /** 070 * RFID発行処理 071 * RFIDのシステムに応じてこのメソッドをオーバーライドします 072 * 実行後はfgkanの値を正しい値でセットしなおして下さい。 073 * 074 * @return 結果 [true:正常/false:異常] 075 */ 076 public abstract boolean execute(); 077 078 /** 079 * 帳票起動された要求番号をセットします。 080 * 081 * @param no 要求NO 082 */ 083 public void setYkno( final String no ) { 084 ykno = no; 085 } 086 087 /** 088 * システムIDをセットします。 089 * 090 * @param id システムID 091 */ 092 public void setSystemId( final String id ) { 093 systemId = id; 094 } 095 096 /** 097 * 実行方法をセットします。 098 * 099 * @param flag 実行方法 100 */ 101 public void setFgrun( final String flag ) { 102 fgrun = flag; 103 } 104 105 /** 106 * 帳票デーモンが実行されているホスト名をセットします。 107 * 108 * @param host ホスト名 109 */ 110 public void setHostName( final String host ) { 111 hostName = host; 112 } 113 114 /** 115 * プリンター名をセットします。 116 * 117 * @param printerName プリンタ名 118 */ 119 public void setPrinterName( final String printerName ) { 120 prtName = printerName; 121 } 122 123 /** 124 * DBTableModel をセットします。 125 * 126 * @param tbl DBTableModelオブジェクト 127 */ 128 public void setTable( final DBTableModel tbl ) { 129 table = tbl; 130 } 131 132 /** 133 * REPORT_RFID_SERVICE_CLASSから起動するバッチ等のプログラムをセットします。 134 * 135 * @param dir バッチプログラムディレクトリ 136 */ 137 public void setPrgDir( final String dir ){ 138 prgdir = dir; 139 } 140 141 /** 142 * REPORT_RFID_SERVICE_CLASSから起動するバッチ等のプログラムをセットします。 143 * 144 * @param file バッチプログラム名 145 */ 146 public void setPrgFile( final String file ){ 147 prgfile = file; 148 } 149 150 /** 151 * ファイル出力時のディレクトリを指定します。 152 * 153 * @og.rev 4.3.2.2 (2008/09/22) 板金 RFID対応 154 * @param dir ファイル出力ディレクトリ 155 */ 156 public void setOutDir( final String dir ){ 157 outdir = dir; 158 } 159 160 /** 161 * ファイル出力時のディレクトリを指定します。 162 * 163 * @og.rev 5.4.3.0 (2011/12/26) _DEFAULT対応 164 * @param id プリンタID 165 */ 166 public void setPrtId( final String id ){ 167 prtid = id; 168 } 169 170 /** 171 * プリンタのポート名。 172 * 173 * @og.rev 5.4.3.1 (2011/12/27) 174 * @param port ポート名 175 */ 176 public void setPortnm( final String port ){ 177 portnm = port; 178 } 179 180 /** 181 * RFIDのレイアウトデータをセットします。 182 * 183 * キーはカラム名です。 184 * 値はGE58で定義された出力区分及びパラメーターの配列です。 185 * 配列の各インデックス番号の意味は、RFIDPrintRequestを参照して下さい。 186 * 187 * @og.rev 6.4.3.1 (2016/02/12) 実態を、HashMap → ConcurrentHashMap に置き換えたので、key,val ともに not null 制限です。 188 * @og.rev 6.4.3.3 (2016/03/04) ConcurrentHashMap を受け取ることを明確にするため、I/FをConcurrentMapに変更します。 189 * 190 * @param layout RFIDレイアウト 191 */ 192 public void setLayout( final ConcurrentMap<String, String[]> layout ) { 193 rfidLayout = layout; 194 } 195 196 /** 197 * 帳票IDをセットします。 198 * 199 * @param id 帳票ID 200 */ 201 public void setListId( final String id ) { 202 listid = id; 203 } 204 205 /** 206 * 帳票IDをセットします。 207 * 208 * @og.rev 5.4.3.9 (2012/01/25) 209 * @param file 雛形ファイル名 210 */ 211 public void setLayoutFile( final String file ) { 212 layoutFile = file; 213 } 214 215 /** 216 * 完成フラグを返します。 217 * 218 * @return 完成フラグ String 219 */ 220 public String getFgkan(){ 221 return fgkan; 222 } 223 224 /** 225 * エラーメッセージを返します。 226 * 227 * @return エラーメッセージ String 228 * @og.rtnNotNull 229 */ 230 public String getErrMsg(){ 231 return errMsg.toString(); 232 } 233 234 /** 235 * シェルの実行を行います。 236 * 237 * @og.rev 5.4.3.0 (2011/12/26) 238 * 239 * @return 結果 [true:正常/false:異常] 240 */ 241 protected boolean programRun(){ 242 final Shell shell = new Shell(); 243 shell.setCommand( shellCmd,true ); // BATCHプロセスで実行する 244 shell.setWait( true ); // プロセスの終了を待つ 245 shell.setTimeout( TIMEOUT ); 246 247 final int rtnCode = shell.exec(); // 0 は正常終了を示す 248 249 if( rtnCode != 0 ) { 250 errMsg.append( "Shell Command exequte Error." ).append( CR ) 251 .append( "==============================" ).append( CR ) 252 .append( shellCmd ).append( CR ) 253 .append( shell.getStdoutData() ).append( CR ) 254 .append( shell.getStderrData() ).append( CR ) 255 .append( CR ); 256 return false; 257 } 258 259 return true; 260 } 261 262}