Media Authoring
with Java API

tv.amwa.maj.embeddable
Class MobID

java.lang.Object
  extended by tv.amwa.maj.embeddable.MobID
All Implemented Interfaces:
Serializable, Cloneable, MAJCommon, XMLSerializable, MobID

public final class MobID
extends Object
implements MobID, Serializable, XMLSerializable, Cloneable, MAJCommon

Implementation of a 32 byte mob id unique identifier that can hold a SMPTE UMID, as specified in SMPTE 330M. Material object identifiers represented by this class are 32-byte - yes, byte - numbers that can be generated at source with a high degree of likelihood that two independently generated identifiers will not clash. For most systems, mob ids are and should be treated as dumb numbers whose bit pattern structure is of no significance. However, for the purposes of id generation and consistent representation between systems, a mob id can be viewed as consisting of:

One common form of mob id is the SMPTE Unique Material Identifier (UMID), as defined in SMPTE S330M-2004. A number of helper methods are provided that allow the mob id to be created and managed as a UMID, including a factory method (umidFactory()) and the ability to generate the next UMID instance number for an existing piece of material (nextInstance()). To decrease the likelihood of two UMIDs being the same within a network of systems, the adoption of the same material number generation and instance number generation schemes is advisable.

A mob id can be represented as a string in four sections, consisting of the universal label, followed by the length, then instance number and finally the material number. It is an informal convention that the string representation of a UMID, which is generated by a call to toString(), starts with "urn:x-umid:". For example:

urn:x-umid:060a2b340101010101010f13-13-0098ef-4dfc94b90124509571af322ec0a801ba

The value above is structured according to the SMPTE UMID specification as follows:

urn:x-umid:<label>-<length>-<instance number>-<material number>

This class does not represent SMPTE extended UMIDs, which are 64 bytes in length.

Mob ids can be used as embeddable identifiers for entities that represent material. The internal representation of a mob id is a 32 byte array, which can be accessed with the getMobIDValue() method and set using the setMobIDValue(byte[]) method. A database column defined to hold a mob id may be defined as follows:

     `MobID` binary(32) NOT NULL
 

All methods assume network byte order.

Author:
Richard Cartwright
See Also:
AUID, TypeDefinitionRecord.MobIDType, MobIDType, Serialized Form

Constructor Summary
MobID()
          Generate a new mob id using a secure random number generator.
MobID(byte[] mobID)
          Creates a new mob id from an array of bytes.
MobID(byte[] label, byte length, byte instanceHigh, byte instanceMid, byte instanceLow, AUID material)
          Create a new mob id from the specified parameters.
 
Method Summary
 void appendXMLChildren(Node parent)
          Append child elements to the given parent node to serialize the value of an object to an XML fragment.
static MobID castFromInterface(MobID alien)
          Cast a tv.amwa.maj.record.MobID value from the generic interface one of this implementation.
 MobID clone()
          Creates a cloned deep copy of this embeddable value.
 boolean equals(Object o)
          Tests to see if the given object is equal to this embeddable value.
static byte[] getBaseUniversalLabel()
          Returns a base universal label that identifies a mob id as compatible with the SMPTE Unique Material Identifier (UMID) specification, as documented in SMPTE 330M.
 InstanceNumberGeneration getInstanceGenerator()
          Returns the instance number generation method for this mob id.
 byte getInstanceHigh()
          Returns the most significant bit of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id.
 byte getInstanceLow()
          Returns the least significant byte of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id.
 byte getInstanceMid()
          Returns the middle byte of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id.
 int getInstanceNumber()
          Returns the instance number as an unsigned integer made up from its constituent high, middle and low parts.
 byte getLength()
          Returns the length of the mob id in terms of the number of bytes following this byte, as stored at byte 13 of the mob id.
 AUID getMaterial()
          Returns the material number of the mob id, represented as an AUID, which is taken from bytes 17 to 32 of the mob id.
 MaterialNumberGeneration getMaterialNumberGenerator()
          Returns the material number generation method for this mob id.
 MaterialType getMaterialType()
          Returns the material type for this mob id.
 byte[] getMobIDValue()
          Returns a copy of all 32 bytes representing the value of this mob id as a byte array.
 byte[] getUniversalLabel()
          Returns the universal label that makes up bytes 1 to 12 of a mob id.
static MobID getZeroMobID()
          Returns a copy of the zero mob id, for which every component byte of the mob id is set to 0.
 int hashCode()
          Returns a hash code value for this embeddable object.
 boolean isZero()
          Returns true if this mob identifier the special zero mob identifier, where all 32-bytes of the identifier are zero; otherwise false.
 MobID nextInstance()
          Returns a new mob id with the same material number as this one and a newly created instance number.
static MobID parseMobID(String mobIdURN)
          Parse a mob id formatted as a URN-style UMID string and convert it into a newly instantiated mob id with an equivalent value.
 void setInstanceHigh(byte instanceHigh)
          Sets the most significant bit of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id.
 void setInstanceLow(byte instanceLow)
          Sets the least significant byte of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id.
 void setInstanceMid(byte instanceMid)
          Sets the middle byte of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id.
 void setLength(byte length)
          Returns the length of the mob id in terms of the number of bytes following this byte, as stored at byte 13 of the mob id.
 void setMaterial(AUID material)
          Sets the material number of the mob id, represented as an AUID, which is taken from bytes 17 to 32 of the mob id.
 void setMobIDValue(byte[] mobID)
          Sets the value of this mob id using the given byte array, which should contain 32 bytes of data.
 void setPropertiesFromInterface(MobID castFrom)
          Set the properties of this instance value from those available in the given value, which is specified by the MobID interface.
 void setUniversalLabel(byte[] label)
          Sets the universal label that makes up bytes 1 to 12 of a mob id.
 String toString()
          Formats the value of this mob id as a URN-style UMID string, starting with "urn:x-umid:".
static MobID umidFactory(MaterialType materialType, MaterialNumberGeneration materialNumberGeneration, InstanceNumberGeneration instanceNumberGeneration, byte[] extraData)
          Factory that manufactures new mob ids according to the given SMPTE UMID generation specification.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MobID

public MobID(byte[] label,
             @UInt8
             byte length,
             @UInt8
             byte instanceHigh,
             @UInt8
             byte instanceMid,
             @UInt8
             byte instanceLow,
             AUID material)
      throws NullPointerException

Create a new mob id from the specified parameters. The label and material values are copied to ensure that subsequent external changes do not effect the newly created mob id.

A default universal label to set the mob id to be a SMPTE UMID is available by calling getBaseUniversalLabel().

Note that this method does not generate a new mob id, it creates one using the given parameters. To generate values, use MobID() or the UMID factory method.

Parameters:
label - Universal label component of the mob id.
length - Length of the following data.
instanceHigh - Most significant part of the instance number component of the mob id.
instanceMid - Second most significant part the instance number component of the mob id.
instanceLow - Least significant part of the instance number component of the mob id.
material - Unique identifier for the identified material, the material number component of the mob id.
Throws:
NullPointerException

MobID

public MobID(byte[] mobID)
      throws NullPointerException

Creates a new mob id from an array of bytes. The array should be 32 bytes in length and prepared to be considered as a mob id. If the array is too short or too long, it will be padded with 0s or truncated to make it 32 bytes. The passed array value is cloned to avoid external changes to the array affecting this value.

Parameters:
mobID - Byte array to use to create a new mob id value.
Throws:
NullPointerException - The given byte array is null.
See Also:
setMobIDValue(byte[]), getMobIDValue()

MobID

public MobID()

Generate a new mob id using a secure random number generator. The value created is a SMPTE UMID with the following properties:

This method is provided as a quick way to generate a mob id. Statistically, it is highly unlikely that mob ids generated this way will clash with one another . For more control over generating globally unique mob ids, use the UMID factory method.

Method Detail

getBaseUniversalLabel

public static final byte[] getBaseUniversalLabel()

Returns a base universal label that identifies a mob id as compatible with the SMPTE Unique Material Identifier (UMID) specification, as documented in SMPTE 330M. This default label has:

Returns:
A universal label that identifies a mob id as a SMPTE UMID.
See Also:
getUniversalLabel(), setUniversalLabel(byte[])

getZeroMobID

public static final MobID getZeroMobID()

Returns a copy of the zero mob id, for which every component byte of the mob id is set to 0. The zero mob id is used as a flag in certain properties, such as to indicate that a source clip is the original source.

Returns:
Copy of the zero mob id.
See Also:
isZero(), AUID.isNil(), SourceReferenceValue.isOriginalSource()

umidFactory

public static final MobID umidFactory(MaterialType materialType,
                                      MaterialNumberGeneration materialNumberGeneration,
                                      InstanceNumberGeneration instanceNumberGeneration,
                                      byte[] extraData)
                               throws GenerationMethodNotSupportedException,
                                      NullPointerException

Factory that manufactures new mob ids according to the given SMPTE UMID generation specification.

Some of the generation methods documented in appendix A of SMPTE 330M are difficult to support in Java as the core API does not support all the required features, such as access to the ethernet address of a system. This additional data can be provided using the parameter, as described below. Results produced by this factory are only as good as the extra data provided and so this factory method should be considered as not fully compliant with SMPTE 330M.

The supported material number generation methods are as follows:

The supported instance generation methods are documented in more detail in nextInstance(), with the instance number initialized as follows:

The chosen type of instance number generated will define the behaviour of subsequent calls to nextInstance() for the new mob id.

Parameters:
materialType - Type of material represented by the new mob id.
materialNumberGeneration - Method to use to generate the material number of the mob id.
instanceNumberGeneration - Method to use to generate the first and next instance numbers for the mob id.
extraData - Additional data required by the material number generation method.
Returns:
Newly manufactured mob id, which is a SMPTE UMID according to the given specification.
Throws:
GenerationMethodNotSupportedException - The given material or instance number generation method is not supported.
NullPointerException - One or more of the arguments is null and all are required.
See Also:
auidFactory()

castFromInterface

public static final MobID castFromInterface(MobID alien)
                                     throws NullPointerException

Cast a tv.amwa.maj.record.MobID value from the generic interface one of this implementation. If the given value is not an instance of this MAJ API implementation, a copy of the given value of this type will be created.

Parameters:
alien - A potentially alien implementation of an interface-compatible mob id value.
Returns:
Instance of this class that is equal to the given value.
Throws:
NullPointerException - The given mob id value is null.
See Also:
setPropertiesFromInterface(tv.amwa.maj.record.MobID)

setPropertiesFromInterface

public final void setPropertiesFromInterface(MobID castFrom)
                                      throws NullPointerException

Set the properties of this instance value from those available in the given value, which is specified by the MobID interface.

Parameters:
castFrom - Value to extract properties from.
Throws:
NullPointerException - The given value to use to set this value is null.
See Also:
castFromInterface(tv.amwa.maj.record.MobID)

getMobIDValue

public final byte[] getMobIDValue()

Returns a copy of all 32 bytes representing the value of this mob id as a byte array. The internal representation of a mob id in the MAJ API is as a 32-byte array.

Returns:
Copy of the 32-byte value of this mob id.

setMobIDValue

public final void setMobIDValue(byte[] mobID)
                         throws NullPointerException

Sets the value of this mob id using the given byte array, which should contain 32 bytes of data. If the array is smaller than required, it will be padded with zeros. If the array is larger than required, it will be truncated. The given array is cloned so that subsequent changes do not affect the internal representation within this mob id.

Parameters:
mobID - Data to use to set the value of this mob id.
Throws:
NullPointerException - The given mob id data is null.
See Also:
MobID(byte[])

getUniversalLabel

public final byte[] getUniversalLabel()
Description copied from interface: MobID

Returns the universal label that makes up bytes 1 to 12 of a mob id.

Specified by:
getUniversalLabel in interface MobID
Returns:
Universal label component of the mob id.
See Also:
getBaseUniversalLabel()

setUniversalLabel

public final void setUniversalLabel(byte[] label)
                             throws NullPointerException
Description copied from interface: MobID

Sets the universal label that makes up bytes 1 to 12 of a mob id.

Specified by:
setUniversalLabel in interface MobID
Parameters:
label - Universal label component of the mob id.
Throws:
NullPointerException - The given universal label for this mob id is null.
See Also:
getBaseUniversalLabel()

getLength

@UInt8
public final byte getLength()
Description copied from interface: MobID

Returns the length of the mob id in terms of the number of bytes following this byte, as stored at byte 13 of the mob id. This value is normally 19 (0x13) for a 32 byte mob id.

Specified by:
getLength in interface MobID
Returns:
Length component of the mob id.

setLength

public final void setLength(@UInt8
                            byte length)
Description copied from interface: MobID

Returns the length of the mob id in terms of the number of bytes following this byte, as stored at byte 13 of the mob id. This value is normally 19 (0x13) for a 32 byte mob id.

Specified by:
setLength in interface MobID
Parameters:
length - Length component of the mob id.

getInstanceNumber

@UInt32
public final int getInstanceNumber()

Returns the instance number as an unsigned integer made up from its constituent high, middle and low parts. This method is intended for use with the local registration instance number generation strategy.

Returns:
Instance number of this mob id represented as an unsigned integer.
See Also:
getInstanceGenerator()

getInstanceHigh

@UInt8
public final byte getInstanceHigh()
Description copied from interface: MobID

Returns the most significant bit of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id. This value is the 14th byte of the mob id.

Specified by:
getInstanceHigh in interface MobID
Returns:
Most significant byte of the instance number component of the mob id.

setInstanceHigh

public final void setInstanceHigh(@UInt8
                                  byte instanceHigh)
Description copied from interface: MobID

Sets the most significant bit of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id. This value is the 14th byte of the mob id.

Specified by:
setInstanceHigh in interface MobID
Parameters:
instanceHigh - Most significant byte of the instance number component of the mob id.

getInstanceMid

@UInt8
public final byte getInstanceMid()
Description copied from interface: MobID

Returns the middle byte of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id. This value is the 15th byte of the mob id.

Specified by:
getInstanceMid in interface MobID
Returns:
Middle byte of the instance number component of the mob id.

setInstanceMid

public final void setInstanceMid(@UInt8
                                 byte instanceMid)
Description copied from interface: MobID

Sets the middle byte of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id. This value is the 15th byte of the mob id.

Specified by:
setInstanceMid in interface MobID
Parameters:
instanceMid - Middle byte of the instance number component of the mob id.

getInstanceLow

@UInt8
public final byte getInstanceLow()
Description copied from interface: MobID

Returns the least significant byte of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id. This value is the 16th byte of the mob id.

Specified by:
getInstanceLow in interface MobID
Returns:
Least significant byte of the instance number component of the mob id.

setInstanceLow

public final void setInstanceLow(@UInt8
                                 byte instanceLow)
Description copied from interface: MobID

Sets the least significant byte of the 3 byte instance number, which is stored as bytes 14 to 16 of the mob id. This value is the 16th byte of the mob id.

Specified by:
setInstanceLow in interface MobID
Parameters:
instanceLow - Least significant byte of the instance number component of the mob id.

getMaterial

public final AUID getMaterial()
Description copied from interface: MobID

Returns the material number of the mob id, represented as an AUID, which is taken from bytes 17 to 32 of the mob id.

Specified by:
getMaterial in interface MobID
Returns:
Material number component of the mob id.

setMaterial

public final void setMaterial(AUID material)
                       throws NullPointerException
Description copied from interface: MobID

Sets the material number of the mob id, represented as an AUID, which is taken from bytes 17 to 32 of the mob id.

Specified by:
setMaterial in interface MobID
Parameters:
material - Material number component of the mob id
Throws:
NullPointerException - The given material number is null.

isZero

public final boolean isZero()
Description copied from interface: MobID

Returns true if this mob identifier the special zero mob identifier, where all 32-bytes of the identifier are zero; otherwise false. The zero mob identifier is represented as a URN as follows:

urn:x-umid:000000000000000000000000-00-000000-00000000000000000000000000000000

Zero mob ids are used to specify original source references for source clips, indicating that a mob represents the original source of essence or data.

Specified by:
isZero in interface MobID
Returns:
Is the mob identifier the special zero mob identifier?
See Also:
getZeroMobID(), SourceReferenceValue.isOriginalSource(), SourceReferenceSegment.getSourceID(), AUID.isNil()

hashCode

public final int hashCode()
Description copied from interface: MAJCommon

Returns a hash code value for this embeddable object.

Specified by:
hashCode in interface MAJCommon
Overrides:
hashCode in class Object
Returns:
Hash code value for this embeddable object.
See Also:
Object.hashCode()

toString

public final String toString()

Formats the value of this mob id as a URN-style UMID string, starting with "urn:x-umid:". For example:

urn:x-umid:060a2b340101010101010f13-13-00b347-53b933d918245095ca82322ec0a801ba

Values from this method can be turned back into mob ids using the parseMobID(String) static method. The canonical form of formatted values created by this implementation uses lower case letters for hexadecimal digits.

Specified by:
toString in interface MAJCommon
Overrides:
toString in class Object
Returns:
The value of this MobID formatted as a URN-style UMID string.
See Also:
Object.toString(), parseMobID(String)

parseMobID

public static final MobID parseMobID(String mobIdURN)
                              throws NullPointerException,
                                     NumberFormatException

Parse a mob id formatted as a URN-style UMID string and convert it into a newly instantiated mob id with an equivalent value. The format of the expected value is the same as that generated by the toString() method, for example:

urn:x-umid:060a2b340101010101010f13-13-00b347-53b933d918245095ca82322ec0a801ba

Hexadecimal digits used to express the UMID value may used upper or lower case values.

Parameters:
mobIdURN - Mob id value formatted as a URN-style UMID string.
Returns:
MobID created from the given URN-style UMID value.
Throws:
NullPointerException - The mob id urn argument is null.
NumberFormatException - The given URN value is the wrong length, a different kind or URN, has path separators in the wrong place or contains digits other than hexadecimal digits where hexadecimal digits are expected.
See Also:
toString()

clone

public final MobID clone()
Description copied from interface: MAJCommon

Creates a cloned deep copy of this embeddable value. The clone will be initialized to have the same value as this value but exists independently from then on. Changes to this value will not effect the clone and changes to the clone will not effect this. MAJ API clones are true deep clones with no shared references to areas of memory within the original.

This method does not throw a CloneNotSupportedException as all embeddable values must implement the Cloneable interface.

Specified by:
clone in interface MAJCommon
Overrides:
clone in class Object
Returns:
Independent clone of this value, which is a deep copy.
See Also:
Object.clone()

equals

public final boolean equals(Object o)
Description copied from interface: MAJCommon

Tests to see if the given object is equal to this embeddable value. To be equal, the given value must be not null, share the same interface to its value and each of the properties of the value must each be equal.

Specified by:
equals in interface MAJCommon
Overrides:
equals in class Object
Parameters:
o - Object to test for equality with.
Returns:
Is the given object equals to this value?
See Also:
Object.equals(Object)

getMaterialNumberGenerator

public final MaterialNumberGeneration getMaterialNumberGenerator()

Returns the material number generation method for this mob id. This value only makes sense if this mob id is a SMPTE UMID.

Returns:
Material number generation method for this mob id.
See Also:
umidFactory(MaterialType, MaterialNumberGeneration, InstanceNumberGeneration, byte[])

getInstanceGenerator

public final InstanceNumberGeneration getInstanceGenerator()

Returns the instance number generation method for this mob id. This value only makes sense if the mob id is a SMPTE UMID.

Returns:
Instance number generation method for this mob id.
See Also:
umidFactory(MaterialType, MaterialNumberGeneration, InstanceNumberGeneration, byte[]), nextInstance()

getMaterialType

public final MaterialType getMaterialType()

Returns the material type for this mob id. This value only makes sense if the mob id is a SMPTE UMID.

Returns:
Material type for this mob id.
See Also:
umidFactory(MaterialType, MaterialNumberGeneration, InstanceNumberGeneration, byte[])

nextInstance

public final MobID nextInstance()
                         throws InstanceOverflowException,
                                GenerationMethodNotSupportedException

Returns a new mob id with the same material number as this one and a newly created instance number. The method of generation of the instance number is set as part of the mob id's universal label and can be found by calling getInstanceGenerator().

The mob ids generated by this method are only unique within the local context and are not thread safe where clones exist or safe for use across more than one virtual machine. It is up to a user of this method to ensure instance uniqueness in their own local context, using techniques such as transaction management and persistence mapping to a central store.

The relationship between the current and new instance number for each type of generator is:

Returns:
The next mob id instance as defined by the instance generation method for this mob id.
Throws:
InstanceOverflowException - For methods that increment counters to define the next instance mob id, the counter has overflowed.
GenerationMethodNotSupportedException - The instance number generation method is not supported, which is currently the case for the live stream method.
See Also:
getInstanceGenerator(), getInstanceNumber(), getInstanceHigh(), getInstanceMid(), getInstanceLow()

appendXMLChildren

public final void appendXMLChildren(Node parent)
Description copied from interface: XMLSerializable

Append child elements to the given parent node to serialize the value of an object to an XML fragment. Methods of the XMLBuilder class are provided to help with this process.

Specified by:
appendXMLChildren in interface XMLSerializable
Parameters:
parent - XML parent element to append child nodes to.

Media Authoring
with Java API

(c) 2007-2008 Richard Cartwright, all rights reserved. Subject to the terms of the AAF SDK Public Source License.