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    }