org.licas.meta

## Class MetaFactory

- java.lang.Object
- - org.licas.meta.MetaFactory

-     public class MetaFactory
      extends java.lang.Object

  This class can create metadata parts that can be used to define service creation or initialisation.
  Author:
    Kieran Greer

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MetaFactory()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static org.licas_xml.abs.Element` | `add(org.licas_xml.abs.Element scriptXml, org.licas_xml.abs.Element toAdd)` Add the new XML element to the admin document/script under the appropriate element type.
    `static org.licas_xml.abs.Element` | `add(org.licas_xml.abs.Element scriptXml, org.licas_xml.abs.Element toAdd, java.lang.String type)` Add the new XML element to the admin document/script under the appropriate element type.
    `static void` | `addAttribute(org.licas_xml.abs.Element xmlElem, java.lang.String attrName, java.lang.String attrValue)` Add an attribute to the base XML element that has a `attrName` tag and `attrValue` value.
    `static org.licas_xml.abs.Element` | `createAdmin()` Create an empty Admin XML element that can be used as the base of an admin script.
    `static org.licas_xml.abs.Element` | `createCategory(java.lang.String category)` Create a category element that can be used as part of a script.
    `static org.licas_xml.abs.Element` | `createMeta(java.lang.String metaType)` Create and return an XML element.
    `static org.licas_xml.abs.Element` | `createMetaValue(java.lang.String metaType, java.lang.Object metaValue)` Create an XML element that can be used as part of a script.
    `static org.licas_xml.abs.Element` | `createMethod(java.lang.Class toInvoke, java.lang.String methodName, java.lang.String rtnType)` Parse the object using reflection, to find the first method that matches the spec and return an XML-based description of it.
    `static org.licas_xml.abs.Element` | `createMethod(java.lang.Class toInvoke, java.lang.String methodName, java.lang.String rtnType, java.util.ArrayList<java.lang.String> paramTypes)` Parse the object using reflection, to find the method that matches the spec and return an XML-based description of it.
    `static org.licas_xml.abs.Element` | `createMethod(java.lang.Class toInvoke, java.lang.String methodName, java.lang.String rtnType, java.util.ArrayList<java.lang.String> paramTypes, java.util.ArrayList<java.lang.String> paramNames)` Parse the object using reflection, to find the method that matches the spec and return an XML-based description of it.
    `static org.licas_xml.abs.Element` | `createParser(java.lang.String toParseClass, java.lang.String parserClass, java.util.ArrayList<java.lang.String> jarFiles)` Create an XML element that can be used as part of a script to define a parser to dynamically create and use, to parse a specified Java object to or from XML.
    `static org.licas_xml.abs.Element` | `createPolicy()` Create a Policy element that can be used as the base for the policy script, as in `<Policy></Policy>`.
    `static MetaFactoryAI` | `getFactoryAI()` Get the meta factory related to AI elements.
    `static MetaFactoryData` | `getFactoryData()` Get the meta factory related to data elements.
    `static MetaFactoryService` | `getFactoryService()` Get the meta factory related to service metadata.
    `static org.licas_xml.abs.Element` | `objectToXml(java.lang.Object theObject)` Convert the known object to XML using the known parser.
    `static void` | `parsedObjTypeAttr(org.licas_xml.abs.Element xmlElem, java.lang.String className)` Format the XML-based description of a Java Object, to make sure that it will be interpreted correctly by the automatic licas parsers.
    `static void` | `replaceValue(org.licas_xml.abs.Element metaXml, java.util.ArrayList<KeyValue> valueList)` Replace element text values that may be tagged with the equivalent value from the key-value list.

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

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

- - ### Constructor Detail

    - #### MetaFactory

          public MetaFactory()

  - ### Method Detail

    - #### createPolicy

          public static org.licas_xml.abs.Element createPolicy()

      Create a Policy element that can be used as the base for the policy script, as in `<Policy></Policy>`.
      Returns:
        an XML element that defines the policy element.

    - #### createCategory

          public static org.licas_xml.abs.Element createCategory(java.lang.String category)

      Create a category element that can be used as part of a script. This method creates a script with just a category description, as in `<Service_Category>category</Service_Category>`.
      Parameters:
        `category` - the category type to add.
      Returns:
        an XML element that defines the service to load.

    - #### createMethod

          public static org.licas_xml.abs.Element createMethod(java.lang.Class toInvoke,
                                                               java.lang.String methodName,
                                                               java.lang.String rtnType)

      Parse the object using reflection, to find the first method that matches the spec and return an XML-based description of it. As no parameters are declared, only the parameter type is returned and different parameter sets cannot be considered.
      Parameters:
        `toInvoke` - class of the object to invoke.
        `methodName` - the name of the method to invoke. This is required.
        `rtnType` - the method return type. Can be null for no match.
      Returns:
        an XML-based description of the method to invoke, or null if there was no match.

    - #### createMethod

          public static org.licas_xml.abs.Element createMethod(java.lang.Class toInvoke,
                                                               java.lang.String methodName,
                                                               java.lang.String rtnType,
                                                               java.util.ArrayList<java.lang.String> paramTypes,
                                                               java.util.ArrayList<java.lang.String> paramNames)

      Parse the object using reflection, to find the method that matches the spec and return an XML-based description of it.
      Parameters:
        `toInvoke` - class of the object to invoke.
        `methodName` - the name of the method to invoke. This is required.
        `rtnType` - the method return type. Can be null for no match.
        `paramTypes` - list of parameter types to match to.
        `paramNames` - a list of names that get added to each parameter in order. This also serves to specify the number of required parameters. If null, then the first match is returned and only the parameter type is defined.
      Returns:
        an XML-based description of the method to invoke, or null if there was no match.

    - #### createMethod

          public static org.licas_xml.abs.Element createMethod(java.lang.Class toInvoke,
                                                               java.lang.String methodName,
                                                               java.lang.String rtnType,
                                                               java.util.ArrayList<java.lang.String> paramTypes)

      Parse the object using reflection, to find the method that matches the spec and return an XML-based description of it.
      Parameters:
        `toInvoke` - class of the object to invoke.
        `methodName` - the name of the method to invoke. This is required.
        `rtnType` - the method return type. Can be null for no match.
        `paramTypes` - list of parameter types to match to.
      Returns:
        an XML-based description of the method to invoke, or null if there was no match.

    - #### createAdmin

          public static org.licas_xml.abs.Element createAdmin()

      Create an empty Admin XML element that can be used as the base of an admin script. This method creates an admin script with just a root element, as in `<Admin></Admin>` that then needs to be populated with other elements.
      Returns:
        an XML element that defines the service to load.

    - #### addAttribute

          public static void addAttribute(org.licas_xml.abs.Element xmlElem,
                                          java.lang.String attrName,
                                          java.lang.String attrValue)

      Add an attribute to the base XML element that has a `attrName` tag and `attrValue` value. This will overwrite any existing attribute.
      Parameters:
        `xmlElem` - the element to add the attribute to.
        `attrName` - the name of the attribute
        `attrValue` - the value of the attribute.

    - #### add

          public static org.licas_xml.abs.Element add(org.licas_xml.abs.Element scriptXml,
                                                      org.licas_xml.abs.Element toAdd)

      Add the new XML element to the admin document/script under the appropriate element type.
      Parameters:
        `scriptXml` - the current admin document/script. Can use `createAdminXML` to create an empty admin document, for example.
        `toAdd` - the XML element to add to the script.
      Returns:
        the newly created admin document.

    - #### add

          public static org.licas_xml.abs.Element add(org.licas_xml.abs.Element scriptXml,
                                                      org.licas_xml.abs.Element toAdd,
                                                      java.lang.String type)

      Add the new XML element to the admin document/script under the appropriate element type.
      Parameters:
        `scriptXml` - the current admin document/script. Can use `createAdminXML` to create an empty admin document, for example.
        `toAdd` - the XML element to add to the script.
        `type` - the type of element to add, see the admin user guide spec for examples. If `null`, then the element gets added to `scriptXml` directly. If not null, then its type can be checked for correctness. Currently, the only manual correction is for `MetaConst.AISOLVER` that creates an `Const.OTHERMETA` element only and then adds the new element to that. Otherwise, a child element of `scriptXml`, with the the `Name` of `type` is retrieved and the new element is added to that. If there is no element with that name, it gets added to `scriptXml` again. This is related to parsing problem solving scripts.
      Returns:
        the newly created admin document.

    - #### createParser

          public static org.licas_xml.abs.Element createParser(java.lang.String toParseClass,
                                                               java.lang.String parserClass,
                                                               java.util.ArrayList<java.lang.String> jarFiles)

      Create an XML element that can be used as part of a script to define a parser to dynamically create and use, to parse a specified Java object to or from XML.
      Parameters:
        `toParseClass` - this can be used to define the class type that should be parsed. It can also be null if the invoking object already knows the object to parse.
        `parserClass` - this defines the class type of the parser itself. The parser should probably extend the ParserDef interface, but it does not get added to the default list automatically and so this is optional and implementation-dependent.
        `jarFiles` - a list of jar files if the parser is from an external source.
      Returns:
        an XML element that defines the service to load. This might look like: `<Parser><To_Parse_Class>Optional class to parse</To_Parse_Class> <Parser_Class>Parser class name</Parser_Class><Jar_Files><Jar_File>Jar file path</Jar_File> </Jar_Files></Parser>`

    - #### createMeta

          public static org.licas_xml.abs.Element createMeta(java.lang.String metaType)

      Create and return an XML element. This method creates an empty element with the specified name, as in `<metaType></metaType>` and is just for convenience.
      Parameters:
        `metaType` - the metadata element name.
      Returns:
        the created XML element.

    - #### createMetaValue

          public static org.licas_xml.abs.Element createMetaValue(java.lang.String metaType,
                                                                  java.lang.Object metaValue)

      Create an XML element that can be used as part of a script. This method creates an XML element with the specified name, but then adds either a string or nested XML to that, depending on what the value is, as in `<metaType>String or Nested XML value</metaType>`.
      Parameters:
        `metaType` - the metadata element name.
        `metaValue` - the value for the element. this should be either a String or XML.
      Returns:
        an XML element that defines the service to load.

    - #### replaceValue

          public static void replaceValue(org.licas_xml.abs.Element metaXml,
                                          java.util.ArrayList<KeyValue> valueList)

      Replace element text values that may be tagged with the equivalent value from the key-value list.
      Parameters:
        `metaXml` - the xml script that can have element values with some name.
        `valueList` - a list of `KeyValue` objects, where if the key matches any element value, the value is replaced by the KeyValue value, as a String cast.

    - #### parsedObjTypeAttr

          public static void parsedObjTypeAttr(org.licas_xml.abs.Element xmlElem,
                                               java.lang.String className)

      Format the XML-based description of a Java Object, to make sure that it will be interpreted correctly by the automatic licas parsers. This involves adding a class name attribute to the base XML element that has a `Const.CONVERSIONTYPE` tag. The conversion type is required for the automatic parsing and should be added to the base element, if the XML description is being created manually. This will overwrite any existing attribute.
      Parameters:
        `xmlElem` - the XML-based or parsed description of the Java object.
        `className` - the fully qualified class name of the object that was parsed.

    - #### objectToXml

          public static org.licas_xml.abs.Element objectToXml(java.lang.Object theObject)
                                                       throws java.lang.Exception

      Convert the known object to XML using the known parser. This calls `Parsers.serializeToString(...)` to serializeToString the Object to an XML `Element` reply.
      Parameters:
        `theObject` - the object to parse, including its values. The object must already be known by `Parsers`, including having added its parser.
      Returns:
        the object serialized into an XML-based description, or null if the serialization was not successful.
      Throws:
        `java.lang.Exception` - any error.

    - #### getFactoryService

          public static MetaFactoryService getFactoryService()

      Get the meta factory related to service metadata.
      Returns:
        the value of factoryService.

    - #### getFactoryData

          public static MetaFactoryData getFactoryData()

      Get the meta factory related to data elements.
      Returns:
        the value of factoryData.

    - #### getFactoryAI

          public static MetaFactoryAI getFactoryAI()

      Get the meta factory related to AI elements.
      Returns:
        the value of factoryAI.