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

tv.amwa.maj.meta

## Interface TypeDefinition

- All Superinterfaces:
    MetadataObject, MetaDefinition, WeakReferenceTarget
  All Known Subinterfaces:
    TypeDefinitionCharacter, TypeDefinitionEnumeration, TypeDefinitionExtendibleEnumeration, TypeDefinitionFixedArray, TypeDefinitionIndirect, TypeDefinitionInteger, TypeDefinitionObjectReference, TypeDefinitionOpaque, TypeDefinitionRecord, TypeDefinitionRename, TypeDefinitionSet, TypeDefinitionStream, TypeDefinitionString, TypeDefinitionStrongObjectReference, TypeDefinitionVariableArray, TypeDefinitionWeakObjectReference
  All Known Implementing Classes:
    SingletonTypeDefinitionImpl, TypeDefinitionCharacterImpl, TypeDefinitionEnumerationImpl, TypeDefinitionExtendibleEnumerationImpl, TypeDefinitionFixedArrayImpl, TypeDefinitionImpl, TypeDefinitionIndirectImpl, TypeDefinitionIntegerImpl, TypeDefinitionObjectReferenceImpl, TypeDefinitionOpaqueImpl, TypeDefinitionRecordImpl, TypeDefinitionRenameImpl, TypeDefinitionSetImpl, TypeDefinitionStreamImpl, TypeDefinitionStringImpl, TypeDefinitionStrongObjectReferenceImpl, TypeDefinitionVariableArrayImpl, TypeDefinitionWeakObjectReferenceImpl

      public interface TypeDefinition
      extends MetaDefinition

  Specifies the definition of a property type.

  The methods of type definitions allow property values of the given type to be manipulated. The interfaces provided in the MAJ API allow property values to be converted to and from equivalent Java types. Taking the character type definition as an example:

  - The `createValueFromChar(char)` converts a value of the Java `char` primitive type into a new AAF property value with type definition `TypeDefinitionCharacter`. The `createValue(Object)` method will do the same for a `Character` value.
  - The `char getCharacter(PropertyValue)` method retrieves a value of Java `char` primitive type from an AAF property value of the correct type.
  - The `setCharacter(PropertyValue, char)` method sets an existing character type AAF property value to the given value of the Java `char` primitive type.

  All other data types have similar methods.

  See Also:
    `PropertyDefinition.getTypeDefinition()`, `PropertyValue.getType()`, `Parameter.getTypeDefinition()`, `Warehouse.lookForType(String)`, `Warehouse.lookForType(AUID)`, `TypeDefinitions.TypeDefinitionWeakReference`, `TypeDefinitions.TypeDefinitionWeakReferenceVector`, `TypeDefinitions.TypeDefinitionStrongReference`, `TypeDefinitions.TypeDefinitionStrongReferenceSet`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `TypeDefinition` | `clone()` Create a cloned copy of this 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 of this type from the given Java value.
    `PropertyValue` | `getPropertyValue(MetadataObject metadataObject, PropertyDefinition property)` Get the specified property's value from the given object.
    `TypeCategory` | `getTypeCategory()` Returns the type category to which this type definition belongs, which corresponds to its sub interface.
    `long` | `lengthAsBytes(PropertyValue value)` Returns the number of bytes that the given value of this type is serialized as a sequence of bytes.
    `boolean` | `resolveReferences(PropertyValue value, Map<AUID,MetadataObject> referenceMap)` Resolve any unresolved object references using the given reference map.
    `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.
    `List<PropertyValue>` | `writeAsStructuredStorageBytes(PropertyValue value, ByteBuffer buffer)` Write the given property value of this type to the given byte stream that is to be written to a structured storage format file.

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

      `appendMetadictXML, 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`

- - ### Method Detail

    - #### getTypeCategory

          TypeCategory getTypeCategory()

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

      Returns:
        Type category to which the type definition belongs.
      See Also:
        `TypeCategory`

    - #### createValue

          PropertyValue createValue(Object javaValue)
                             throws ClassCastException

      Create a property value of this type from the given Java value. Each kind of type definition will do its best to convert the given value to a property value of its type.

      Parameters:
        `javaValue` - Java value to use to create a new property value from.
      Returns:
        New property value of this type with a value corresponding to the given Java value.
      Throws:
        `ClassCastException` - The given java value could not be cast to a property value of this type.

    - #### createFromBytes

          PropertyValue createFromBytes(ByteBuffer buffer)
                                 throws NullPointerException,
                                        EndOfDataException

      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 `writeAsBytes(PropertyValue, ByteBuffer)` method.

      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:
        `writeAsBytes(PropertyValue, ByteBuffer)`, `lengthAsBytes(PropertyValue)`

    - #### writeAsBytes

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

      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 `createFromBytes(ByteBuffer)` method. The number of bytes written to the byte buffer will be the same as returned by `lengthAsBytes(PropertyValue)`.

      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:
        `writeAsStructuredStorageBytes(PropertyValue, ByteBuffer)`, `createFromBytes(ByteBuffer)`, `lengthAsBytes(PropertyValue)`

    - #### writeAsStructuredStorageBytes

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

      Write the given property value of this type to the given byte stream that is to be written to a structured storage format file.

      The number of bytes written to the byte buffer will be the same as returned by `lengthAsBytes(PropertyValue)`.

      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:
        `writeAsBytes(PropertyValue, ByteBuffer)`, `lengthAsBytes(PropertyValue)`

    - #### lengthAsBytes

          long lengthAsBytes(PropertyValue value)
                      throws NullPointerException,
                             IllegalPropertyValueException

      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 `writeAsBytes(PropertyValue, ByteBuffer)` method.

      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:
        `writeAsBytes(PropertyValue, ByteBuffer)`, `createFromBytes(ByteBuffer)`

    - #### resolveReferences

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

      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.
      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.

    - #### setPropertyValue

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

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

      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:
        `getPropertyValue(MetadataObject, PropertyDefinition)`

    - #### getPropertyValue

          PropertyValue getPropertyValue(MetadataObject metadataObject,
                                         PropertyDefinition property)
                                  throws IllegalArgumentException,
                                         IllegalAccessException,
                                         InvocationTargetException

      Get the specified property's value from the given object. The property must be of this type.

      Parameters:
        `metadataObject` - Object to retrieve the property value from.
        `property` - Property of this type to extract the value for.
      Returns:
        Current value of the given property for the object.
      Throws:
        `IllegalArgumentException` - The given property value is not of this type.
        `IllegalAccessException` - Insufficient privileges to get properties on the given metadata object.
        `InvocationTargetException` - Problem encountered while calling the get method associated with the property for the given object.
      See Also:
        `setPropertyValue(MetadataObject, PropertyDefinition, PropertyValue)`

    - #### clone

          TypeDefinition clone()

      Create a cloned copy of this type definition.

      Specified by:
        `clone` in interface `MetaDefinition`
      Returns:
        Cloned copy of this type definition.

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