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

tv.amwa.maj.meta.impl

## Class TypeDefinitionEnumerationImpl

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

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

      @MediaClass(uuid1=218169601,
                  uuid2=519,
                  uuid3=0,
                  uuid4={6,14,43,52,2,6,1,1},
                  definedName="TypeDefinitionEnumeration",
                  description="The TypeDefinitionEnumeration class defines a property type that can have one of a set of integer values.",
                  symbol="TypeDefinitionEnumeration")
      public final class TypeDefinitionEnumerationImpl
      extends SingletonTypeDefinitionImpl
      implements TypeDefinitionEnumeration, Serializable, Cloneable

  Implements the definition of a property type that can have one of a set of integer values.

  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `TypeDefinitionEnumerationImpl.EnumerationValue`

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

      `SingletonTypeDefinitionImpl.SingletonMethodBag`

    - ### 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
    `TypeDefinitionEnumerationImpl(AUID identification, String typeName, Class<?> enumeration, TypeDefinition elementType)` Creates and initializes an enumeration type definition, which defines a property type that can have one of a set of integer values.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `appendElementName(String elementName)`
    `void` | `appendElementValue(long elementValue)`
    `void` | `appendMetadictXML(Node metadict, String namespace, String prefix)` Append an XML representation of this meta definition to the given XML node.
    `void` | `clearElementNames()`
    `void` | `clearElementValues()`
    `TypeDefinitionEnumeration` | `clone()` Create a cloned copy of this meta definition.
    `int` | `countElements()` Returns the number of enumeration elements contained in the list of elements of this enumeration type definition.
    `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.
    `PropertyValue` | `createValueFromName(String name)` Creates and returns an enumeration property value of this enumeration type using the given enumeration element name.
    `PropertyValue` | `createValueFromOrdinal(Number ordinal)` Creates and returns an enumeration property value of this enumeration type using the given enumeration element value.
    `String` | `getElementName(int index)` Returns the name of the enumeration element at the given index into the list of elements of this enumeration type definition.
    `String[]` | `getElementNames()`
    `TypeDefinition` | `getElementType()` Returns the type definition of the integer values that are found in this enumeration.
    `long` | `getElementValue(int index)` Returns the integer value associated with the enumeration element at the given index in the list of elements of this enumeration type definition.
    `long[]` | `getElementValues()`
    `Class<Enum<?>>` | `getEnumeration()` Returns the `Enum` Java type associated with this enumeration type definition.
    `long` | `getIntegerValue(PropertyValue enumerationProperty)` Returns the integer value associated with the given enumeration property value as defined by this enumeration type definition.
    `String` | `getNameFromInteger(long value)` Returns the name element with the given integer in this enumeration type definition.
    `String` | `getNameFromValue(PropertyValue enumerationProperty)` Returns the name associated with the given enumeration property value as defined by this enumeration type definition.
    `String` | `getSymbolFromValue(PropertyValue enumerationProperty)`
    `TypeCategory` | `getTypeCategory()` Returns the type category to which this type definition belongs, which corresponds to its sub interface.
    `static String[]` | `initializeElementNames()`
    `static TypeDefinition` | `initializeElementType()`
    `static long[]` | `initializeElementValues()`
    `long` | `lengthAsBytes(PropertyValue value)` Returns the number of bytes that the given value of this type is serialized as a sequence of bytes.
    `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, nameToAAFName, resolveReferences, 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, resolveReferences, 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

    - #### TypeDefinitionEnumerationImpl

          public TypeDefinitionEnumerationImpl(AUID identification,
                                               @AAFString
                                               String typeName,
                                               Class<?> enumeration,
                                               TypeDefinition elementType)
                                        throws NullPointerException,
                                               IllegalArgumentException

      Creates and initializes an enumeration type definition, which defines a property type that can have one of a set of integer values. The enumeration is initialized with its identity and its enumeration elements defined by a `java.lang.Enum` class (`Class<Enum>`).

      The interface `MediaEnumerationValue` must be implemented by the Java class defining the enumeration. For any enumeration value, this interface provides a method `value()` that is used to find the `Int64` value associated with the enumeration token in the AAF object specification and associated registries. Note, however, that Java enumeration values are backed by Java `int` values that are actually `Int32` AAF values.

      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` - Unique identifier to be used to identify this type.
        `typeName` - Display name for the enumeration type definition.
        `enumeration` - Java enumeration represented by this type definition.
      Throws:
        `NullPointerException` - One or more of the arguments is null, or one or more of the elements of the names array is null.
        `IllegalArgumentException` - The class provided to describe this enumeration is not a Java enumeration or does not implement the `MediaEnumerationValue` interface.

  - ### Method Detail

    - #### countElements

          public int countElements()

      Description copied from interface: `TypeDefinitionEnumeration`

      Returns the number of enumeration elements contained in the list of elements of this enumeration type definition.

      Specified by:
        `countElements` in interface `TypeDefinitionEnumeration`
      Returns:
        Number of enumeration elements contained in this enumeration type definition.

    - #### createValueFromName

          public PropertyValue createValueFromName(String name)
                                            throws NullPointerException,
                                                   InvalidParameterException

      Description copied from interface: `TypeDefinitionEnumeration`

      Creates and returns an enumeration property value of this enumeration type using the given enumeration element name.

      Specified by:
        `createValueFromName` in interface `TypeDefinitionEnumeration`
      Parameters:
        `name` - Name of an enumeration element to create a property value for.
      Returns:
        Newly created property value element set to the given element name.
      Throws:
        `NullPointerException` - The given element name is `null`.
        `InvalidParameterException` - The given name is not in the list of element names for this enumeration type.
      See Also:
        `TypeDefinitionEnumeration.createValueFromOrdinal(Number)`

    - #### createValueFromOrdinal

          public PropertyValue createValueFromOrdinal(Number ordinal)
                                               throws NullPointerException,
                                                      InvalidParameterException

      Description copied from interface: `TypeDefinitionEnumeration`

      Creates and returns an enumeration property value of this enumeration type using the given enumeration element value.

      Specified by:
        `createValueFromOrdinal` in interface `TypeDefinitionEnumeration`
      Parameters:
        `ordinal` - Element value to create a property value for.
      Returns:
        Newly created property value element set to the given element value.
      Throws:
        `NullPointerException` - The given element value is `null`.
        `InvalidParameterException` - The given name is not in the list of element values for this enumeration type.
      See Also:
        `TypeDefinitionEnumeration.createValueFromName(String)`

    - #### getElementName

          public String getElementName(int index)
                                throws IndexOutOfBoundsException

      Description copied from interface: `TypeDefinitionEnumeration`

      Returns the name of the enumeration element at the given index into the list of elements of this enumeration type definition.

      Specified by:
        `getElementName` in interface `TypeDefinitionEnumeration`
      Parameters:
        `index` - 0-based index of the name to retrieve from the list of elements of this enumeration type definition.
      Returns:
        Name of the enumeration element at the given index in the list of elements of this enumeration type definition.
      Throws:
        `IndexOutOfBoundsException`

    - #### getElementType

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

      Description copied from interface: `TypeDefinitionEnumeration`

      Returns the type definition of the integer values that are found in this enumeration. For data types created using the MAJ API, this is always an `Int32`.

      Specified by:
        `getElementType` in interface `TypeDefinitionEnumeration`
      Returns:
        Type definition of the integer values that are found in this enumeration.
      See Also:
        `TypeDefinitionInteger`

    - #### setElementType

          @MediaPropertySetter(value="ElementType")
          public void setElementType(TypeDefinition elementType)
                                                                        throws NullPointerException,
                                                                               IllegalArgumentException

      Parameters:
        `elementType` -
      Throws:
        `NullPointerException`
        `IllegalArgumentException`

    - #### initializeElementType

          public static final TypeDefinition initializeElementType()

    - #### getElementNames

          @MediaProperty(uuid1=50397699,
                         uuid2=1024,
                         uuid3=0,
                         uuid4={6,14,43,52,1,1,1,2},
                         definedName="ElementNames",
                         aliases="EnumElementNames",
                         typeName="UTF16StringArray",
                         optional=false,
                         uniqueIdentifier=false,
                         pid=21,
                         symbol="ElementNames")
          public String[] getElementNames()

    - #### initializeElementNames

          public static final String[] initializeElementNames()

    - #### clearElementNames

          @MediaPropertyClear(value="ElementNames")
          public void clearElementNames()

    - #### appendElementName

          @MediaListAppend(value="ElementNames")
          public void appendElementName(String elementName)

    - #### getElementValues

          @MediaProperty(uuid1=50397699,
                         uuid2=1280,
                         uuid3=0,
                         uuid4={6,14,43,52,1,1,1,2},
                         definedName="ElementValues",
                         aliases="EnumElementValues",
                         typeName="Int64Array",
                         optional=false,
                         uniqueIdentifier=false,
                         pid=22,
                         symbol="ElementValues")
          public long[] getElementValues()

    - #### initializeElementValues

          public static final long[] initializeElementValues()

    - #### clearElementValues

          @MediaPropertyClear(value="ElementValues")
          public void clearElementValues()

    - #### appendElementValue

          @MediaListAppend(value="ElementValues")
          public void appendElementValue(long elementValue)

    - #### getElementValue

          public long getElementValue(int index)
                               throws IndexOutOfBoundsException

      Description copied from interface: `TypeDefinitionEnumeration`

      Returns the integer value associated with the enumeration element at the given index in the list of elements of this enumeration type definition.

      Specified by:
        `getElementValue` in interface `TypeDefinitionEnumeration`
      Parameters:
        `index` - 0-based index of the integer value to retrieve from the list of elements of this enumeration type definition.
      Returns:
        Integer value of the element at this given index into the enumeration type definition.
      Throws:
        `IndexOutOfBoundsException` - The given index is outside the acceptable range for the enumeration type definition.

    - #### getEnumeration

          public Class<Enum<?>> getEnumeration()

      Description copied from interface: `TypeDefinitionEnumeration`

      Returns the `Enum` Java type associated with this enumeration type definition.

      Specified by:
        `getEnumeration` in interface `TypeDefinitionEnumeration`
      Returns:
        Java enumeration associated with this type definition.

    - #### getIntegerValue

          public long getIntegerValue(PropertyValue enumerationProperty)
                               throws NullPointerException,
                                      IllegalPropertyValueException

      Description copied from interface: `TypeDefinitionEnumeration`

      Returns the integer value associated with the given enumeration property value as defined by this enumeration type definition.

      Specified by:
        `getIntegerValue` in interface `TypeDefinitionEnumeration`
      Parameters:
        `enumerationProperty` - Enumeration property value to find the associated integer for.
      Returns:
        Integer value associated with the given property value as defined by this enumeration type definition.
      Throws:
        `NullPointerException` - The given enumeration property is `null`.
        `IllegalPropertyValueException` - The given property value is not defined by the enumeration type definition.

    - #### getNameFromInteger

          public String getNameFromInteger(long value)
                                    throws IllegalArgumentException

      Description copied from interface: `TypeDefinitionEnumeration`

      Returns the name element with the given integer in this enumeration type definition.

      Specified by:
        `getNameFromInteger` in interface `TypeDefinitionEnumeration`
      Parameters:
        `value` - Integer value associated with an enumeration element.
      Returns:
        Name of the element with the given integer in this enumeration type definition.
      Throws:
        `IllegalArgumentException`

    - #### getNameFromValue

          public String getNameFromValue(PropertyValue enumerationProperty)
                                  throws NullPointerException,
                                         IllegalPropertyValueException

      Description copied from interface: `TypeDefinitionEnumeration`

      Returns the name associated with the given enumeration property value as defined by this enumeration type definition.

      Specified by:
        `getNameFromValue` in interface `TypeDefinitionEnumeration`
      Parameters:
        `enumerationProperty` - Enumeration property value to find the name of.
      Returns:
        Name associated with the given enumeration property definition according to this enumeration type definition.
      Throws:
        `NullPointerException` - The given property value is `null`.
        `IllegalPropertyValueException` - The given property value is not a value of this enumeration property type.

    - #### getSymbolFromValue

          public String getSymbolFromValue(PropertyValue enumerationProperty)
                                    throws NullPointerException,
                                           IllegalPropertyValueException

      Throws:
        `NullPointerException`
        `IllegalPropertyValueException`

    - #### 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`

    - #### createFromBytes

          public PropertyValue createFromBytes(ByteBuffer buffer)
                                        throws NullPointerException,
                                               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:
        `NullPointerException` - Cannot read values from a `null` buffer.
        `EndOfDataException` - Insufficient bytes remaining in the given buffer to create a value of this type.
      See Also:
        `TypeDefinition.writeAsBytes(PropertyValue, ByteBuffer)`, `TypeDefinition.lengthAsBytes(PropertyValue)`

    - #### 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)`

    - #### 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)`

    - #### 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`
      Overrides:
        `setPropertyValue` in class `SingletonTypeDefinitionImpl`
      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)`

    - #### 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 TypeDefinitionEnumeration 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 `TypeDefinitionEnumeration`
      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.