org.licas.call

## Class MethodFactory

- java.lang.Object
- - org.licas.call.MethodFactory

-     public final class MethodFactory
      extends java.lang.Object

  This factory class can be used to create method info objects for dynamic execution on any of the communication protocols. Note that `createMethodCall` can be used on direct object references and also ones that are not `Service`-related. So it might be used as a general mechanism for creating a method description to execute through the `CallObject` interface, and therefore on a separate thread.
  The generated object is not guaranteed to be 100% complete, so you will need to check this in your code, in case you need to add other values, but it does reduce the amount of effort you may require to construct the method objects.
  Author:
    Kieran Greer

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MethodFactory()` Creates a new instance of MethodFactory.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static MethodInfo` | `createMethodCall(java.lang.String methodName, java.lang.String returnType, java.lang.Object serviceObj, java.util.ArrayList<java.lang.Object> parameters, PasswordHandler passwordHandler)` Automatically construct the RPC-XML/Reflection method call from the parameter values entered.
    `static MethodInfo` | `createObjectCall(java.lang.String methodName, java.lang.String returnType, java.lang.Object objToInvoke, java.util.ArrayList<java.lang.Object> parameters)` Automatically construct the Reflection method info from the parameter values entered.
    `static WsMethodInfo` | `createRestCall(java.lang.String endpointAddress, java.lang.String query)` Create and return a method info object for invoking a web service using the REST protocol.
    `static WsMethodInfo` | `createSoapCall(java.lang.String operationName, boolean setRtn, boolean paramValues, LicasWsdlModel wsdlModel)` Create and return a method info object for invoking a web service using the SOAP protocol.
    `static WsMethodInfo` | `createSoapCall(java.lang.String webService, java.lang.String operation, java.lang.String endpointAddress, java.lang.String soapActionUri, java.lang.String namespace, java.util.ArrayList<WsdlParamInfo> parameters, boolean setRtn)` Create and return a method info object for invoking a web service using the SOAP protocol.
    `static void` | `mapToParams(MethodInfo methodInfo, java.util.ArrayList<java.lang.Object> paramList)` Map and set parameter instance values in the related info objects.
    `static java.lang.Object` | `parseReply(java.lang.Object reply)` Parse the reply back into n Object and return.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MethodFactory

          public MethodFactory()

      Creates a new instance of MethodFactory.

  - ### Method Detail

    - #### createObjectCall

          public static MethodInfo createObjectCall(java.lang.String methodName,
                                                    java.lang.String returnType,
                                                    java.lang.Object objToInvoke,
                                                    java.util.ArrayList<java.lang.Object> parameters)
                                             throws java.lang.Exception

      Automatically construct the Reflection method info from the parameter values entered. This might more typically be for a direct reference to an object that is not licas `Service`-derived. So any other object, when no passwords are required.
      Parameters:
        `methodName` - the name of the method to call.
        `returnType` - the return type for the call.
        `objToInvoke` - the reference to the object to invoke. This should probably be a direct reference to the Object itself and not `Service`-derived.
        `parameters` - the parameter list for the method to call.
      Returns:
        the created method info object.
      Throws:
        `java.lang.Exception` - any error.

    - #### createMethodCall

          public static MethodInfo createMethodCall(java.lang.String methodName,
                                                    java.lang.String returnType,
                                                    java.lang.Object serviceObj,
                                                    java.util.ArrayList<java.lang.Object> parameters,
                                                    PasswordHandler passwordHandler)
                                             throws java.lang.Exception

      Automatically construct the RPC-XML/Reflection method call from the parameter values entered. The `serviceObj` would typically be a reference to a licas `Service`-derived object, but does not have to be.
      Parameters:
        `methodName` - the name of the method to call.
        `returnType` - the return type for the call.
        `serviceObj` - the reference to the service to call. This can either be a URI description as an XML element or a direct reference Object.
        `parameters` - the parameter list for the method to call.
        `passwordHandler` - the passwords that are required to make the call. If `passwordHandler` is `null` then passwords are not checked for, but remote access to any `Service`-derived object will require passwords.
      Returns:
        the created method info object.
      Throws:
        `java.lang.Exception` - any error.

    - #### createSoapCall

          public static WsMethodInfo createSoapCall(java.lang.String operationName,
                                                    boolean setRtn,
                                                    boolean paramValues,
                                                    LicasWsdlModel wsdlModel)
                                             throws java.lang.Exception

      Create and return a method info object for invoking a web service using the SOAP protocol.
      Parameters:
        `operationName` - the name of the operation to call.
        `setRtn` - true if set the return Object type.
        `paramValues` - if true add the parameter values as `WsdlParamInfo` objects.
        `wsdlModel` - the wsdl model that stores the description.
      Returns:
        a web service info object with the appropriate values.
      Throws:
        `java.lang.Exception` - any error.

    - #### createSoapCall

          public static WsMethodInfo createSoapCall(java.lang.String webService,
                                                    java.lang.String operation,
                                                    java.lang.String endpointAddress,
                                                    java.lang.String soapActionUri,
                                                    java.lang.String namespace,
                                                    java.util.ArrayList<WsdlParamInfo> parameters,
                                                    boolean setRtn)
                                             throws java.lang.Exception

      Create and return a method info object for invoking a web service using the SOAP protocol.
      Parameters:
        `webService` - the service name.
        `operation` - the name of the operation to call.
        `endpointAddress` - the server endpoint address.
        `soapActionUri` - soap action uri type.
        `namespace` - ontology namespace.
        `parameters` - list of `WsdlParamInfo` objects that store parameter types and values.
        `setRtn` - true if set the return Object type.
      Returns:
        a web service info object with the appropriate values.
      Throws:
        `java.lang.Exception` - any error.

    - #### createRestCall

          public static WsMethodInfo createRestCall(java.lang.String endpointAddress,
                                                    java.lang.String query)
                                             throws java.lang.Exception

      Create and return a method info object for invoking a web service using the REST protocol.
      Parameters:
        `endpointAddress` - the server endpoint address.
        `query` - the full REST-style query.
      Returns:
        a web service info object with the appropriate values.
      Throws:
        `java.lang.Exception` - any error.

    - #### mapToParams

          public static void mapToParams(MethodInfo methodInfo,
                                         java.util.ArrayList<java.lang.Object> paramList)

      Map and set parameter instance values in the related info objects. This works best with a properly configured method object and parameter list, with the following rules:

      1. If the `ParamInfo` objects of this method do not have names assigned, then assign the first parameter value in the list to each one.
      2. If the `ParamInfo` objects of this method do have names try to map to the name.
      2.1. If the paramList is a list of `KeyValue` objects, then the related name can be mapped.
      2.2. If the paramList is a list of objects, then assign the first one again.
      3. A null value, evaluated by `ObjectHandler`.`isNull` will not be added.

      So if names are tagged, they can be replaced from any position in the list, but if names are missing, the first available value must be used. Safest is to have a `paramList` of `KeyValue` objects and each `MethodInfo` parameter also assigned an identical name.

      Parameters:
        `methodInfo` - the method info that gets its parameter list updated.
        `paramList` - list of parameters, preferably as `KeyValue` objects so that they can be mapped across properly.

    - #### parseReply

          public static java.lang.Object parseReply(java.lang.Object reply)
                                             throws java.lang.Exception

      Parse the reply back into n Object and return.
      Parameters:
        `reply` - the method reply in some form.
      Returns:
        the method reply after further formatting.
      Throws:
        `java.lang.Exception` - any error.