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 */
016 package org.opengion.hayabusa.report;
017
018 import java.util.Map;
019
020 import org.opengion.fukurou.util.Shell;
021 import org.opengion.hayabusa.common.HybsSystem;
022 import 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 */
034 public 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 要æ±?O
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 }