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 * @og.rev 5.7.1.2 (2013/12/20) msg ?errMsg 変更
072 *
073 * @param valMap サーブレ?が受け取ったキーと値のマッ?
074 *
075 * @return XML形式?実行結果
076 */
077 public String remoteControl( final Map<String,String> valMap ) {
078 // パラメーターより伝?設定オブジェクトを生?します?
079 TransferConfig conf = new TransferConfig(
080 valMap.get( "KBREAD" )
081 , valMap.get( "READOBJ" )
082 , valMap.get( "READPRM" )
083 , valMap.get( "KBEXEC" )
084 , valMap.get( "EXECDBID" )
085 , valMap.get( "EXECOBJ" )
086 , valMap.get( "EXECPRM" )
087 , valMap.get( "ERROR_SENDTO" )
088 , valMap.get( "HFROM" )
089 , null, -1 );
090
091 // パラメーターより伝?実行オブジェクトに渡す??(配?)を生成します?
092 String[] vals = getVals( valMap );
093
094 Transaction tran = null;
095 try {
096 tran = new TransactionReal( appInfo );
097 // 実行方法?オブジェクトを生?します?
098 TransferExec exec = (TransferExec)StringUtil.newInstance( EXEC_CLASS_BASE + valMap.get( "KBEXEC" ) );
099 // 処?実行します?
100 exec.execute( vals, conf, tran );
101 }
102 catch ( Throwable ex ) {
103 // String msg = "伝?処??HTTP経由)でエラーが発生しました?;
104 // throw new HybsSystemException( msg, ex );
105 String errMsg = "伝?処??HTTP経由)でエラーが発生しました?;
106 throw new HybsSystemException( errMsg, ex ); // 5.7.1.2 (2013/12/20) msg ?errMsg 変更
107 }
108 finally {
109 if( tran != null ) { tran.close(); }
110 }
111
112 return "";
113 }
114
115 /**
116 * パラメーターより伝?実行オブジェクトに渡す??(配?)を生成します?
117 * 対象パラメーターは?(??タ件数) と ②v1?vn(??タ) です?
118 *
119 * @param valMap パラメーターMap
120 *
121 * @return 値?(配?)
122 */
123 private String[] getVals( final Map<String,String> valMap ) {
124 int rows = 0;
125 String rno = valMap.get( "n" );
126 if( rno != null && rno.length() > 0 ) {
127 rows = Integer.valueOf( rno );
128 }
129 List<String> list = new ArrayList<String>();
130 for( int i=0; i<rows; i++ ) {
131 // String val = valMap.get( "v" + String.valueOf( i ) );
132 String val = valMap.get( "v" + i );
133 list.add( val );
134 }
135 // return list.toArray( new String[0] );
136 return list.toArray( new String[list.size()] );
137 }
138 }