org.licas.call.rest

## Class RestFactory

- java.lang.Object
- - org.licas.call.rest.RestFactory

-     public class RestFactory
      extends java.lang.Object

  Factory object for RESTful-style messages. If you do not set an instance of this in your main program, then it defaults to this class.
  Author:
    Kieran Greer

- - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `RestMessage` | `createRestGET(org.licas_xml.abs.Element serviceUri, java.lang.String serverPassword, java.lang.String servicePassword)` Create a string-based RESTful description to invoke the default GET method on a licas service.
    `RestMessage` | `createRestMessage(WsMethodInfo methodInfo)` Create a string-based RESTful description of the contents of the method info.
    `Rest_MethodHandler` | `createRestMethodHandler()` Create the client rest method handler.
    `static java.lang.String` | `decode(java.lang.String queryUri)` Decode the encoded RestFactory-style query URI, from the application/x-www-form-urlencoded MIME format.
    `static java.lang.String` | `encode(java.lang.String queryUri)` Encode the RestFactory-style query URI, to the application/x-www-form-urlencoded MIME format.
    `static RestFactory` | `getInstance()` Get the rest factory instance.
    `boolean` | `notQueryMessage(java.lang.String message)` Return true if the message string cannot be a REST-style query, namely, there are no query key-value pairs.
    `static void` | `setInstance(RestFactory thisInstance)` Set the rest factory instance if null.
    `WsMethodInfo` | `toMethodInfo(RestMessage restMessage)` Convert the REST-style message back into a method info object.

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

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

- - ### Method Detail

    - #### setInstance

          public static void setInstance(RestFactory thisInstance)

      Set the rest factory instance if null.
      Parameters:
        `thisInstance` - the factory instance.

    - #### getInstance

          public static RestFactory getInstance()

      Get the rest factory instance.
      Returns:
        the value of instance.

    - #### createRestGET

          public RestMessage createRestGET(org.licas_xml.abs.Element serviceUri,
                                           java.lang.String serverPassword,
                                           java.lang.String servicePassword)

      Create a string-based RESTful description to invoke the default GET method on a licas service.
      Parameters:
        `serviceUri` - the `Handle`-based description of the service uri.
        `serverPassword` - the server password. If null, it defaults to `Const`.`ANON`.
        `servicePassword` - the service password. If null, it defaults to `Const`.`ANON`.
      Returns:
        a RestFactory-compatible description of the method details. The first element is the service uri, the second is any additional password parameters.

    - #### createRestMessage

          public RestMessage createRestMessage(WsMethodInfo methodInfo)
                                        throws java.io.UnsupportedEncodingException

      Create a string-based RESTful description of the contents of the method info. NOTE: the values are encoded here. If there is no server URL, then a web service endpoint address is looked for and a rest version of that is constructed, but this is definitely not reliable/compatible and the method works best with the licas method descriptions.
      Parameters:
        `methodInfo` - the method info. Null fields are not included.
      Returns:
        a RestFactory-compatible description of the method details. The first element is the server uri, the second is any additional parameters.
      Throws:
        `java.io.UnsupportedEncodingException` - encoding format not supported. UTF-8.

    - #### createRestMethodHandler

          public Rest_MethodHandler createRestMethodHandler()

      Create the client rest method handler.
      Returns:
        a rest handler for the communication mechanism.

    - #### toMethodInfo

          public WsMethodInfo toMethodInfo(RestMessage restMessage)
                                    throws java.lang.Exception

      Convert the REST-style message back into a method info object.
      Parameters:
        `restMessage` - the rest query.
      Returns:
        a method info object with appropriate parameters filled.
      Throws:
        `java.lang.Exception` - any error.

    - #### notQueryMessage

          public boolean notQueryMessage(java.lang.String message)

      Return true if the message string cannot be a REST-style query, namely, there are no query key-value pairs.
      Parameters:
        `message` - the full rest message.
      Returns:
        true if not a query, there are no `=` symbols.

    - #### encode

          public static java.lang.String encode(java.lang.String queryUri)
                                         throws java.io.UnsupportedEncodingException

      Encode the RestFactory-style query URI, to the application/x-www-form-urlencoded MIME format.
      Parameters:
        `queryUri` - the rest-style query to encode.
      Returns:
        the encoded query. Do not encode starting http or https.
      Throws:
        `java.io.UnsupportedEncodingException` - if the encoding is not supported.

    - #### decode

          public static java.lang.String decode(java.lang.String queryUri)
                                         throws java.io.UnsupportedEncodingException

      Decode the encoded RestFactory-style query URI, from the application/x-www-form-urlencoded MIME format.
      Parameters:
        `queryUri` - the rest-style query to decode.
      Returns:
        the decoded query.
      Throws:
        `java.io.UnsupportedEncodingException` - if the encoding is not supported.