Media Authoring
with Java API

tv.amwa.maj.meta
Class ClassDefinition

java.lang.Object
  extended by tv.amwa.maj.meta.MetaDefinition
      extended by tv.amwa.maj.meta.ClassDefinition
All Implemented Interfaces:
Serializable, DefinitionType, ClassDefinition, MetaDefinition, XMLSerializable, MAJCommon

@AAFClass(uuid1=218169601,
          uuid2=513,
          uuid3=0,
          uuid4={6,14,43,52,2,6,1,1},
          definedName="ClassDefinition",
          description="The ClassDefinition class is used to programatically represent the class hierarchy defined in the AAF object specification.")
public final class ClassDefinition
extends MetaDefinition
implements ClassDefinition, Serializable, XMLSerializable, MAJCommon

Implementation of the definition of an AAF class.

THE COMMENTS FOR THIS CLASS ARE INCOMPLETE.

Author:
Richard Cartwright
See Also:
Serialized Form

Nested Class Summary
static class ClassDefinition.XMLHandler
           
 
Constructor Summary
ClassDefinition(AUID identification, String className, ClassDefinition parentClass, boolean isConcrete)
          Creates and initializes a class definition object that inherits from the given parent class.
 
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.
 int countPropertyDefinitions()
          Returns number of property definitions in this class.
 Object createInstance()
          Creates an instance of this class, and returns it.
 boolean deepEquals(Object o)
          Check to see if this definition is equal to the given object by comparing each property.
static ClassDefinition forAUID(AUID identification)
           
static ClassDefinition forClass(Class<?> aafClass)
          For any given Java class, this method finds the corresponding AAF class definition or creates it if it does not yet exists within the current Java virtual machine.
 boolean getIsConcrete()
           
 String getJavaClassName()
           
 Class<?> getJavaImplementation()
          Returns the Java class implementation associated with the defined class.
 ClassDefinition getParent()
          Gets the Parent class for this class definition.
 Set<PropertyDefinition> getPropertyDefinitions()
          Returns all of the AAF property definitions attached to the current class.
 PropertyDefinition getUniqueIdentifier()
          Returns the property definition corresponding to this class' unique identifier.
static PropertyDefinition globalPropertyIDLookup(short tag)
           
 boolean isConcrete()
          Returns true if the defined class can be instantiated; returns false otherwise.
 boolean isRoot()
          Returns true if the defined class is the base of the inheritance hierarchy; returns false otherwise.
 boolean isUniquelyIdentified()
          Returns true if the defined class is uniquely identified, which means that it has a single property that is a unique identifier for any given instance.
 PropertyDefinition lookupPropertyDefinition(AUID propertyID)
          Looks up and returns the property definition corresponding to the given AUID in the set of propertise defined for this class.
 PropertyDefinition lookupPropertyDefinition(short propertyTag)
           
 PropertyDefinition lookupPropertyDefinition(String propertyName)
           
 PropertyDefinition registerNewPropertyDefinition(AUID identification, String name, TypeDefinition typeDefinition, boolean isOptional, boolean isUniqueIdentifier, Short pid)
          Creates a new property definition and registers it in this class definition.
 PropertyDefinition registerOptionalPropertyDefinition(AUID identification, String name, TypeDefinition typeDefinition)
          Creates a new property definition and registers it in this class definition.
 void setJavaImplementation(Class<?> javaImplementation)
          Sets the Java class implementation associated with the defined class.
 void setPropertiesFromInterface(ClassDefinition castFrom)
           
 
Methods inherited from class tv.amwa.maj.meta.MetaDefinition
castFromInterface, equals, getAUID, getDescription, getIdentification, getName, hashCode, setDescription, setName, setPropertiesFromInterface, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface tv.amwa.maj.iface.MetaDefinition
getAUID, getDescription, getName, setDescription, setName
 
Methods inherited from interface tv.amwa.maj.meta.MAJCommon
equals, hashCode, toString
 

Constructor Detail

ClassDefinition

public ClassDefinition(AUID identification,
                       String className,
                       ClassDefinition parentClass,
                       boolean isConcrete)
                throws NullPointerException

Creates and initializes a class definition object that inherits from the given parent class. If the is concrete property is set to true, objects of this class can be instantiated; otherwise, it will be illegal to instantiate such objects.

When creating the class implementation, it is advisable to set the Java class implementation of the given definition using setJavaImplementation(Class).

Parameters:
identification - Identification of the new class definition.
className - Friendly name of the new class definition.
parentClass - Specifies the parent of the class being defined from which this class inherits. If set to null, the new definition is assumed to be for a root class.
isConcrete - Can objects of this class be instantiated?
Throws:
NullPointerException - The identification argument is null.
Method Detail

forClass

public static final ClassDefinition forClass(Class<?> aafClass)
                                      throws NullPointerException,
                                             IllegalArgumentException

For any given Java class, this method finds the corresponding AAF class definition or creates it if it does not yet exists within the current Java virtual machine. The creation of class definitions is done by lazy evaluation as required using Java reflection and annotations. All generated values are cached in a local, static hashtable so that once generated, the work is not repeated.

The values returned by this method are only as good as the annotations provided with the sourcecode, as labelled using AAFClass and AAFProperty. If an AAFClass annotation is not present in the given class, an IllegalArgumentException is thrown. Any problems found with the AAFProperty annotations, such as two properties having the same name, will also result in an IllegalArgumentException.

Parameters:
aafClass - Java class to find the AAF class definition of.
Returns:
AAF class definition associated with the given Java class.
Throws:
NullPointerException - The given Java class is null.
IllegalArgumentException - The given Java class is not annotated with AAFClass or the AAFProperty annotations contain errors.

setPropertiesFromInterface

public final void setPropertiesFromInterface(ClassDefinition castFrom)
See Also:
MetaDefinition.setPropertiesFromInterface(tv.amwa.maj.iface.MetaDefinition)

countPropertyDefinitions

public int countPropertyDefinitions()
Description copied from interface: ClassDefinition

Returns number of property definitions in this class.

Specified by:
countPropertyDefinitions in interface ClassDefinition
Returns:
Number of properties contained in this class definition.

createInstance

public Object createInstance()
                      throws NotImplementedException
Description copied from interface: ClassDefinition

Creates an instance of this class, and returns it. This method is not supported in the MAJ API and will always throw a NotImplementedException. Use implementations of the AAF factory instead.

Specified by:
createInstance in interface ClassDefinition
Returns:
An instance object of this class definition.
Throws:
NotImplementedException

getJavaClassName

public String getJavaClassName()
                        throws PropertyNotPresentException
Throws:
PropertyNotPresentException

getJavaImplementation

public Class<?> getJavaImplementation()
                               throws PropertyNotPresentException
Description copied from interface: ClassDefinition

Returns the Java class implementation associated with the defined class.

Specified by:
getJavaImplementation in interface ClassDefinition
Returns:
Java class implementation associated with this AAF class definition.
Throws:
PropertyNotPresentException - The optional java implementation property is not present in this AAF class definition.
See Also:
AAFClass, forClass(Class)

setJavaImplementation

public void setJavaImplementation(Class<?> javaImplementation)
Description copied from interface: ClassDefinition

Sets the Java class implementation associated with the defined class.

Specified by:
setJavaImplementation in interface ClassDefinition
Parameters:
javaImplementation - Java class implementation associated with this AAF class definition.
See Also:
AAFClass, forClass(Class)

getParent

@AAFProperty(uuid1=100729095,
             uuid2=256,
             uuid3=0,
             uuid4={6,14,43,52,1,1,1,2},
             definedName="ParentClass",
             typeName="WeakReference to ClassDefinition",
             optional=false,
             uniqueIdentifier=false,
             pid=8)
public ClassDefinition getParent()
Description copied from interface: ClassDefinition

Gets the Parent class for this class definition. If there is no parent then null is returned. The only classes which have no parent will be InterchangeObject and MetaDefinition. These classes return themselves as their own parents to indicate that they are the root of the type hierarchy.

Specified by:
getParent in interface ClassDefinition
Returns:
Parent class of this class definition, this class if it is the root of the class hierarchy or null if no parent class has been defined.

getPropertyDefinitions

@AAFProperty(uuid1=100729095,
             uuid2=512,
             uuid3=0,
             uuid4={6,14,43,52,1,1,1,2},
             definedName="Properties",
             typeName="StrongReferenceSet of PropertyDefinition",
             optional=true,
             uniqueIdentifier=false,
             pid=9)
public Set<PropertyDefinition> getPropertyDefinitions()
Description copied from interface: ClassDefinition

Returns all of the AAF property definitions attached to the current class.

Specified by:
getPropertyDefinitions in interface ClassDefinition
Returns:
Shallow copy of the set of property definitions object that define the properties for this defined class.

getUniqueIdentifier

public PropertyDefinition getUniqueIdentifier()
Description copied from interface: ClassDefinition

Returns the property definition corresponding to this class' unique identifier.

Specified by:
getUniqueIdentifier in interface ClassDefinition
Returns:
The unique identifier of this class definition, or null if the class does not have a unique identifier property definition.
See Also:
ClassDefinition.isUniquelyIdentified(), PropertyDefinition.getIsUniqueIdentifier()

isConcrete

public boolean isConcrete()
Description copied from interface: ClassDefinition

Returns true if the defined class can be instantiated; returns false otherwise. If the class is not concrete, then it is abstract and implemented by an abstract Java class in the MAJ API. Any object in an AAF file that belongs to an abstract class shall also belong to a concrete subclass of the abstract class.

Specified by:
isConcrete in interface ClassDefinition
Returns:
Can the defined class be instantiated?

getIsConcrete

@AAFProperty(uuid1=100729095,
             uuid2=768,
             uuid3=0,
             uuid4={6,14,43,52,1,1,1,2},
             definedName="IsConcrete",
             typeName="Boolean",
             optional=false,
             uniqueIdentifier=false,
             pid=10)
public boolean getIsConcrete()

isRoot

public boolean isRoot()
Description copied from interface: ClassDefinition

Returns true if the defined class is the base of the inheritance hierarchy; returns false otherwise.

Specified by:
isRoot in interface ClassDefinition
Returns:
Is this a root (base) class?

isUniquelyIdentified

public boolean isUniquelyIdentified()
Description copied from interface: ClassDefinition

Returns true if the defined class is uniquely identified, which means that it has a single property that is a unique identifier for any given instance.

Specified by:
isUniquelyIdentified in interface ClassDefinition
Returns:
Is this a uniquely identified class?
See Also:
ClassDefinition.getUniqueIdentifier(), PropertyDefinition.getIsUniqueIdentifier()

lookupPropertyDefinition

public PropertyDefinition lookupPropertyDefinition(AUID propertyID)
                                            throws NullPointerException,
                                                   BadParameterException
Description copied from interface: ClassDefinition

Looks up and returns the property definition corresponding to the given AUID in the set of propertise defined for this class.

Specified by:
lookupPropertyDefinition in interface ClassDefinition
Parameters:
propertyID - AUID identifying the property to look up.
Returns:
Property definition with the given identifier.
Throws:
NullPointerException - The given property identifier is null.
BadParameterException - The given property identifier is not registered as a property definition for this class.

lookupPropertyDefinition

public PropertyDefinition lookupPropertyDefinition(String propertyName)
                                            throws NullPointerException,
                                                   BadParameterException
Throws:
NullPointerException
BadParameterException

lookupPropertyDefinition

public PropertyDefinition lookupPropertyDefinition(short propertyTag)
                                            throws BadParameterException
Throws:
BadParameterException

globalPropertyIDLookup

public static final PropertyDefinition globalPropertyIDLookup(short tag)

registerNewPropertyDefinition

public PropertyDefinition registerNewPropertyDefinition(AUID identification,
                                                        String name,
                                                        TypeDefinition typeDefinition,
                                                        boolean isOptional,
                                                        boolean isUniqueIdentifier,
                                                        Short pid)
                                                 throws NullPointerException,
                                                        AlreadyUniquelyIdentifiedException,
                                                        ObjectAlreadyAttachedException
Description copied from interface: ClassDefinition

Creates a new property definition and registers it in this class definition. The new property definition is returned.

Note that it is illegal to add mandatory properties to an existing (registered) class. This method will allow adding either optional or mandatory properties to a class, but they must be added to a class which has not yet been registered in the dictionary. If this class has already been registered, it is possible to add optional properties, but not through this method. Optional properties added to an existing (registered) class may be added through the InterchangeObject.createOptionalPropertyValue(PropertyDefinition, Object) method.

Specified by:
registerNewPropertyDefinition in interface ClassDefinition
Parameters:
identification - AUID to be used to identify this property.
name - Name of the new property.
typeDefinition - Type of the new property.
isOptional - True if new property is to be optional.
isUniqueIdentifier - True if new property is to be the unique identifier of the class.
pid - Short tag used to identify the property, or null if it is not known.
Returns:
The newly created property definition.
Throws:
NullPointerException - One of the name or type definition arguments is null.
AlreadyUniquelyIdentifiedException - This class already has a unique identifier property.
ObjectAlreadyAttachedException - A property with the given identifier has already been registered.
See Also:
Dictionary.getClassDefinitions(), PropertyDefinition, InterchangeObject.createOptionalPropertyValue(PropertyDefinition, Object)

registerOptionalPropertyDefinition

public PropertyDefinition registerOptionalPropertyDefinition(AUID identification,
                                                             String name,
                                                             TypeDefinition typeDefinition)
                                                      throws NullPointerException,
                                                             ObjectAlreadyAttachedException
Description copied from interface: ClassDefinition

Creates a new property definition and registers it in this class definition. The new property definition is returned.

Note that it is illegal to add mandatory properties to an already existing (registered) class. It is assumed that this property is being added to a class which is already registered. If so, it must be optional and this method will declare it so. If it is wished to add a mandatory property, that may be done through the registerNewPropertyDef() method, but that must be called on a class which is not yet registered.

Specified by:
registerOptionalPropertyDefinition in interface ClassDefinition
Parameters:
identification - AUID to be used to identify this property.
name - Name of the new property.
typeDefinition - Type of the new property.
Returns:
Newly created property definition.
Throws:
NullPointerException - Name or typeDef argument is null.
ObjectAlreadyAttachedException - The given property identifier has already been registered.

deepEquals

public final boolean deepEquals(Object o)
Description copied from class: MetaDefinition

Check to see if this definition is equal to the given object by comparing each property. The MetaDefinition.equals(Object) method only checks that the identies of two definitions are equal, relying on the unqiueness ensured by identity registration. This method is provided for debugging and validation purposes.

Overrides:
deepEquals in class MetaDefinition
Parameters:
o - Object to compare to this definition.
Returns:
Is the given object a meta definiition with all of its properties equal to this meta definition?
See Also:
MetaDefinition.deepEquals(java.lang.Object)

appendXMLChildren

public 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
Overrides:
appendXMLChildren in class MetaDefinition
Parameters:
parent - XML parent element to append child nodes to.

forAUID

public static final ClassDefinition forAUID(AUID identification)

Media Authoring
with Java API

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