org.progeeks.meta
Class MetaClass

java.lang.Object
  extended by org.progeeks.meta.MetaClass
All Implemented Interfaces:
java.io.Serializable

public class MetaClass
extends java.lang.Object
implements java.io.Serializable

Describes the properties associated with a meta-object. MetaClass objects must be created through the factory methods provided by the MetaClassRegistry to which they will belong.

Version:
$Revision: 1.52 $
Author:
Paul Speed
See Also:
Serialized Form

Constructor Summary
protected MetaClass(MetaClassRegistry classRegistry, java.lang.String name, java.util.Collection propertyInfo, java.util.Collection identityProperties, java.util.Collection superclasses)
          Creates the meta-class using the specified parameters.
 
Method Summary
protected  void addProperty(PropertyInfo info)
          Adds the specified property info to this meta-class.
 boolean areEquivalent(MetaObject obj1, MetaObject obj2)
          Returns true if the specified meta-objects are equivalent based on this meta-class's identity.
 boolean equals(MetaClass mClass)
           
 boolean equals(java.lang.Object obj)
           
static MetaClass forName(java.lang.String name)
          Retrieves the specified class from the current context class registry or throws a RuntimeException.
 MetaClassRegistry getClassRegistry()
          Returns the class registry to which this meta-class belongs.
 java.lang.String getIdentityKey(MetaObject obj)
          Returns a string "key" for the MetaObject based on its identity.
 java.util.Set getIdentityProperties()
          Returns the set of the names of this MetaClass's identity properties.
 java.lang.Object getMetaClassAnnotation(AnnotationType type)
          Returns the general MetaClass-level annotation for the specified annotation type.
 java.lang.Object getMetaClassAnnotation(AnnotationType type, java.lang.Object key)
          Returns the MetaClass-level annotation for the specified annotation type and key.
 java.lang.String getName()
          Returns the name of this meta-class.
 java.lang.Object getPropertyAnnotation(AnnotationType type, java.lang.String propertyName)
          Returns the annotation for the specified annotation type and property.
 PropertyInfo getPropertyInfo(java.lang.String name)
          Returns the descriptive information for the specified property.
 java.util.Collection getPropertyInfos()
          Returns an unmodifiable collection of property info objects.
 java.util.Set getPropertyNames()
          Returns the unmodifiable sorted set of property names in alphabetical order.
 PropertyType getPropertyType(java.lang.String name)
          Returns the type for the specified property.
 java.util.List getSuperclasses()
          Returns a List containing the immediate superclasses of this meta-class.
 int hashCode()
           
 int hashCode(MetaObject instance, int defaultHash)
          Returns a hashcode for the specified MetaObject instance based on the identity properties for this meta-class.
 boolean hasIdentity()
          Returns true if this class defines any identity properties.
 boolean hasProperty(java.lang.String name)
          Returns true if this class has the specified property defined.
 boolean isAssignableFrom(MetaClass metaClass)
          Returns true if this MetaClass is either the same as or is a superclass of the specified MetaClass.
 boolean isInstance(MetaObject obj)
          Returns true if the specified meta-object is an instance of this class.
 boolean isInstance(java.lang.Object obj)
          Returns true if the specified object is a meta-object and an instance of this class.
static MetaClass lookupMetaClass(java.lang.String name)
          Retrieves the specified class from the current context class registry or returns null.
 java.util.Iterator propertyNames()
          Returns an iterator over all valid property names in alphabetical order.
protected  PropertyType resolveType(PropertyType type)
          Called internally to resolve a property type if it is required.
 void resolveTypes()
          Resolves any deferred types against the class registry associated with this meta-class.
 void setMetaClassAnnotation(AnnotationType type, java.lang.Object annotation)
          Sets the general MetaClass-level annotation for the specified annotation type to the specified value.
 void setMetaClassAnnotation(AnnotationType type, java.lang.Object key, java.lang.Object annotation)
          Sets the MetaClass-level annotation for the specified annotation type and key to the specified value.
 void setPropertyAnnotation(AnnotationType type, java.lang.String propertyName, java.lang.Object annotation)
          Sets the annotation value for the specified annotation type and property.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MetaClass

protected MetaClass(MetaClassRegistry classRegistry,
                    java.lang.String name,
                    java.util.Collection propertyInfo,
                    java.util.Collection identityProperties,
                    java.util.Collection superclasses)
Creates the meta-class using the specified parameters.

Method Detail

resolveType

protected PropertyType resolveType(PropertyType type)
Called internally to resolve a property type if it is required.


resolveTypes

public void resolveTypes()
Resolves any deferred types against the class registry associated with this meta-class. This should be called by meta-object implementations during instantiation until a more automatic way becomes available.


getClassRegistry

public MetaClassRegistry getClassRegistry()
Returns the class registry to which this meta-class belongs.


getName

public java.lang.String getName()
Returns the name of this meta-class.


getSuperclasses

public java.util.List getSuperclasses()
Returns a List containing the immediate superclasses of this meta-class.


getIdentityProperties

public java.util.Set getIdentityProperties()
Returns the set of the names of this MetaClass's identity properties. The set of identity properties is what MetaObject implementations should use to determine object equivalence. All of the usual caveats apply regarding using meta-objects as HashMap keys when their identity values are mutable. In general, only immutable properties should be used for identity determination.


hasIdentity

public boolean hasIdentity()
Returns true if this class defines any identity properties.


addProperty

protected void addProperty(PropertyInfo info)
Adds the specified property info to this meta-class. If the specified PropertyInfo contains a DeferredPropertyType and there a exists a superclass property that is not a DeferredPropertyType then the supplied type well be resolved here instead of when the class is resolved later. The theory is that only way the types would ever be compatible is if they were resolved the same way. If the supertype is already resolved then it must be ok to resolve the subtype. If not, then they weren't compatible anyway.


getPropertyType

public PropertyType getPropertyType(java.lang.String name)
Returns the type for the specified property.


getPropertyInfo

public PropertyInfo getPropertyInfo(java.lang.String name)
Returns the descriptive information for the specified property.


propertyNames

public java.util.Iterator propertyNames()
Returns an iterator over all valid property names in alphabetical order. Returned property names will always be in alphabetical order and this is part of the contract. Several pieces of code are optimized based on this behavior.


getPropertyNames

public java.util.Set getPropertyNames()
Returns the unmodifiable sorted set of property names in alphabetical order. Returned property names will always be in alphabetical order and this is part of the contract. Several pieces of code are optimized based on this behavior.


hasProperty

public boolean hasProperty(java.lang.String name)
Returns true if this class has the specified property defined.


getPropertyInfos

public java.util.Collection getPropertyInfos()
Returns an unmodifiable collection of property info objects.


getMetaClassAnnotation

public java.lang.Object getMetaClassAnnotation(AnnotationType type)
Returns the general MetaClass-level annotation for the specified annotation type.


setMetaClassAnnotation

public void setMetaClassAnnotation(AnnotationType type,
                                   java.lang.Object annotation)
                            throws ImmutableAnnotationMapException
Sets the general MetaClass-level annotation for the specified annotation type to the specified value.

Throws:
ImmutableAnnotationMapException - if the annotation type does not support updates to annotation values.

getMetaClassAnnotation

public java.lang.Object getMetaClassAnnotation(AnnotationType type,
                                               java.lang.Object key)
Returns the MetaClass-level annotation for the specified annotation type and key.


setMetaClassAnnotation

public void setMetaClassAnnotation(AnnotationType type,
                                   java.lang.Object key,
                                   java.lang.Object annotation)
                            throws ImmutableAnnotationMapException,
                                   UnsupportedKeyException
Sets the MetaClass-level annotation for the specified annotation type and key to the specified value.

Throws:
ImmutableAnnotationMapException - if the annotation type does not support updates to annotation values.
UnsupportedKeyException - if the specified key is not supported by the underlying implementation.

getPropertyAnnotation

public java.lang.Object getPropertyAnnotation(AnnotationType type,
                                              java.lang.String propertyName)
Returns the annotation for the specified annotation type and property.


setPropertyAnnotation

public void setPropertyAnnotation(AnnotationType type,
                                  java.lang.String propertyName,
                                  java.lang.Object annotation)
                           throws ImmutableAnnotationMapException
Sets the annotation value for the specified annotation type and property.

Throws:
ImmutableAnnotationMapException - if the annotation type does not support updates to annotation values.

isInstance

public boolean isInstance(MetaObject obj)
Returns true if the specified meta-object is an instance of this class.


isInstance

public boolean isInstance(java.lang.Object obj)
Returns true if the specified object is a meta-object and an instance of this class.


isAssignableFrom

public boolean isAssignableFrom(MetaClass metaClass)
Returns true if this MetaClass is either the same as or is a superclass of the specified MetaClass.


hashCode

public int hashCode(MetaObject instance,
                    int defaultHash)
Returns a hashcode for the specified MetaObject instance based on the identity properties for this meta-class. If this meta-class has no identity properties then the specified hashcode is used.


areEquivalent

public boolean areEquivalent(MetaObject obj1,
                             MetaObject obj2)
Returns true if the specified meta-objects are equivalent based on this meta-class's identity. If this meta-class has no identity then this method returns false unless the objects are reference equivalent, i.e.: obj1 == obj2.


getIdentityKey

public java.lang.String getIdentityKey(MetaObject obj)
Returns a string "key" for the MetaObject based on its identity. This will throw an UnsupportedOperationException if the class doesn't have an identity defined. Note: the key will be created in the order that the identity fields are defined. This means that identity order equivalence is necessary when comparing keys. A small limitation in the interest of performance.


hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(MetaClass mClass)

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

forName

public static MetaClass forName(java.lang.String name)
                         throws MetaClassNotFoundException
Retrieves the specified class from the current context class registry or throws a RuntimeException. For non-registry-specific lookups, this is the preferrred method for getting MetaClasses.

Throws:
MetaClassNotFoundException

lookupMetaClass

public static MetaClass lookupMetaClass(java.lang.String name)
Retrieves the specified class from the current context class registry or returns null. This is similar to forName() except that it won't throw an exception if the class isn't found.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2002-2003 Paul Speed. All Rights Reserved.