1 16 17 package org.apache.axis.client; 18 19 import java.lang.reflect.InvocationHandler ; 20 import java.lang.reflect.Method ; 21 import java.util.Map ; 22 import java.util.Vector ; 23 24 import javax.xml.namespace.QName ; 25 import javax.xml.rpc.holders.Holder ; 26 27 import org.apache.axis.description.OperationDesc; 28 import org.apache.axis.description.ParameterDesc; 29 import org.apache.axis.utils.JavaUtils; 30 31 40 public class AxisClientProxy implements InvocationHandler { 41 42 private Call call; 43 private QName portName; 44 45 50 AxisClientProxy(Call call, QName portName) 51 { 52 this.call = call; 53 this.portName = portName; } 55 56 57 70 private Object [] proxyParams2CallParams(Object [] proxyParams) 71 throws JavaUtils.HolderException 72 { 73 OperationDesc operationDesc = call.getOperation(); 74 if (operationDesc == null) 75 { 76 return proxyParams; 79 } 80 81 Vector paramsCall = new Vector (); 82 for (int i = 0; proxyParams != null && i < proxyParams.length;i++) 83 { 84 Object param = proxyParams[i]; 85 ParameterDesc paramDesc = operationDesc.getParameter(i); 86 87 if (paramDesc.getMode() == ParameterDesc.INOUT) { 88 paramsCall.add(JavaUtils.getHolderValue((Holder )param)); 89 } 90 else 91 if (paramDesc.getMode() == ParameterDesc.IN) { 92 paramsCall.add(param); 93 } 94 } 95 return paramsCall.toArray(); 96 } 97 98 103 private void callOutputParams2proxyParams(Object [] proxyParams) 104 throws JavaUtils.HolderException 105 { 106 OperationDesc operationDesc = call.getOperation(); 107 if (operationDesc == null) 108 { 109 return; 112 } 113 114 Map outputParams = call.getOutputParams(); 115 116 for (int i = 0; i < operationDesc.getNumParams();i++) 117 { 118 Object param = proxyParams[i]; 119 ParameterDesc paramDesc = operationDesc.getParameter(i); 120 if ((paramDesc.getMode() == ParameterDesc.INOUT) || 121 (paramDesc.getMode() == ParameterDesc.OUT)) { 122 123 JavaUtils.setHolderValue((Holder )param, 124 outputParams.get(paramDesc.getQName())); 125 } 126 } 127 } 128 129 140 public Object invoke(Object o, Method method, Object [] objects) 141 throws Throwable { 142 if (method.getName().equals("_setProperty")) { 144 call.setProperty((String ) objects[0], objects[1]); 145 return null; 146 } else if (method.getName().equals("_getProperty")) { 147 return call.getProperty((String ) objects[0]); 148 } else if (method.getName().equals("_getPropertyNames")) { 149 return call.getPropertyNames(); 150 } else if (Object .class.equals(method.getDeclaringClass())) { 151 return method.invoke(call, objects); 153 } else { 154 Object outValue; 155 Object [] paramsCall; 156 157 if ((call.getTargetEndpointAddress() != null) && 158 (call.getPortName() != null)) { 159 call.setOperation(method.getName()); 162 paramsCall = proxyParams2CallParams(objects); 163 outValue = call.invoke(paramsCall); 164 } 165 else if (portName != null) 166 { 167 call.setOperation(portName,method.getName()); 170 paramsCall = proxyParams2CallParams(objects); 171 outValue = call.invoke(paramsCall); 172 } 173 else 174 { 175 paramsCall = objects; 177 outValue = call.invoke(method.getName(), paramsCall); 178 } 179 callOutputParams2proxyParams(objects); 180 return outValue; 181 } 182 } 183 184 189 public Call getCall(){ 190 return call; 191 } 192 } 193 | Popular Tags |