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