FileDocCategorySizeDatePackage
AxisClientProxy.javaAPI DocApache Axis 1.46695Sat Apr 22 18:57:26 BST 2006org.apache.axis.client

AxisClientProxy

public class AxisClientProxy extends Object implements InvocationHandler
Very simple dynamic proxy InvocationHandler class. This class is constructed with a Call object, and then each time a method is invoked on a dynamic proxy using this invocation handler, we simply turn it into a SOAP request.
author
Glen Daniels (gdaniels@apache.org)
author
C?dric Chabanois (cchabanois@ifrance.com)

Fields Summary
private Call
call
private QName
portName
Constructors Summary
AxisClientProxy(Call call, QName portName)
Constructor - package access only (should only really get used in Service.getPort(endpoint, proxyClass). Call can be pre-filled from wsdl

        this.call = call;
        this.portName = portName; // can be null
    
Methods Summary
private voidcallOutputParams2proxyParams(java.lang.Object[] proxyParams)
Copy in/out and out parameters (Holder parameters) back to proxyParams.

param
proxyParams proxyParameters

        OperationDesc operationDesc = call.getOperation();
        if (operationDesc == null)
        {
            // we don't know which parameters are IN, OUT or INOUT
            // let's suppose they are all in
            return;
        }

        Map outputParams = call.getOutputParams();

        for (int i = 0; i < operationDesc.getNumParams();i++)
        {
            Object param = proxyParams[i];
            ParameterDesc paramDesc = operationDesc.getParameter(i);
            if ((paramDesc.getMode() == ParameterDesc.INOUT) ||
                (paramDesc.getMode() == ParameterDesc.OUT)) {

                  JavaUtils.setHolderValue((Holder)param,
                      outputParams.get(paramDesc.getQName()));
            }
        }
    
public CallgetCall()
Returns the current call.

return
the current Call

        return call;
    
public java.lang.Objectinvoke(java.lang.Object o, java.lang.reflect.Method method, java.lang.Object[] objects)
Handle a method invocation.

param
o the object to invoke relative to
param
method the Method to invoke
param
objects the arguments to the method
return
the result of the method
throws
Throwable if anything went wrong in method dispatching or the execution of the method itself

        // first see if we invoke Stub methods
        if (method.getName().equals("_setProperty")) {
            call.setProperty((String) objects[0], objects[1]);
            return null;
        } else if (method.getName().equals("_getProperty")) {
            return call.getProperty((String) objects[0]);
        } else if (method.getName().equals("_getPropertyNames")) {
            return call.getPropertyNames();
        } else if (Object.class.equals(method.getDeclaringClass())) {
            // if we invoke basic Object methods : delegate to Call instance
            return method.invoke(call, objects);
        } else {
          Object outValue;
          Object[] paramsCall;

          if ((call.getTargetEndpointAddress() != null) &&
              (call.getPortName() != null)) {
              // call object has been prefilled : targetEndPoint and portname
              // are already set. We complete it with method informations
              call.setOperation(method.getName());
              paramsCall = proxyParams2CallParams(objects);
              outValue = call.invoke(paramsCall);
          }
          else if (portName != null)
          {
              // we only know the portName. Try to complete this information
              // from wsdl if available
              call.setOperation(portName,method.getName());
              paramsCall = proxyParams2CallParams(objects);
              outValue = call.invoke(paramsCall);
          }
          else
          {
              // we don't even know the portName (we don't have wsdl)
              paramsCall = objects;
              outValue = call.invoke(method.getName(), paramsCall);
          }
          callOutputParams2proxyParams(objects);
          return outValue;
        }
    
private java.lang.Object[]proxyParams2CallParams(java.lang.Object[] proxyParams)
Map between the parameters for the method call and the parameters needed for the Call.

Parameters for invoke method are not the same as parameter for Call instance : - Holders must be converted to their mapped java types - only in and inout parameters must be present in call parameters

param
proxyParams proxyParameters
return
Object[] Call parameters
throws
JavaUtils.HolderException

        OperationDesc operationDesc = call.getOperation();
        if (operationDesc == null)
        {
            // we don't know which parameters are IN, OUT or INOUT
            // let's suppose they are all in
            return proxyParams;
        }

        Vector paramsCall = new Vector();
        for (int i = 0; proxyParams != null && i < proxyParams.length;i++)
        {
            Object param = proxyParams[i];
            ParameterDesc paramDesc = operationDesc.getParameter(i);

            if (paramDesc.getMode() == ParameterDesc.INOUT) {
                paramsCall.add(JavaUtils.getHolderValue((Holder)param));
            }
            else
            if (paramDesc.getMode() == ParameterDesc.IN) {
                paramsCall.add(param);
            }
        }
        return paramsCall.toArray();