TypeDefinitionSetImpl (Media Authoring with Java API)
Date: 2016-02-05

tv.amwa.maj.meta.impl

## Class TypeDefinitionSetImpl

- java.lang.Object
- - tv.amwa.maj.meta.impl.MetaDefinitionImpl
  - - tv.amwa.maj.meta.impl.TypeDefinitionImpl
    - - tv.amwa.maj.meta.impl.TypeDefinitionSetImpl

- All Implemented Interfaces:
    Serializable, Cloneable, CommonConstants, MetadataObject, WeakReferenceTarget, MetaDefinition, TypeDefinition, TypeDefinitionSet, DefinitionType

      @MediaClass(uuid1=218169601,
                  uuid2=522,
                  uuid3=0,
                  uuid4={6,14,43,52,2,6,1,1},
                  definedName="TypeDefinitionSet",
                  description="The TypeDefinitionSet class defines a property type that has a collection of object references to uniquely identified objects. The order of the objects has no meaning.",
                  symbol="TypeDefinitionSet")
      public final class TypeDefinitionSetImpl
      extends TypeDefinitionImpl
      implements TypeDefinitionSet, Serializable, Cloneable

  Implements the definition of a property type that has a collection of object references to uniquely identified objects. The order of the objects has no meaning.

  See Also:
    `MediaSetAdd`, `MediaPropertyRemove`, `MediaPropertyCount`, `MediaPropertyContains`, `MediaPropertyClear`, Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `TypeDefinitionSetImpl.SetMethodBag`
    `static class` | `TypeDefinitionSetImpl.SetValue`

    - ### Nested classes/interfaces inherited from class tv.amwa.maj.meta.impl.TypeDefinitionImpl

      `TypeDefinitionImpl.PropertyValueImpl`

  - ### Field Summary

    - ### Fields inherited from interface tv.amwa.maj.constant.CommonConstants

      `AAF_METADICT_NAMESPACE, AAF_METADICT_PREFIX, AAF_XML_NAMESPACE, AAF_XML_PREFIX, ApplicationPluginObjectID, ApplicationPluginsID, MAX_NUM_RGBA_COMPS, MemberOfID, ObjectClassID, ParentClassID, PropertiesID, XMLClassIDAsAttributeName`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TypeDefinitionSetImpl(AUID identification, String typeName, TypeDefinition elementType)` Creates and initializes the set type definition, which defines a property type that has a collection of object references to uniquely identified objects.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addElement(PropertyValue setPropertyValue, PropertyValue elementPropertyValue)` Adds the given element to the given set, which is represented by the given property value of this set type definition.
    `void` | `appendMetadictXML(Node metadict, String namespace, String prefix)` Append an XML representation of this meta definition to the given XML node.
    `TypeDefinitionSet` | `clone()` Create a cloned copy of this meta definition.
    `boolean` | `containsElement(PropertyValue setPropertyValue, PropertyValue elementPropertyValue)` Returns `true` if the given element is contained in the given set; otherwise `false`.
    `PropertyValue` | `createEmptySet()` Create a property value with an empty set, ready to hold property values of this type definitions element type.
    `PropertyValue` | `createFromBytes(ByteBuffer buffer)` Create a value of this type by reading the bytes in the given byte buffer.
    `PropertyValue` | `createValue(Object javaValue)` Create a property value from the given Java object.
    `int` | `getCount(PropertyValue setPropertyValue)` Returns the number of elements in the given set, or -1 if the set is `null`.
    `Set<PropertyValue>` | `getElements(PropertyValue setPropertyValue)` Returns a copy of the set of all the elements in the given set property value.
    `TypeDefinition` | `getElementType()` Returns the type of elements referenced from the defined set.
    `TypeCategory` | `getTypeCategory()` Returns the type category to which this type definition belongs, which corresponds to its sub interface.
    `static TypeDefinition` | `initializeSetElementType()`
    `long` | `lengthAsBytes(PropertyValue value)` Returns the number of bytes that the given value of this type is serialized as a sequence of bytes.
    `String` | `nameToAAFName(String name)`
    `void` | `removeElement(PropertyValue setPropertyValue, PropertyValue elementPropertyValue)` Removes the given element from the given set, which is represented by the given property value of this set type definition.
    `boolean` | `resolveReferences(PropertyValue value, Map<AUID,MetadataObject> referenceMap)` Resolve any unresolved object references using the given reference map.
    `void` | `setElementType(TypeDefinition elementType)`
    `void` | `setPropertyValue(MetadataObject metadataObject, PropertyDefinition property, PropertyValue value)` On the given metadata object, set the specified property to the given value.
    `List<PropertyValue>` | `writeAsBytes(PropertyValue value, ByteBuffer buffer)` Write the given property value of this type to the given byte stream.

    - ### Methods inherited from class tv.amwa.maj.meta.impl.TypeDefinitionImpl

      `getNamespace, getPrefix, getPropertyValue, initalizeTypeNameMap, writeAsStructuredStorageBytes`

    - ### Methods inherited from class tv.amwa.maj.meta.impl.MetaDefinitionImpl

      `aafNameToName, appendXMLChildren, deepEquals, equals, getAAFNamesInUse, getAliases, getAUID, getComment, getDescription, getIdentification, getName, getSymbol, getWeakTargetReference, hashCode, initializeMetaDefinitionIdentification, initializeMetaDefinitionName, setAAFNamesInUse, setAliases, setDescription, setIdentification, setName, setNamespace, setPrefix, setSymbol, toString`

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

      `getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface tv.amwa.maj.meta.TypeDefinition

      `getPropertyValue, writeAsStructuredStorageBytes`

    - ### Methods inherited from interface tv.amwa.maj.meta.MetaDefinition

      `deepEquals, equals, getAAFNamesInUse, getAliases, getAUID, getDescription, getName, getNamespace, getPrefix, getSymbol, hashCode, setAAFNamesInUse, setDescription, setName, setNamespace, setPrefix, setSymbol, toString`

    - ### Methods inherited from interface tv.amwa.maj.industry.WeakReferenceTarget

      `getWeakTargetReference`

- - ### Constructor Detail

    - #### TypeDefinitionSetImpl

          public TypeDefinitionSetImpl(AUID identification,
                                       @AAFString
                                       String typeName,
                                       TypeDefinition elementType)
                                throws NullPointerException

      Creates and initializes the set type definition, which defines a property type that has a collection of object references to uniquely identified objects. The order of the objects has no meaning.

      Creating new and unregistered type definitions is not recommended as this may cause interoperability issues with other systems. The official registry of type definitions is available from SMPTE at SMPTE Metadata Registries And Related Items. The full range of data types documented in the AAF 1.1 object specification can be accessed by name and identification using either `Warehouse.lookForType(String)` or `Warehouse.lookForType(tv.amwa.maj.record.AUID)` respectively.

      Parameters:
        `identification` - AUID to be used to identify this type of set.
        `typeName` - Friendly name for this type definition.
        `elementType` - Type definition of each element contained in this set.
      Throws:
        `NullPointerException` - The identification and/or element type arguments is/are `null`.

  - ### Method Detail

    - #### addElement

          public void addElement(PropertyValue setPropertyValue,
                                 PropertyValue elementPropertyValue)
                          throws NullPointerException,
                                 IllegalPropertyValueException

      Description copied from interface: `TypeDefinitionSet`

      Adds the given element to the given set, which is represented by the given property value of this set type definition.

      Specified by:
        `addElement` in interface `TypeDefinitionSet`
      Parameters:
        `setPropertyValue` - Set to add the given element to.
        `elementPropertyValue` - Element to add to the given set.
      Throws:
        `NullPointerException` - One or both of the arguments is/are `null`.
        `IllegalPropertyValueException` - The type of the given property value does not match this set type definition.

    - #### containsElement

          public boolean containsElement(PropertyValue setPropertyValue,
                                         PropertyValue elementPropertyValue)
                                  throws NullPointerException,
                                         IllegalPropertyValueException

      Description copied from interface: `TypeDefinitionSet`

      Returns `true` if the given element is contained in the given set; otherwise `false`. The set to test membership for is represented by the given property value of this set type definition.

      Specified by:
        `containsElement` in interface `TypeDefinitionSet`
      Parameters:
        `setPropertyValue` - Set to check for the given element.
        `elementPropertyValue` - Element to check for in the given set.
      Returns:
        Is the given element contained in the given set?
      Throws:
        `NullPointerException` - One or both of the arguments is/are `null`.
        `IllegalPropertyValueException` - The type of the given property value does not match this set type definition.

    - #### getCount

          public int getCount(PropertyValue setPropertyValue)
                       throws NullPointerException,
                              IllegalPropertyValueException

      Description copied from interface: `TypeDefinitionSet`

      Returns the number of elements in the given set, or -1 if the set is `null`. The set to count the members for is represented by the given property value of this set type definition.

      Specified by:
        `getCount` in interface `TypeDefinitionSet`
      Parameters:
        `setPropertyValue` - Property value containing a set.
      Returns:
        Number of elements in the given set.
      Throws:
        `NullPointerException` - The given set property value is `null`.
        `IllegalPropertyValueException` - The type of the given property value does not match this set type definition.

    - #### getElementType

          @MediaProperty(uuid1=100729095,
                         uuid2=3584,
                         uuid3=0,
                         uuid4={6,14,43,52,1,1,1,2},
                         definedName="SetElementType",
                         aliases="ElementType",
                         typeName="TypeDefinitionWeakReference",
                         optional=false,
                         uniqueIdentifier=false,
                         pid=26,
                         symbol="SetElementType")
          public TypeDefinition getElementType()

      Description copied from interface: `TypeDefinitionSet`

      Returns the type of elements referenced from the defined set.

      Specified by:
        `getElementType` in interface `TypeDefinitionSet`
      Returns:
        Type of elements referenced from the defined set.
      See Also:
        `TypeDefinitionObjectReference.getObjectType()`

    - #### setElementType

          @MediaPropertySetter(value="SetElementType")
          public void setElementType(TypeDefinition elementType)
                                                                           throws NullPointerException

      Throws:
        `NullPointerException`

    - #### initializeSetElementType

          public static final TypeDefinition initializeSetElementType()

    - #### getElements

          public Set<PropertyValue> getElements(PropertyValue setPropertyValue)
                                         throws NullPointerException,
                                                IllegalPropertyValueException

      Description copied from interface: `TypeDefinitionSet`

      Returns a copy of the set of all the elements in the given set property value.

      Specified by:
        `getElements` in interface `TypeDefinitionSet`
      Parameters:
        `setPropertyValue` - Property value to read and returns the elements for.
      Returns:
        Shallow copy of the value of the given set property value.
      Throws:
        `NullPointerException` - The given set property value is `null`.
        `IllegalPropertyValueException` - The type of the given argument does not match this set type definition.

    - #### removeElement

          public void removeElement(PropertyValue setPropertyValue,
                                    PropertyValue elementPropertyValue)
                             throws NullPointerException,
                                    IllegalPropertyValueException,
                                    BadTypeException,
                                    ObjectNotFoundException

      Description copied from interface: `TypeDefinitionSet`

      Removes the given element from the given set, which is represented by the given property value of this set type definition.

      Specified by:
        `removeElement` in interface `TypeDefinitionSet`
      Parameters:
        `setPropertyValue` - Set to remove the given element from.
        `elementPropertyValue` - Element to remove from the given set.
      Throws:
        `NullPointerException` - One or both of the arguments is/are `null`.
        `IllegalPropertyValueException` - The type of the given property value does not match this set type definition.
        `BadTypeException` - The type of the given element for removal does not match the element type of this set type definition.
        `ObjectNotFoundException` - The given element to remove cannot be found in the given set property value.

    - #### createEmptySet

          public PropertyValue createEmptySet()

      Description copied from interface: `TypeDefinitionSet`

      Create a property value with an empty set, ready to hold property values of this type definitions element type. Call `TypeDefinitionSet.addElement(PropertyValue, PropertyValue)` to add elements to this set.

      Specified by:
        `createEmptySet` in interface `TypeDefinitionSet`
      Returns:
        New property value containing an empty set.

    - #### createValue

          public PropertyValue createValue(Object javaValue)
                                    throws ClassCastException

      Description copied from class: `TypeDefinitionImpl`

      Create a property value from the given Java object. If the type of the object is not compatible with this type definition, a `ClassCastException` is thrown.

      Specified by:
        `createValue` in interface `TypeDefinition`
      Specified by:
        `createValue` in class `TypeDefinitionImpl`
      Parameters:
        `javaValue` - Java object to use to create a property value of this type.
      Returns:
        Property value representing the given value.
      Throws:
        `ClassCastException` - The given object cannot be cast to a property value with this type definition.

    - #### getTypeCategory

          public TypeCategory getTypeCategory()

      Description copied from interface: `TypeDefinition`

      Returns the type category to which this type definition belongs, which corresponds to its sub interface. For example, TypeCategory.Int is returned for a `TypeDefinitionInteger`.

      Specified by:
        `getTypeCategory` in interface `TypeDefinition`
      Specified by:
        `getTypeCategory` in class `TypeDefinitionImpl`
      Returns:
        Type category to which the type definition belongs.
      See Also:
        `TypeCategory`

    - #### setPropertyValue

          public void setPropertyValue(MetadataObject metadataObject,
                                       PropertyDefinition property,
                                       PropertyValue value)
                                throws IllegalArgumentException,
                                       IllegalAccessException,
                                       InvocationTargetException

      Description copied from interface: `TypeDefinition`

      On the given metadata object, set the specified property to the given value. The property must be of this type.

      Specified by:
        `setPropertyValue` in interface `TypeDefinition`
      Specified by:
        `setPropertyValue` in class `TypeDefinitionImpl`
      Parameters:
        `metadataObject` - Object to set the value on.
        `property` - Property of the object to set.
        `value` - Value of this type to set the property value to.
      Throws:
        `IllegalArgumentException` - The given property value is not of this type.
        `IllegalAccessException` - Insufficient privileges to set properties on the given metadata object.
        `InvocationTargetException` - Problem encountered while calling the set method associated with the property for the given object.
      See Also:
        `TypeDefinition.getPropertyValue(MetadataObject, PropertyDefinition)`

    - #### createFromBytes

          public PropertyValue createFromBytes(ByteBuffer buffer)
                                        throws EndOfDataException

      Description copied from interface: `TypeDefinition`

      Create a value of this type by reading the bytes in the given byte buffer. The buffer is assumed to have exactly the number of bytes that represent the value. For example, the length of a string value will be determined by the length (remaining bytes) in the buffer and not by reading a length value from the buffer.

      This method is able to read values written by the `TypeDefinition.writeAsBytes(PropertyValue, ByteBuffer)` method.

      Specified by:
        `createFromBytes` in interface `TypeDefinition`
      Overrides:
        `createFromBytes` in class `TypeDefinitionImpl`
      Parameters:
        `buffer` - Buffer to create a value from.
      Returns:
        Value of this type created from the given byte array.
      Throws:
        `EndOfDataException` - Insufficient bytes remaining in the given buffer to create a value of this type.
      See Also:
        `TypeDefinition.writeAsBytes(PropertyValue, ByteBuffer)`, `TypeDefinition.lengthAsBytes(PropertyValue)`

    - #### lengthAsBytes

          public long lengthAsBytes(PropertyValue value)
                             throws NullPointerException,
                                    IllegalPropertyValueException

      Description copied from interface: `TypeDefinition`

      Returns the number of bytes that the given value of this type is serialized as a sequence of bytes.

      The number returned by this method is the same as the number of bytes written to a byte buffer by the `TypeDefinition.writeAsBytes(PropertyValue, ByteBuffer)` method.

      Specified by:
        `lengthAsBytes` in interface `TypeDefinition`
      Overrides:
        `lengthAsBytes` in class `TypeDefinitionImpl`
      Parameters:
        `value` - Value to find the length of when serialized to bytes.
      Returns:
        Number of bytes used to represent the given value when serialized.
      Throws:
        `NullPointerException` - Cannot compute the serialized length of a `null` value.
        `IllegalPropertyValueException` - The given property value is not of this type.
      See Also:
        `TypeDefinition.writeAsBytes(PropertyValue, ByteBuffer)`, `TypeDefinition.createFromBytes(ByteBuffer)`

    - #### writeAsBytes

          public List<PropertyValue> writeAsBytes(PropertyValue value,
                                                  ByteBuffer buffer)
                                           throws NullPointerException,
                                                  IllegalPropertyValueException,
                                                  InsufficientSpaceException

      Description copied from interface: `TypeDefinition`

      Write the given property value of this type to the given byte stream. This version is most appropriate for writing KLV streams (MXF files).

      The format used to serialize the value with be compatible with the `TypeDefinition.createFromBytes(ByteBuffer)` method. The number of bytes written to the byte buffer will be the same as returned by `TypeDefinition.lengthAsBytes(PropertyValue)`.

      Specified by:
        `writeAsBytes` in interface `TypeDefinition`
      Overrides:
        `writeAsBytes` in class `TypeDefinitionImpl`
      Parameters:
        `value` - Value to write to the given buffer.
        `buffer` - Buffer to write the value to.
      Returns:
        List of any strongly referenced property values referenced from the new structure of bytes. Elements of this list will require separate serialization to the stream if the reference if to be resolved.
      Throws:
        `NullPointerException` - Cannot write from a `null` property value and/or to a `null` value.
        `IllegalPropertyValueException` - The given property value is not of this type.
        `InsufficientSpaceException` - Insufficient space to write the given value into the given buffer.
      See Also:
        `TypeDefinition.writeAsStructuredStorageBytes(PropertyValue, ByteBuffer)`, `TypeDefinition.createFromBytes(ByteBuffer)`, `TypeDefinition.lengthAsBytes(PropertyValue)`

    - #### resolveReferences

          public boolean resolveReferences(PropertyValue value,
                                           Map<AUID,MetadataObject> referenceMap)
                                    throws NullPointerException,
                                           IllegalPropertyValueException

      Description copied from interface: `TypeDefinition`

      Resolve any unresolved object references using the given reference map. Unresolved object references occur when a value has been read from a file but not linked to its strong or weak values. This method only effects types that are references or contain references in collections, which are:

      - `TypeDefinitionWeakObjectReference`;
      - `TypeDefinitionStrongObjectReference`;
      - `TypeDefinitionVariableArray` with elements of one of the object reference types;
      - `TypeDefinitionSet` with elements of one of the object reference types.
      Specified by:
        `resolveReferences` in interface `TypeDefinition`
      Overrides:
        `resolveReferences` in class `TypeDefinitionImpl`
      Parameters:
        `value` - Value to resolve references for.
        `referenceMap` - Map of local identifications to values to be used for resolution.
      Returns:
        Have all references been resolved?
      Throws:
        `NullPointerException` - The value or reference map is/are `null`.
        `IllegalPropertyValueException` - The given property value is not of this type.

    - #### nameToAAFName

          public String nameToAAFName(String name)

      Overrides:
        `nameToAAFName` in class `TypeDefinitionImpl`

    - #### appendMetadictXML

          public void appendMetadictXML(Node metadict,
                                        String namespace,
                                        String prefix)

      Description copied from interface: `MetaDefinition`

      Append an XML representation of this meta definition to the given XML node.

      Specified by:
        `appendMetadictXML` in interface `MetaDefinition`
      Overrides:
        `appendMetadictXML` in class `MetaDefinitionImpl`
      Parameters:
        `metadict` - Meta dictionary node to append a description of this node to.
      See Also:
        `CommonConstants.AAF_METADICT_NAMESPACE`

    - #### clone

          public TypeDefinitionSet clone()

      Description copied from interface: `MetaDefinition`

      Create a cloned copy of this meta definition.

      Specified by:
        `clone` in interface `MetaDefinition`
      Specified by:
        `clone` in interface `TypeDefinition`
      Specified by:
        `clone` in interface `TypeDefinitionSet`
      Overrides:
        `clone` in class `TypeDefinitionImpl`
      Returns:
        Cloned copy of this meta definition.

(c)2007-2016 Richard Cartwright, all rights reserved. Licensed under Apache 2 license and subject to the AMWA IPR policy.