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.remote; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 import java.util.Map; 021 022 import org.opengion.fukurou.db.Transaction; 023 import org.opengion.fukurou.db.TransactionReal; 024 import org.opengion.fukurou.transfer.TransferConfig; 025 import org.opengion.fukurou.transfer.TransferExec; 026 import org.opengion.fukurou.util.ApplicationInfo; 027 import org.opengion.fukurou.util.StringUtil; 028 import org.opengion.hayabusa.common.HybsSystem; 029 import org.opengion.hayabusa.common.HybsSystemException; 030 031 /** 032 * RemoteControllableインタフェイスを実?? 033 * サーブレ?経由で?伝?実行??行うためのクラスです? 034 * 035 * こ?クラスは、伝?実行???ラ?ークラスです? 036 * 引数のKBEXECのパラメーターに基づき?伝?実行オブジェクトを生?し?伝?処?実行します? 037 * 詳細につ?は、{@link org.opengion.fukurou.transfer.TransferExec_HTTP}を参照して下さ?? 038 * 039 * @og.rev 5.4.2.0 (2011/12/01) 新規作? 040 * 041 * @version 4.1 042 * @author Hiroki Nakamura 043 * @since JDK6.0, 044 * 045 */ 046 public class TransferExecWrapper implements RemoteControllable { 047 048 // 伝?実行クラスのベ?スクラス? 049 private static final String EXEC_CLASS_BASE = "org.opengion.fukurou.transfer.TransferExec_" ; 050 051 // コネクションにアプリケーション??を追記するかど??? 052 private static final boolean USE_DB_APPLICATION_INFO = HybsSystem.sysBool( "USE_DB_APPLICATION_INFO" ) ; 053 054 private static final ApplicationInfo appInfo; 055 056 static { 057 if( USE_DB_APPLICATION_INFO ) { 058 appInfo = new ApplicationInfo(); 059 // ユーザーID,IPアドレス,ホスト名 060 appInfo.setClientInfo( "TransferExecWrapper",HybsSystem.HOST_ADRS,HybsSystem.HOST_NAME ); 061 // 画面ID,操?プログラ?D 062 appInfo.setModuleInfo( "TransferExecWrapper","TransferExecWrapper","TransferExecWrapper" ); 063 } 064 else { 065 appInfo = null; 066 } 067 } 068 /** 069 * RemoteControllableインタフェイスの実?ソ?です? 070 * 071 * @param valMap サーブレ?が受け取ったキーと値のマッ? 072 * 073 * @return XML形式?実行結果 074 */ 075 public String remoteControl( final Map<String,String> valMap ) { 076 // パラメーターより伝?設定オブジェクトを生?します? 077 TransferConfig conf = new TransferConfig( 078 valMap.get( "KBREAD" ) 079 , valMap.get( "READOBJ" ) 080 , valMap.get( "READPRM" ) 081 , valMap.get( "KBEXEC" ) 082 , valMap.get( "EXECDBID" ) 083 , valMap.get( "EXECOBJ" ) 084 , valMap.get( "EXECPRM" ) 085 , valMap.get( "ERROR_SENDTO" ) 086 , valMap.get( "HFROM" ) 087 , null, -1 ); 088 089 // パラメーターより伝?実行オブジェクトに渡す??(配?)を生成します? 090 String[] vals = getVals( valMap ); 091 092 Transaction tran = null; 093 try { 094 tran = new TransactionReal( appInfo ); 095 // 実行方法?オブジェクトを生?します? 096 TransferExec exec = (TransferExec)StringUtil.newInstance( EXEC_CLASS_BASE + valMap.get( "KBEXEC" ) ); 097 // 処?実行します? 098 exec.execute( vals, conf, tran ); 099 } 100 catch ( Throwable ex ) { 101 String msg = "伝?処??HTTP経由)でエラーが発生しました?; 102 throw new HybsSystemException( msg, ex ); 103 } 104 finally { 105 if( tran != null ) { tran.close(); } 106 } 107 108 return ""; 109 } 110 111 /** 112 * パラメーターより伝?実行オブジェクトに渡す??(配?)を生成します? 113 * 対象パラメーターは?(??タ件数) と ②v1?vn(??タ) です? 114 * 115 * @param valMap パラメーターMap 116 * 117 * @return 値?(配?) 118 */ 119 private String[] getVals( final Map<String,String> valMap ) { 120 int rows = 0; 121 String rno = valMap.get( "n" ); 122 if( rno != null && rno.length() > 0 ) { 123 rows = Integer.valueOf( rno ); 124 } 125 List<String> list = new ArrayList<String>(); 126 for( int i=0; i<rows; i++ ) { 127 // String val = valMap.get( "v" + String.valueOf( i ) ); 128 String val = valMap.get( "v" + i ); 129 list.add( val ); 130 } 131 // return list.toArray( new String[0] ); 132 return list.toArray( new String[list.size()] ); 133 } 134 }