|
Media Authoring with Java API |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttv.amwa.maj.embeddable.MobID
public final class MobID
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.
AUID
,
TypeDefinitionRecord.MobIDType
,
MobIDType
,
Serialized FormConstructor 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 |
---|
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.
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.
NullPointerException
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.
mobID
- Byte array to use to create a new mob id value.
NullPointerException
- The given byte array is null
.setMobIDValue(byte[])
,
getMobIDValue()
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 |
---|
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:
getUniversalLabel()
,
setUniversalLabel(byte[])
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.
isZero()
,
AUID.isNil()
,
SourceReferenceValue.isOriginalSource()
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
The supported material number generation methods are as follows:
MaterialNumberGeneration.SMPTE
- Creates a material number from the system clock,
current date, a two byte random number and a 6 byte system identifier. This approach is documented in
section A.1 of SMPTE 330M and should ensure a high degree of identifier uniqueness. The
system identifier must be provided as the first 6 bytes of the extra data parameter. Java 1.5 does not
provide a means to extract the ethernet address of the system on which a virtual machine is running
but a locally administered value that is a combination of bytes taken from the system's IP address
and domain name should be sufficient. Just such a value is provided by calling
Utilities.createLocalHostID(6)
.MaterialNumberGeneration.UUID_UL
- Generates a material number from the UUID or universal
label provided as the 16 bytes passed as the extra data parameter. The method assumes that the byte
reordering documented in section A.2 of SMPTE 330M has already taken place. No validation
of the UUID or universal label is carried out. In fact, this method is implemented here as a
dumb pass through of the given value directly to the 16-bytes of the material number of
the new mob id.MaterialNumberGeneration.Masked
- Generates a material number according to the SMPTE
method and then uses an MD5 function on the value to mask the details, as described in section A.3
of SMPTE 330M. This masking is normally done for security reasons so as to hide details of creation times
and systems identification. Once masked, the time and host id values cannot be easily recovered and
the masking function ensures the same degree of uniqueness as the
SMPTE method.MaterialNumberGeneration.IEEE1394
- Generates a material number according to the IEEE 1394
network method, as described in section A.4 of SMPTE 330M. The first 8 bytes are generated
from the system clock, current date and a random number. The last 8 bytes are the device node identifier that
must be provided as the extra bytes parameter. The device node of the
system on which the virtual machine is running is not available in the core Java API version 1.5. A locally
derived host identifier created from the system's IP address and domain name can be generated by calling
Utilities.createLocalHostID(8)
.
MaterialNumberGeneration.NotDefined
- A pseudo random number is generated for the
128-bits of data representing the material number, using the SecureRandom
class.The supported instance generation methods are documented in more detail in nextInstance()
,
with the instance number initialized as follows:
InstanceNumberGeneration.LocalRegistration
- All three instance bytes are set to
zero.InstanceNumberGeneration.CopyAndPseudoRandom16Bit
- The instance high byte is
set to 0 and the other two bytes are set to random values.InstanceNumberGeneration.PseudoRandom24Bit
- The instance high, middle and low
values are set using 24 randomly generated bits.InstanceNumberGeneration.LiveStream
- Not supported and throws a
GenerationMethodNotSupportedException
.InstanceNumberGeneration.NotDefined
- Same as PseudoRandom24Bit.The chosen type of instance number generated will define the behaviour of subsequent
calls to nextInstance()
for the new mob id.
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.
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.auidFactory()
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.
alien
- A potentially alien implementation of an interface-compatible mob id
value.
NullPointerException
- The given mob id value is null
.setPropertiesFromInterface(tv.amwa.maj.record.MobID)
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.
castFrom
- Value to extract properties from.
NullPointerException
- The given value to use to set this value is null
.castFromInterface(tv.amwa.maj.record.MobID)
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.
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.
mobID
- Data to use to set the value of this mob id.
NullPointerException
- The given mob id data is null
.MobID(byte[])
public final byte[] getUniversalLabel()
MobID
Returns the universal label that makes up bytes 1 to 12 of a mob id.
getUniversalLabel
in interface MobID
getBaseUniversalLabel()
public final void setUniversalLabel(byte[] label) throws NullPointerException
MobID
Sets the universal label that makes up bytes 1 to 12 of a mob id.
setUniversalLabel
in interface MobID
label
- Universal label component of the mob id.
NullPointerException
- The given universal label for this mob id is null
.getBaseUniversalLabel()
@UInt8 public final byte getLength()
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.
getLength
in interface MobID
public final void setLength(@UInt8 byte length)
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.
setLength
in interface MobID
length
- Length component of the mob id.@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.
getInstanceGenerator()
@UInt8 public final byte getInstanceHigh()
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.
getInstanceHigh
in interface MobID
public final void setInstanceHigh(@UInt8 byte instanceHigh)
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.
setInstanceHigh
in interface MobID
instanceHigh
- Most significant byte of the instance number component of the mob id.@UInt8 public final byte getInstanceMid()
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.
getInstanceMid
in interface MobID
public final void setInstanceMid(@UInt8 byte instanceMid)
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.
setInstanceMid
in interface MobID
instanceMid
- Middle byte of the instance number component of the mob id.@UInt8 public final byte getInstanceLow()
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.
getInstanceLow
in interface MobID
public final void setInstanceLow(@UInt8 byte instanceLow)
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.
setInstanceLow
in interface MobID
instanceLow
- Least significant byte of the instance number component of the mob id.public final AUID getMaterial()
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.
getMaterial
in interface MobID
public final void setMaterial(AUID material) throws NullPointerException
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.
setMaterial
in interface MobID
material
- Material number component of the mob id
NullPointerException
- The given material number is null
.public final boolean isZero()
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.
isZero
in interface MobID
getZeroMobID()
,
SourceReferenceValue.isOriginalSource()
,
SourceReferenceSegment.getSourceID()
,
AUID.isNil()
public final int hashCode()
MAJCommon
Returns a hash code value for this embeddable object.
hashCode
in interface MAJCommon
hashCode
in class Object
Object.hashCode()
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.
toString
in interface MAJCommon
toString
in class Object
Object.toString()
,
parseMobID(String)
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.
mobIdURN
- Mob id value formatted as a URN-style UMID string.
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.toString()
public final MobID clone()
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.
clone
in interface MAJCommon
clone
in class Object
Object.clone()
public final boolean equals(Object o)
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.
equals
in interface MAJCommon
equals
in class Object
o
- Object to test for equality with.
Object.equals(Object)
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.
umidFactory(MaterialType, MaterialNumberGeneration, InstanceNumberGeneration, byte[])
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.
umidFactory(MaterialType, MaterialNumberGeneration, InstanceNumberGeneration, byte[])
,
nextInstance()
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.
umidFactory(MaterialType, MaterialNumberGeneration, InstanceNumberGeneration, byte[])
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:
InstanceNumberGeneration.LocalRegistration
- The instance high, mid and low bytes
are treated as the most significant, middle and least significant bytes of an unsigned 24-bit
integer value representing the local registration number of the mob id for the given material
number. The instance number of the new mob id is set to be one greater than current instance
number, as returned by getInstanceNumber()
.InstanceNumberGeneration.CopyAndPseudoRandom16Bit
- The instance high byte is
incremented by one to make the instance high byte of the new mob id. If the counter exceeds
255
, an InstanceOverflowException
is thrown, which gives the caller the
option of resetting the counter to 0
or to take their own choice of action. The
middle and low instance bytes are set using a random number generator. This implementation
ensures that any two consecutive current and new instances do not have the same middle and low
instance values.InstanceNumberGeneration.PseudoRandom24Bit
- The instance high, middle and low
values are set using 24 randomly generated bits. The method ensures that any two consecutive
current and new instance numbers do not have the same values. InstanceNumberGeneration.LiveStream
- Not supported by the MAJ API and throws a
GenerationMethodNotSupportedException
.InstanceNumberGeneration.NotDefined
- Same as InstanceNumberGeneration.PseudoRandom24Bit
.
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.getInstanceGenerator()
,
getInstanceNumber()
,
getInstanceHigh()
,
getInstanceMid()
,
getInstanceLow()
public final void appendXMLChildren(Node parent)
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.
appendXMLChildren
in interface XMLSerializable
parent
- XML parent element to append child nodes to.
|
Media Authoring with Java API |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |