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.report2; 017 018import java.util.Random; 019 020import org.opengion.hayabusa.common.HybsSystem; 021import org.opengion.hayabusa.common.HybsSystemException; 022import org.opengion.hayabusa.db.DBTableModel; 023 024/** 025 * 画面から直接キューを作成するためのクラスです。 026 * 各種設定値を直接指定することでDBのマスタ設定を行うことなく帳票出力を行います。 027 * 現時点では、出力系の処理しか対応していません。 028 * 029 * ここで登録されたキューは、別スレッドで処理されるため、#create()メソッドを呼び出した後は、 030 * #waitExec()メソッドを呼び出し、処理の終了に同期させる必要があります。 031 * エラーが発生した場合は、HybsSystemExceptionを発生します。 032 * 033 * また、処理のタイムアウトは、システムリソースのREPORT_DAEMON_TIMEOUTで設定します。 034 * 035 * @og.group 帳票システム 036 * 037 * @version 4.0 038 * @author Hiroki.Nakamura 039 * @since JDK1.6 040 */ 041public class QueueManager_DIRECT implements QueueManager { 042 043 private final int timeout = HybsSystem.sysInt( "REPORT_DAEMON_TIMEOUT" ); 044 045 private static final String SYSTEM_ID = HybsSystem.sys( "SYSTEM_ID" ); 046 private static final Random RANDOM = new Random(); 047 048 private String listId ; 049 private String outputName ; 050 private String lang ; 051 private String outputType ; 052 private String templateName ; 053 private String printerName ; 054 private boolean fglocal ; 055 private boolean fgcut ; 056 private boolean useSheetName; // 5.7.6.2 (2014/05/16) PAGEBREAKカラムの値を、シート名として使うかどうか。 057 058 private DBTableModel body ; 059 private DBTableModel header ; 060 private DBTableModel footer ; 061 062 private boolean isEnd ; 063 private String errMsg ; 064 065 /** 066 * デフォルトコンストラクター 067 * 068 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 069 */ 070 public QueueManager_DIRECT() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 071 072 /** 073 * 帳票処理キューを作成します。 074 * 075 * @og.rev 5.1.6.0 (2010/05/01) 要求単位にスレッドを生成するようにします。 076 * @og.rev 5.7.6.2 (2014/05/16) PAGEBREAKカラムの値を、シート名として使うかどうかをセットします 077 */ 078 public void create() { 079 final ExecQueue queue = new ExecQueue(); 080 queue.setSystemId( SYSTEM_ID ); 081 queue.setYkno( "DIRECT_" + Long.toString( RANDOM.nextLong() & 0x7fffffffffffffffL ) ); 082 queue.setListId( listId ); 083 queue.setLang( lang ); 084 queue.setOutputName( outputName ); 085 queue.setOutputType( outputType ); 086 // 5.1.6.0 (2010/05/01) 087 queue.setThreadId( "DIRECT_" + Long.toString( RANDOM.nextLong() & 0x7fffffffffffffffL ) ); 088 queue.setTemplateName( templateName ); 089 queue.setPrinterName( printerName ); 090 queue.setFglocal( fglocal ); 091 queue.setFgcut( fgcut ); 092 queue.setUseSheetName( useSheetName ); // 5.7.6.2 (2014/05/16) PAGEBREAKカラムの値を、シート名として使うかどうかをセットします 093 094 queue.setBody( body ); 095 queue.setHeader( header ); 096 queue.setFooter( footer ); 097 098 queue.setManager( this ); 099 100 // 5.1.6.0 (2010/05/01) 101 ExecThreadManager.insertQueueOnNewThread( queue ); 102 } 103 104 /** 105 * 帳票処理データをキューにセットします。 106 * 画面から発行する場合は、テーブルモデルを直接セットするので、 107 * ここでは何もしません。 108 * 109 * @param queue ExecQueueオブジェクト 110 */ 111 public void set( final ExecQueue queue ) { 112 // 何もありません。(PMD エラー回避) 113 } 114 115 /** 116 * キューを実行中の状態に更新します。 117 * 画面から発行する場合は、実行中であることを知る必要がないため、 118 * ここでは何もしません。 119 * 120 * @param queue ExecQueueオブジェクト 121 */ 122 public void execute( final ExecQueue queue ) { 123 // 何もありません。(PMD エラー回避) 124 } 125 126 /** 127 * キューを完了済の状態に更新します。 128 * 129 * @param queue ExecQueueオブジェクト 130 */ 131 public void complete( final ExecQueue queue ) { 132 isEnd = true; 133 } 134 135 /** 136 * キューをエラーの状態に更新します。 137 * 138 * @param queue ExecQueueオブジェクト 139 */ 140 public void error( final ExecQueue queue ) { 141 isEnd = true; 142 errMsg = queue.getMsg(); 143 } 144 145 /** 146 * 処理が完了してするまでスレッドを待ち状態にします。 147 * エラーが発生した場合は、例外が発生します。 148 * また、REPORT_DAEMON_TIMEOUTで指定された期間処理が終了しない場合は、 149 * タイムアウトエラーとなります。 150 * 151 */ 152 public void waitExec() { 153 final long start = System.currentTimeMillis(); 154 while( true ) { 155 if( isEnd ) { 156 if( errMsg == null ) { 157 break; 158 } 159 else { 160 throw new HybsSystemException( errMsg ); 161 } 162 } 163 164 if( (int)(System.currentTimeMillis() - start) > timeout * 1000 ) { 165 throw new HybsSystemException( "帳票処理でタイムアウトになりました" ); 166 } 167 try { 168 Thread.sleep( 100 ); 169 } 170 catch( final InterruptedException ex ) { } 171 } 172 } 173 174 /** 175 * 帳票IDを設定します。 176 * 177 * @param listId 帳票ID 178 */ 179 public final void setListId( final String listId ) { 180 this.listId = listId; 181 } 182 183 /** 184 * 言語を設定します。 185 * 186 * @param lang 言語 187 */ 188 public void setLang( final String lang ) { 189 this.lang = lang; 190 } 191 192 /** 193 * 出力ファイル名を設定します。 194 * 195 * @param outputName 出力ファイル名 196 */ 197 public final void setOutputName( final String outputName ) { 198 this.outputName = outputName; 199 } 200 201 /** 202 * 実行方法を設定します。 203 * 204 * @param outputType 実行方法 205 */ 206 public final void setOutputType( final String outputType ) { 207 this.outputType = outputType; 208 } 209 210 /** 211 * 雛形ファイル名を設定します。 212 * 213 * @param templateName 雛形ファイル名 214 */ 215 public final void setTemplateName( final String templateName ) { 216 this.templateName = templateName; 217 } 218 219 /** 220 * 出力先のプリンタ名を設定します。 221 * 222 * @param printerName 出力先のプリンタ名 223 */ 224 public final void setPrinterName( final String printerName ) { 225 this.printerName = printerName; 226 } 227 228 /** 229 * ローカルリソースの使用可否を設定します。 230 * 231 * @param fglocal 使用可否[true/false] 232 */ 233 public void setFglocal( final boolean fglocal ) { 234 this.fglocal = fglocal; 235 } 236 237 /** 238 * ページエンドカットを行うかを設定します。 239 * 240 * @param fgcut ページエンドカットの使用可否[true:使用/false:通常] 241 */ 242 public void setFgcut( final boolean fgcut ) { 243 this.fgcut = fgcut; 244 } 245 246 /** 247 * PAGEBREAKカラムの値を、シート名として使うかどうかをセットします(初期値:false)。 248 * 249 * @og.rev 5.7.6.2 (2014/05/16) 新規追加 250 * 251 * @param useSheetName PAGEBREAKカラムのシート名使用可否[true:使用/false:使用しない] 252 */ 253 public void setUseSheetName( final boolean useSheetName ) { 254 this.useSheetName = useSheetName; 255 } 256 257 /** 258 * ボディーのテーブルモデルを設定します。 259 * 260 * @param body DBTableModelオブジェクト 261 */ 262 public void setBody( final DBTableModel body ) { 263 this.body = body; 264 } 265 266 /** 267 * ヘッダーのテーブルモデルを設定します。 268 * 269 * @param header DBTableModelオブジェクト 270 */ 271 public void setHeader( final DBTableModel header ) { 272 this.header = header; 273 } 274 275 /** 276 * フッターのテーブルモデルを設定します。 277 * 278 * @param footer DBTableModelオブジェクト 279 */ 280 public void setFooter( final DBTableModel footer ) { 281 this.footer = footer; 282 } 283}