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.report2; 017 018 import java.util.Random; 019 020 import org.opengion.hayabusa.common.HybsSystem; 021 import org.opengion.hayabusa.common.HybsSystemException; 022 import 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 */ 041 public 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 = false; 063 private String errMsg = null; 064 065 /** 066 * 帳票処?ューを作?します? 067 * 068 * @og.rev 5.1.6.0 (2010/05/01) 要求単位にスレ?を生成するよ?します? 069 * @og.rev 5.7.6.2 (2014/05/16) PAGEBREAKカラ??値を?シート名として使?ど?をセ?しま? 070 */ 071 public void create() { 072 ExecQueue queue = new ExecQueue(); 073 queue.setSystemId( SYSTEM_ID ); 074 queue.setYkno( "DIRECT_" + Long.toString( RANDOM.nextLong() & 0x7fffffffffffffffL ) ); 075 queue.setListId( listId ); 076 queue.setLang( lang ); 077 queue.setOutputName( outputName ); 078 queue.setOutputType( outputType ); 079 // 5.1.6.0 (2010/05/01) 080 queue.setThreadId( "DIRECT_" + Long.toString( RANDOM.nextLong() & 0x7fffffffffffffffL ) ); 081 queue.setTemplateName( templateName ); 082 queue.setPrinterName( printerName ); 083 queue.setFglocal( fglocal ); 084 queue.setFgcut( fgcut ); 085 queue.setUseSheetName( useSheetName ); // 5.7.6.2 (2014/05/16) PAGEBREAKカラ??値を?シート名として使?ど?をセ?しま? 086 087 queue.setBody( body ); 088 queue.setHeader( header ); 089 queue.setFooter( footer ); 090 091 queue.setManager( this ); 092 093 // 5.1.6.0 (2010/05/01) 094 ExecThreadManager.insertQueueOnNewThread( queue ); 095 } 096 097 /** 098 * 帳票処?ータをキューにセ?します? 099 * 画面から発行する?合?、テーブルモ?を直接セ?するので? 100 * ここでは何もしません? 101 * 102 * @param queue ExecQueueオブジェク? 103 */ 104 public void set( final ExecQueue queue ) { 105 // 何もありません?PMD エラー回避) 106 } 107 108 /** 109 * キューを実行中の状態に更新します? 110 * 画面から発行する?合?、実行中であることを知る?がな?め? 111 * ここでは何もしません? 112 * 113 * @param queue ExecQueueオブジェク? 114 */ 115 public void execute( final ExecQueue queue ) { 116 // 何もありません?PMD エラー回避) 117 } 118 119 /** 120 * キューを完??状態に更新します? 121 * 122 * @param queue ExecQueueオブジェク? 123 */ 124 public void complete( final ExecQueue queue ) { 125 isEnd = true; 126 } 127 128 /** 129 * キューをエラーの状態に更新します? 130 * 131 * @param queue ExecQueueオブジェク? 132 */ 133 public void error( final ExecQueue queue ) { 134 isEnd = true; 135 errMsg = queue.getMsg(); 136 } 137 138 /** 139 * 処?完?てするまでスレ?を?状態にします? 140 * エラーが発生した?合?、例外が発生します? 141 * また?REPORT_DAEMON_TIMEOUTで?された期間処?終?な??合?? 142 * タイ?ウトエラーとなります? 143 * 144 */ 145 public void waitExec() { 146 long start = System.currentTimeMillis(); 147 while( true ) { 148 if( isEnd ) { 149 if( errMsg == null ) { 150 break; 151 } 152 else { 153 throw new HybsSystemException( errMsg ); 154 } 155 } 156 157 if( (int)(System.currentTimeMillis() - start) > timeout * 1000 ) { 158 throw new HybsSystemException( "帳票処?タイ?ウトになりました" ); 159 } 160 try { 161 Thread.sleep( 100 ); 162 } 163 catch( InterruptedException ex ) { } 164 } 165 } 166 167 /** 168 * 帳票IDを設定します? 169 * 170 * @param listId 帳票ID 171 */ 172 public final void setListId( final String listId ) { 173 this.listId = listId; 174 } 175 176 /** 177 * ?を設定します? 178 * 179 * @param lang ?? 180 */ 181 public void setLang( final String lang ) { 182 this.lang = lang; 183 } 184 185 /** 186 * 出力ファイル名を設定します? 187 * 188 * @param outputName 出力ファイル? 189 */ 190 public final void setOutputName( final String outputName ) { 191 this.outputName = outputName; 192 } 193 194 /** 195 * 実行方法を設定します? 196 * 197 * @param outputType 実行方? 198 */ 199 public final void setOutputType( final String outputType ) { 200 this.outputType = outputType; 201 } 202 203 /** 204 * 雛形ファイル名を設定します? 205 * 206 * @param templateName 雛形ファイル? 207 */ 208 public final void setTemplateName( final String templateName ) { 209 this.templateName = templateName; 210 } 211 212 /** 213 * 出力?のプリンタ名を設定します? 214 * 215 * @param printerName 出力?のプリンタ? 216 */ 217 public final void setPrinterName( final String printerName ) { 218 this.printerName = printerName; 219 } 220 221 /** 222 * ローカルリソースの使用可否を設定します? 223 * 224 * @param fglocal 使用可否[true/false] 225 */ 226 public void setFglocal( final boolean fglocal ) { 227 this.fglocal = fglocal; 228 } 229 230 /** 231 * ペ?ジエンドカ?を行うかを設定します? 232 * 233 * @param fgcut ペ?ジエンドカ?の使用可否[true:使用/false:通常] 234 */ 235 public void setFgcut( final boolean fgcut ) { 236 this.fgcut = fgcut; 237 } 238 239 /** 240 * PAGEBREAKカラ??値を?シート名として使?ど?をセ?しま?初期値:false)? 241 * 242 * @og.rev 5.7.6.2 (2014/05/16) 新規追? 243 * 244 * @param useSheetName PAGEBREAKカラ??シート名使用可否[true:使用/false:使用しない] 245 */ 246 public void setUseSheetName( final boolean useSheetName ) { 247 this.useSheetName = useSheetName; 248 } 249 250 /** 251 * ボディーの??ブルモ?を設定します? 252 * 253 * @param body DBTableModelオブジェク? 254 */ 255 public void setBody( final DBTableModel body ) { 256 this.body = body; 257 } 258 259 /** 260 * ヘッ??の??ブルモ?を設定します? 261 * 262 * @param header DBTableModelオブジェク? 263 */ 264 public void setHeader( final DBTableModel header ) { 265 this.header = header; 266 } 267 268 /** 269 * フッターの??ブルモ?を設定します? 270 * 271 * @param footer DBTableModelオブジェク? 272 */ 273 public void setFooter( final DBTableModel footer ) { 274 this.footer = footer; 275 } 276 }