View Javadoc

1   package org.seasar.remoting.axis.connector;
2   
3   import java.lang.reflect.Method;
4   import java.net.URL;
5   
6   import javax.xml.namespace.QName;
7   import javax.xml.rpc.Call;
8   import javax.xml.rpc.Service;
9   
10  import org.apache.axis.encoding.TypeMappingRegistry;
11  import org.apache.axis.enum.Use;
12  import org.seasar.remoting.axis.S2AxisConstants;
13  import org.seasar.remoting.axis.encoding.AutoRegisterTypeMappingImpl;
14  import org.seasar.remoting.client.connector.impl.URLBasedConnector;
15  
16  /***
17   * @author koichik
18   */
19  public class AxisConnector extends URLBasedConnector {
20      protected Service service;
21  
22      /***
23       * Axisサービスを設定します。
24       * 
25       * @param service Axisサービス
26       */
27      public void setService(final Service service) {
28          this.service = service;
29  
30          final TypeMappingRegistry tmr = (TypeMappingRegistry) service.getTypeMappingRegistry();
31          if (!(tmr.getTypeMapping(Use.DEFAULT.getEncoding()) instanceof AutoRegisterTypeMappingImpl)) {
32  	        final AutoRegisterTypeMappingImpl autoTM = new AutoRegisterTypeMappingImpl(null);
33  	        tmr.register(Use.DEFAULT.getEncoding(), autoTM);
34          }
35      }
36  
37      /***
38       * Axisサービスを使用してリモートメソッドの呼び出しを実行し、その結果を返します。
39       * 
40       * @param targetURL
41       *            リモートオブジェクトのURL
42       * @param method
43       *            呼び出すメソッド
44       * @param args
45       *            リモートオブジェクトのメソッド呼び出しに渡される引数値を格納するオブジェクト配列
46       * @return リモートオブジェクトに対するメソッド呼び出しからの戻り値
47       * @throws Throwable
48       *             リモートオブジェクトに対するメソッド呼び出しからスローされる例外
49       */
50      protected Object invoke(final URL targetURL, final Method method, final Object[] args) throws Throwable {
51          final Call call = service.createCall();
52          call.setTargetEndpointAddress(targetURL.toString());
53          call.setOperationName(new QName(S2AxisConstants.OPERATION_NAMESPACE_URI, method.getName()));
54          return call.invoke(args);
55      }
56  }