org.licas.service.resource.container

## Class ResourceContainer

- java.lang.Object
- - org.licas.service.resource.Resource
  - - org.licas.service.resource.container.ResourceContainer

- Direct Known Subclasses:
    ListContainer, QueryContainer, RandomContainer

      public abstract class ResourceContainer
      extends Resource

  This can be used to store an array or set of `Resource` derived objects that can then be invoked upon request. The resource objects do not have to be of the same type and it is their `getInfo` or `getValue` methods that are invoked. A container might be initialised with a script that includes the details of the stored resources.
  To create the script, for example, you might use `MetaFactory.getFactoryData().createResourceContainerXML(containerType)` and then add to the element: `containerXml.valueXml.addContent(MetaFactory.getFactoryData().createDataValueXML(dataType, infoData))`.
  You can also create an empty list and add resources manually to it.
  Author:
    Kieran Greer

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.LinkedHashMap<java.lang.String,Resource>` | `resourceList` The object-based information

    - ### Fields inherited from class org.licas.service.resource.Resource

      `dataType, INFOANYTYPE, INFOBINARYTYPE, INFOHTMLTYPE, INFOSTREAMXMLTYPE, INFOSTRINGTYPE, INFOTEXTTYPE, INFOURLTYPE, INFOXMLTYPE, LISTCONTAINERTYPE, QUERYCONTAINERTYPE, RANDOMCONTAINERTYPE, uuid`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceContainer(java.lang.String theDataType)` Create a new instance of ResourceContainer.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `addResource(Resource resource)` Add a new resource.
    `static Resource` | `createContainer(java.lang.String dataType, org.licas_xml.abs.Element dataXml)` Create a resource container object and return.
    `Resource` | `getResource(java.lang.String key)` Get the resource relating to the key identifier.
    `java.util.ArrayList<java.lang.String>` | `getResourceIDs()` Get a list of IDs used to identify each resource in the container.
    `protected boolean` | `parseInfo(org.licas_xml.abs.Element dataXml)` Parse the data description in the admin document to create the data object.
    `boolean` | `removeResource(java.lang.String key)` Remove the resource relating to the key identifier.

    - ### Methods inherited from class org.licas.service.resource.Resource

      `createResource, dataFromResourceType, getDataType, getInfo, getUUID, getValue, parseValueElem, resourceTypeForDataType, setUUID, setUUID`

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

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

- - ### Field Detail

    - #### resourceList

          protected java.util.LinkedHashMap<java.lang.String,Resource> resourceList

      The object-based information

  - ### Constructor Detail

    - #### ResourceContainer

          public ResourceContainer(java.lang.String theDataType)
                            throws java.lang.Exception

      Create a new instance of ResourceContainer.
      Parameters:
        `theDataType` - the container type.
      Throws:
        `java.lang.Exception` - any error.

  - ### Method Detail

    - #### parseInfo

          protected boolean parseInfo(org.licas_xml.abs.Element dataXml)
                               throws java.lang.Exception

      Parse the data description in the admin document to create the data object.
      Specified by:
        `parseInfo` in class `Resource`
      Parameters:
        `dataXml` - the `Data` element of the admin document. This should include the container `DataType` element and a `Value` element that stores a list of child `Data` elements that store information for each resource to create. These are processed as defined in the individual resource object comments.
      Returns:
        true if any specified resources are successfully added, false otherwise.
      Throws:
        `java.lang.Exception` - any error.

    - #### getResourceIDs

          public java.util.ArrayList<java.lang.String> getResourceIDs()

      Get a list of IDs used to identify each resource in the container.
      Returns:
        a list of ids to identify each resource in the container.

    - #### addResource

          public boolean addResource(Resource resource)

      Add a new resource. Use its uuid as the key.
      Parameters:
        `resource` - the resource to add.
      Returns:
        true if added, false if the key already exists.

    - #### getResource

          public Resource getResource(java.lang.String key)

      Get the resource relating to the key identifier.
      Parameters:
        `key` - unique uuid identifier for the resource.
      Returns:
        the related resource or null if one does not exist.

    - #### removeResource

          public boolean removeResource(java.lang.String key)

      Remove the resource relating to the key identifier.
      Parameters:
        `key` - unique uuid identifier for the resource.
      Returns:
        true if removed or false if one does not exist.

    - #### createContainer

          public static Resource createContainer(java.lang.String dataType,
                                                 org.licas_xml.abs.Element dataXml)
                                          throws java.lang.Exception

      Create a resource container object and return. The resource that is created is selected automatically from the data type and so is a best match guess.
      Parameters:
        `dataType` - the type of container to create, for example: `TypeConst`.`IDCONTAINER`, `RANDOMCONTAINER` or `QUERYCONTAINER`.
        `dataXml` - a description of the initialisation parameters. Can be null.
      Returns:
        a matched info resource or null if the type is not recognised.
      Throws:
        `java.lang.Exception` - any error.