org.licas.util

## Class ObjectHandler

- java.lang.Object
- - org.licas.util.ObjectHandler

-     public class ObjectHandler
      extends java.lang.Object

  This class provides methods to process or compare objects, with reference to licas objects in particular. Note that you can add a `getKey()` method to your own object and this class will try to use it with its own `getKey` method.
  Author:
    Kieran Greer

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ObjectHandler()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `classInstance(java.lang.Class param1, java.lang.Class param2)` Check if the two parameters match with regard to class type.
    `static boolean` | `classInstance(java.lang.Class param1, java.lang.Object obj2)` Check if the two parameters match with regard to class type.
    `static java.lang.Object` | `convertParameter(java.lang.Object param)` Try to convert the parameter into an Object if possible.
    `static java.lang.Object` | `dataXmlToValue(org.licas_xml.abs.Element dataXml)` Parse the data element from the service info to create the related Java Object.
    `static boolean` | `equals(java.lang.Object ob1, java.lang.Object ob2)` Return true if the two objects are equal to each other as defined by this method.
    `static java.lang.String` | `getClass(java.lang.Object theObject)` Return the object class name in a format suitable for logging.
    `static org.licas_xml.abs.Element` | `getElementPath(java.lang.Object ob1)` Return an Element defining the path to the object specified.
    `static java.lang.String` | `getKey(java.lang.Object ob1)` Return the key relating to the object specified.
    `static java.lang.String` | `getValue(java.lang.Object theValue)` Return a String-based representation of the object value.
    `static boolean` | `isArrayList(java.lang.String type)` Return true if type is an ArrayList type.
    `static boolean` | `isArrayType(java.lang.String type)` Return true if type is an array type type.
    `static boolean` | `isBoolean(java.lang.Object obj)` Return true if the object indicates a Boolean object.
    `static boolean` | `isElement(java.lang.Object obj)` Return true if the object indicates an XML element.
    `static boolean` | `isHashMap(java.lang.String type)` Return true if type is a HashMap type.
    `static boolean` | `isHashtable(java.lang.String type)` Return true if type is a Hashtable type.
    `static boolean` | `isLinkedHashMap(java.lang.String type)` Return true if type is a LinkedHashMap type.
    `static boolean` | `isLinkedList(java.lang.String type)` Return true if type is a LinkedList type.
    `static boolean` | `isNull(java.lang.Object obj)` Return true if the object represents the null type.
    `static boolean` | `isObject(java.lang.Object obj)` Return true if the object indicates the base Object type.
    `static boolean` | `isStack(java.lang.String type)` Return true if type is a Stack type.
    `static boolean` | `isString(java.lang.Object obj)` Return true if the object indicates a String object.
    `static boolean` | `isVector(java.lang.String type)` Return true if type is a Vector type.
    `static long` | `sizeOf(java.lang.Object theObj)` For actual object instances, but not sure how accurate or how to use best.
    `static java.lang.String` | `toObjectClass(java.lang.String paramClass)` Convert a primitive type class description into the related object description.
    `static java.lang.String` | `typeCode(java.lang.String type)` Return a code value for the type if one exists.
    `static java.lang.Object` | `valueFromString(java.lang.String valueType, java.lang.String value)` Convert the String representation to the value object.
    `static boolean` | `valueIsFalse(java.lang.Object var)` Return true if the variable indicates a false value.
    `static boolean` | `valueIsTrue(java.lang.Object var)` Return true if the variable indicates a true value.
    `static java.lang.String` | `valueToString(java.lang.String valueType, java.lang.Object value)` Return the value as a String.

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

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

- - ### Constructor Detail

    - #### ObjectHandler

          public ObjectHandler()

  - ### Method Detail

    - #### getKey

          public static java.lang.String getKey(java.lang.Object ob1)
                                         throws java.lang.Exception

      Return the key relating to the object specified. If the object is derived from a licas Service, then its uuid is returned, if the object is an Element, then its String equivalent is returned. If the object is complex, then if it implements a `getKey()` method, an attempt to invoke that is tried, if that fails then the `String` value of the object is returned.
      Parameters:
        `ob1` - the representation of the object.
      Returns:
        the key value for the source.
      Throws:
        `java.lang.Exception` - any error.

    - #### getValue

          public static java.lang.String getValue(java.lang.Object theValue)
                                           throws java.lang.Exception

      Return a String-based representation of the object value. This either parses an XML-based value or returns `String.valueOf()`. If the value is a service, then it will try to retrieve the uuid name.
      Parameters:
        `theValue` - the object value to describe.
      Returns:
        the object value in String format.
      Throws:
        `java.lang.Exception` - any error.

    - #### getClass

          public static java.lang.String getClass(java.lang.Object theObject)

      Return the object class name in a format suitable for logging.
      Parameters:
        `theObject` - the object to describe.
      Returns:
        the object class name in String format.

    - #### getElementPath

          public static org.licas_xml.abs.Element getElementPath(java.lang.Object ob1)
                                                          throws java.lang.Exception

      Return an Element defining the path to the object specified. If the object is derived from a licas Service, then the getFullPath() method is used to retrieve the path. If the object is an Element then it is returned as it is, otherwise the element is constructed as follows: The Handle class is used to create a handle with the uri of the current server, The String.valueOf value of the object is then used to add a handle part to the whole handle and this is then returned. This is not a reliable option however and the value passed in should be either a Service or an Element.
      Parameters:
        `ob1` - the representation of the object.
      Returns:
        the path value for the source.
      Throws:
        `java.lang.Exception` - any error.

    - #### equals

          public static boolean equals(java.lang.Object ob1,
                                       java.lang.Object ob2)
                                throws java.lang.Exception

      Return true if the two objects are equal to each other as defined by this method. If the objects are derived from licas Services, then their uuids are compared. If they are XML elements then the element values are compared. If they are strings then the String.equals is used, otherwise Object.equals is used.
      Parameters:
        `ob1` - the first object to compare.
        `ob2` - the second object to compare.
      Returns:
        true if the objects are the same as defined by this method.
      Throws:
        `java.lang.Exception` - any error.

    - #### convertParameter

          public static java.lang.Object convertParameter(java.lang.Object param)

      Try to convert the parameter into an Object if possible.
      Parameters:
        `param` - the parameter in String format. Can also represent a list.
      Returns:
        the parameter converted into an other Object format if required.

    - #### classInstance

          public static boolean classInstance(java.lang.Class param1,
                                              java.lang.Object obj2)

      Check if the two parameters match with regard to class type. Consider super classes of the second parameter.
      Parameters:
        `param1` - the first parameter class. Also the base class to match.
        `obj2` - the parameter object that might be of that type.
      Returns:
        true if the parameters match.

    - #### classInstance

          public static boolean classInstance(java.lang.Class param1,
                                              java.lang.Class param2)

      Check if the two parameters match with regard to class type. Consider super classes of the second parameter.
      Parameters:
        `param1` - the first parameter class. Also the base class to match.
        `param2` - the second parameter class that might be of that type.
      Returns:
        true if the parameters match.

    - #### toObjectClass

          public static java.lang.String toObjectClass(java.lang.String paramClass)

      Convert a primitive type class description into the related object description.
      Parameters:
        `paramClass` - string-based description of the class.
      Returns:
        same description, or the object type description for a primitive type.

    - #### typeCode

          public static java.lang.String typeCode(java.lang.String type)

      Return a code value for the type if one exists.
      Parameters:
        `type` - the object type.
      Returns:
        a smaller code value if one exists.

    - #### isBoolean

          public static boolean isBoolean(java.lang.Object obj)

      Return true if the object indicates a Boolean object.
      Parameters:
        `obj` - the object to check.
      Returns:
        true if a Boolean, false if not or error.

    - #### isString

          public static boolean isString(java.lang.Object obj)

      Return true if the object indicates a String object.
      Parameters:
        `obj` - the object to check.
      Returns:
        true if a String, false if not or error.

    - #### isElement

          public static boolean isElement(java.lang.Object obj)

      Return true if the object indicates an XML element.
      Parameters:
        `obj` - the object to check.
      Returns:
        true if a licas or dom XML element, false if not or error.

    - #### isObject

          public static boolean isObject(java.lang.Object obj)

      Return true if the object indicates the base Object type.
      Parameters:
        `obj` - the object to check.
      Returns:
        true if the base Object type, false if not or error.

    - #### isArrayType

          public static boolean isArrayType(java.lang.String type)

      Return true if type is an array type type.
      Parameters:
        `type` - the object type.
      Returns:
        true if type starts with the array type bracket [.

    - #### isArrayList

          public static boolean isArrayList(java.lang.String type)

      Return true if type is an ArrayList type.
      Parameters:
        `type` - the object type.
      Returns:
        true if type is an ArrayList type.

    - #### isVector

          public static boolean isVector(java.lang.String type)

      Return true if type is a Vector type.
      Parameters:
        `type` - the object type.
      Returns:
        true if type is a Vector type.

    - #### isLinkedList

          public static boolean isLinkedList(java.lang.String type)

      Return true if type is a LinkedList type.
      Parameters:
        `type` - the object type.
      Returns:
        true if type is a LinkedList type.

    - #### isHashtable

          public static boolean isHashtable(java.lang.String type)

      Return true if type is a Hashtable type.
      Parameters:
        `type` - the object type.
      Returns:
        true if type is a Hashtable type.

    - #### isHashMap

          public static boolean isHashMap(java.lang.String type)

      Return true if type is a HashMap type.
      Parameters:
        `type` - the object type.
      Returns:
        true if type is a HashMap type.

    - #### isLinkedHashMap

          public static boolean isLinkedHashMap(java.lang.String type)

      Return true if type is a LinkedHashMap type.
      Parameters:
        `type` - the object type.
      Returns:
        true if type is a LinkedHashMap type.

    - #### isStack

          public static boolean isStack(java.lang.String type)

      Return true if type is a Stack type.
      Parameters:
        `type` - the object type.
      Returns:
        true if type is a Stack type.

    - #### valueIsTrue

          public static boolean valueIsTrue(java.lang.Object var)

      Return true if the variable indicates a true value.
      Parameters:
        `var` - the variable to check. Can be Boolean, String or query OK element.
      Returns:
        true if the variable contains a true boolean value.

    - #### valueIsFalse

          public static boolean valueIsFalse(java.lang.Object var)

      Return true if the variable indicates a false value.
      Parameters:
        `var` - the variable to check. Can be Boolean, String or query Not_OK element.
      Returns:
        true if the variable contains a true boolean value.

    - #### isNull

          public static boolean isNull(java.lang.Object obj)

      Return true if the object represents the null type.
      Parameters:
        `obj` - the object to check.
      Returns:
        true if null or `Const`.`NULL`.

    - #### sizeOf

          public static long sizeOf(java.lang.Object theObj)

      For actual object instances, but not sure how accurate or how to use best.
      Parameters:
        `theObj` - the object instance to measure.
      Returns:
        the object size in bytes.

    - #### dataXmlToValue

          public static java.lang.Object dataXmlToValue(org.licas_xml.abs.Element dataXml)
                                                 throws java.lang.Exception

      Parse the data element from the service info to create the related Java Object.
      Parameters:
        `dataXml` - this is the base data or dataset element with nested elements that include directly, `Const`.`DATATYPE`, `DATASETTYPE` and then `VALUE` elements for parsing. If they are missing, a `convertParameter` call is tried on the whole XML object.
      Returns:
        the data value if the XML element is in the correct format, or null otherwise.
      Throws:
        `java.lang.Exception` - any error.

    - #### valueToString

          public static java.lang.String valueToString(java.lang.String valueType,
                                                       java.lang.Object value)
                                                throws java.lang.Exception

      Return the value as a String. If the value type is not recognised, then a `String.valueOf(value)` is returned.
      Parameters:
        `valueType` - the type of the value.
        `value` - the value.
      Returns:
        a String description of the value.
      Throws:
        `java.lang.Exception` - any error.

    - #### valueFromString

          public static java.lang.Object valueFromString(java.lang.String valueType,
                                                         java.lang.String value)
                                                  throws java.lang.Exception

      Convert the String representation to the value object.
      Parameters:
        `valueType` - the type of the value.
        `value` - the value as a String.
      Returns:
        the value as its correct object.
      Throws:
        `java.lang.Exception` - any error.