JAC project
AOPSYS
CEDRIC & LIP6 labs

org.objectweb.jac.core.rtti
Class ClassItem

java.lang.Object
  |
  +--org.objectweb.jac.core.rtti.MetaItem
        |
        +--org.objectweb.jac.core.rtti.MetaItemDelegate
              |
              +--org.objectweb.jac.core.rtti.ClassItem

public class ClassItem
extends MetaItemDelegate

This class defines a meta item that corresponds to the java.lang.reflect.Class meta element.

Author:
Renaud Pawlak, Laurent Martelli

Nested Class Summary
static class ClassItem.AmbiguousMethodNameException
          The exception that is thrown when the accessed method has some synonymes (methods with same names but different parameter types).
 
Field Summary
protected  Hashtable fields
          Stores the fields of the class.
protected  Hashtable methods
          Stores the methods of the class.
 
Fields inherited from class org.objectweb.jac.core.rtti.MetaItemDelegate
delegate, parent
 
Fields inherited from class org.objectweb.jac.core.rtti.MetaItem
attrACs
 
Constructor Summary
ClassItem(Class delegate)
          Default contructor to create a new class item object.
 
Method Summary
 void addChild(ClassItem child)
           
 void addConstructor(ConstructorItem constructor)
          Add a constructor item to this class item.
 void addMethod(MethodItem method)
          Add a method item to this class item.
protected  void buildFieldInfo()
           
 Collection filterFields(String expression)
           
 CollectionItem findCollectionFor(Object substance, Object object)
          Finds the collection of this class item that contains the given object.
 AbstractMethodItem getAbstractMethod(String name)
          Gets an abstract method from its name.
 AbstractMethodItem[] getAbstractMethods(String name)
          Gets a set of homonym methods (including constructors) from their names.
 Class getActualClass()
          Gets the class represented by this class item.
 Collection getAllAccessors()
          Gets all the method items that access the state of the instances for this class item.
 Collection getAllAdders()
          Gets all the method items that adds an object from a collection of this class item.
 Collection getAllFields()
          Gets all the fields for this class item
 Collection getAllGetters()
          Gets all the getter methods of the class.
 Collection getAllInstanceMethods()
           
 Collection getAllMembers()
           
 Collection getAllMethods()
          Gets all the method items for this class item.
 Collection getAllModifiers()
          Gets all the method items that modify the state of the instances for this class item.
 Collection getAllRemovers()
          Gets all the method items that removes an object from a collection of this class item.
 Collection getAllSetters()
          Gets all the method items that modify the state of the instances for this class item.
 Collection getAllStaticMethods()
           
 Collection getAllWriters()
          Gets all the method items that modify a field of the instances for this class item.
 Object getAttribute(String name)
          Get an attribute by searching recursively through all super classes.
 Collection getChildren()
           
 CollectionItem getCollection(String name)
          Gets a collection from its name.
 CollectionItem[] getCollections()
          Gets all the collections for this class item.
 Collection getConstraints()
          Return all field and collection items whose component type is this class.
 ConstructorItem getConstructor(Class[] parameterTypes)
           
 ConstructorItem getConstructor(Constructor constructor)
          Gets the constructor item of this class item that matches the given java.lang.reflect.Constructor.
 ConstructorItem getConstructor(String parameterTypes)
           
 Collection getConstructors()
          Gets all the constructors items for this class item.
 FieldItem getField(String name)
          Gets a field from its name.
 FieldItem getFieldNoError(String name)
          Gets a field from its name.
 FieldItem[] getFields()
          Gets all the fields for this class item.
 FieldItem[] getFields(String[] names)
          Returns a FieldItem array.
 ClassItem[] getInterfaceItems()
          Returns the interfaces implemented by this class.
 Collection getMatchingRelations(String expr)
          Gets all the references and collections that match the expression for this class item.
 MemberItem getMember(String name)
          Returns the member (method or field) of this class with the specified name.
 MemberItem[] getMembers(String[] names)
          Returns a MemberItem array.
 MethodItem getMethod(String name)
          Gets a method from its name.
 Collection getMethods()
          Gets a set of arrays containing all the method items for this class item.
 MethodItem[] getMethods(String name)
          Gets a set of homonym methods (excluding constructors) from their names.
 MethodItem[] getMethods(String[] names)
          Returns a MethodItem array.
 int getModifiers()
          Get the modifiers (see java.lang.reflect) of the meta item.
 String getName()
          This method gets the name of the meta item by delegating to the actual java.lang.reflect meta item.
 ClassItem getOwnerClassItem()
          Gets the class this class is an inner class of.
 FieldItem[] getPrimitiveFields()
          Gets all the primitive fields for this class item.
 FieldItem[] getReferences()
          Gets all the references for this class item.
 String getShortName()
           
 ClassItem getSuperclass()
          Gets the superclass of this class item.
 Collection getTaggedFields(String attribute, boolean not)
          Gets all the current class item's fields that are tagged or not tagged with the given attribute.
 Collection getTaggedMembers(String attribute, boolean not)
           
 Collection getTaggedMembers(String attribute, Object value)
          Returns the members that are tagged by a given attribute that has a given value.
 Collection getTaggedMethods(String attribute, boolean not)
           
 Class getType()
          Synonym of getActualClass.
 boolean hasField(String name)
          Tests if a field exist in this class item.
 boolean hasMethod(MethodItem method)
           
 boolean hasMethod(String name)
          Tests if a method exist in this class item.
 Object invoke(Object object, String methodName, Object[] parameters)
          A shortcut to invoke a method (avoid to get the method item).
 boolean isAbstract()
           
 boolean isInner()
          Tells wether this class is an inner class of some other class
 boolean isSubClassOf(ClassItem cl)
          Tells wether the class inherits from a subclass whose name matches a regular expression.
 boolean isSubClassOf(RE classNameRE)
          Tells wether the class inherits from a subclass whose name matches a regular expression.
 Object newInstance()
          Creates a new instance of this class item by using the default constructor (the one with no parameters).
 Object newInstance(Class[] types, Object[] values)
          Creates a new instance of this class item by using the constructor that matches the given parameter types.
 Object newInstance(Object[] parameters)
          Create a new instance of the class, using the first constructor suitable for the given parameters.
 List parseExpression(String expression)
          Parse the expression and computes its type.
protected  void setSuperClass(ClassItem superClass)
          Set the super class of this class and updates the children of the super class.
 Object superGetAttribute(String name)
           
 
Methods inherited from class org.objectweb.jac.core.rtti.MetaItemDelegate
getDelegate, getParent, setParent, toString
 
Methods inherited from class org.objectweb.jac.core.rtti.MetaItem
getAttribute, getAttribute, getAttributeAlways, getBoolean, getItemClass, registerAccessController, setAttribute, setItemClass, unsetAttribute, unsetAttributesFor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fields

protected Hashtable fields
Stores the fields of the class.


methods

protected Hashtable methods
Stores the methods of the class.

Constructor Detail

ClassItem

public ClassItem(Class delegate)
          throws InvalidDelegateException
Default contructor to create a new class item object.

Parameters:
delegate - the java.lang.reflect.Class actual meta item
Method Detail

buildFieldInfo

protected void buildFieldInfo()

getField

public FieldItem getField(String name)
Gets a field from its name. Throw an exception if the field does not exist.

Parameters:
name - the field name. If name contains a dot, it is considered an expression field and is automatically created if it does not exist yet.
Returns:
a FieldItem instance
See Also:
getFieldNoError(String)

getFieldNoError

public FieldItem getFieldNoError(String name)
Gets a field from its name. Don't throw an exception if the field does not exist.

Parameters:
name - the field name
Returns:
a FieldItem instance, or null if no such field exists in the class
See Also:
getField(String)

parseExpression

public List parseExpression(String expression)
Parse the expression and computes its type.

Parameters:
expression - the expression (.....)

getCollection

public CollectionItem getCollection(String name)
Gets a collection from its name.

Parameters:
name - the collection name
Returns:
a CollectionItem instance

getFields

public FieldItem[] getFields()
Gets all the fields for this class item.

Returns:
an array of field items

getAllFields

public Collection getAllFields()
Gets all the fields for this class item

Returns:
the fields as a collection

getTaggedFields

public Collection getTaggedFields(String attribute,
                                  boolean not)
Gets all the current class item's fields that are tagged or not tagged with the given attribute.

Parameters:
attribute - the attribute
not - if true, returns fields not tagged with attribute
Returns:
a collection of field items

filterFields

public Collection filterFields(String expression)
Parameters:
expression - something like [!](static|transient|private|public|protected)

getTaggedMethods

public Collection getTaggedMethods(String attribute,
                                   boolean not)

getTaggedMembers

public Collection getTaggedMembers(String attribute,
                                   boolean not)

getTaggedMembers

public Collection getTaggedMembers(String attribute,
                                   Object value)
Returns the members that are tagged by a given attribute that has a given value.

Parameters:
attribute - the attribute id
value - the value of the attribute (must not be null!!)

getMember

public MemberItem getMember(String name)
Returns the member (method or field) of this class with the specified name.

Parameters:
name - the name of the member that you want.
Returns:
the member with the specified name
See Also:
getMembers(String[])

getMembers

public MemberItem[] getMembers(String[] names)
Returns a MemberItem array.

Parameters:
names - the names of the members
Returns:
a MemberItem array members such as members[i].getName().equals(names[i]). If no member with a given name is found, it is ignored (but a warning is issued).
See Also:
getMember(String)

getAllMembers

public Collection getAllMembers()

getFields

public FieldItem[] getFields(String[] names)
Returns a FieldItem array.

Parameters:
names - the names of the members
Returns:
a FieldItem array fields such as fields[i].getName().equals(names[i]). If no field with a given name is found, it is ignored (but a warning is issued).
See Also:
getField(String)

getMethods

public MethodItem[] getMethods(String[] names)
Returns a MethodItem array.

Parameters:
names - the names of the members
Returns:
a MethodItem array methods such as methods[i].getName().equals(names[i]). If no method with a given name is found, it is ignored (but a warning is issued).
See Also:
getMethod(String)

getPrimitiveFields

public FieldItem[] getPrimitiveFields()
Gets all the primitive fields for this class item.

Returns:
an array of field items

getReferences

public FieldItem[] getReferences()
Gets all the references for this class item.

Returns:
an array of field items

getMatchingRelations

public Collection getMatchingRelations(String expr)
Gets all the references and collections that match the expression for this class item.

Returns:
a vector of field items

getCollections

public CollectionItem[] getCollections()
Gets all the collections for this class item.

Returns:
an array of field items

getAbstractMethods

public AbstractMethodItem[] getAbstractMethods(String name)
                                        throws NoSuchMethodException
Gets a set of homonym methods (including constructors) from their names.

Parameters:
name - the name of the methods
Returns:
a MethodItem instance
NoSuchMethodException

getAbstractMethod

public AbstractMethodItem getAbstractMethod(String name)
                                     throws NoSuchMethodException,
                                            ClassItem.AmbiguousMethodNameException
Gets an abstract method from its name.

If this method has homonym(s), then an AmbiguousMethodNameException is thrown.

An abstract method can be a static, an instance method or a constructor.

Parameters:
name - the name of the method to search
Returns:
the corresponding method if found
NoSuchMethodException
ClassItem.AmbiguousMethodNameException
See Also:
getMethod(String), getAbstractMethods(String)

getMethods

public MethodItem[] getMethods(String name)
                        throws NoSuchMethodException
Gets a set of homonym methods (excluding constructors) from their names.

Parameters:
name - the name of the methods
Returns:
a MethodItem instance
NoSuchMethodException

getMethod

public MethodItem getMethod(String name)
                     throws NoSuchMethodException,
                            ClassItem.AmbiguousMethodNameException
Gets a method from its name.

If this method has homonym(s), then an AmbiguousMethodNameException is thrown.

A method can be a static or instance method but not a constructor.

Parameters:
name - the name of the method to search
Returns:
the corresponding method if found
NoSuchMethodException
ClassItem.AmbiguousMethodNameException
See Also:
getAbstractMethod(String), getMethods(String)

getMethods

public Collection getMethods()
Gets a set of arrays containing all the method items for this class item.

Each arrays contains the methods of the same name.

Returns:
a collection containing the methods

getAllMethods

public Collection getAllMethods()
Gets all the method items for this class item.

Returns:
a collection containing the methods

getAllStaticMethods

public Collection getAllStaticMethods()
Returns:
a collection of static MethodItem

getAllInstanceMethods

public Collection getAllInstanceMethods()
Returns:
a collection of non static MethodItem

getAllModifiers

public Collection getAllModifiers()
Gets all the method items that modify the state of the instances for this class item.

Returns:
a collection of MethodItem containing the modifiers

getAllSetters

public Collection getAllSetters()
Gets all the method items that modify the state of the instances for this class item.

Returns:
a collection of MethodItem containing the modifiers

getAllWriters

public Collection getAllWriters()
Gets all the method items that modify a field of the instances for this class item.

Returns:
a collection of MethodItem containing the writers

getAllGetters

public Collection getAllGetters()
Gets all the getter methods of the class.

Returns:
a collection containing the getters
See Also:
MethodItem.isGetter()

getAllAccessors

public Collection getAllAccessors()
Gets all the method items that access the state of the instances for this class item.

Returns:
a collection containing the accessors

getAllRemovers

public Collection getAllRemovers()
Gets all the method items that removes an object from a collection of this class item.

Returns:
a collection containing the modifiers

getAllAdders

public Collection getAllAdders()
Gets all the method items that adds an object from a collection of this class item.

Returns:
a collection containing the modifiers

getConstructors

public Collection getConstructors()
Gets all the constructors items for this class item.

Returns:
a collection containing the constructors

getConstructor

public ConstructorItem getConstructor(Class[] parameterTypes)
                               throws NoSuchMethodException
NoSuchMethodException

getConstructor

public ConstructorItem getConstructor(String parameterTypes)

getConstructor

public ConstructorItem getConstructor(Constructor constructor)
Gets the constructor item of this class item that matches the given java.lang.reflect.Constructor.

Returns:
the corresponding constructor item

newInstance

public Object newInstance()
                   throws InstantiationException,
                          IllegalAccessException
Creates a new instance of this class item by using the default constructor (the one with no parameters).

Returns:
the newly created instance
InstantiationException
IllegalAccessException

newInstance

public Object newInstance(Class[] types,
                          Object[] values)
                   throws InstantiationException,
                          IllegalAccessException,
                          NoSuchMethodException,
                          InvocationTargetException
Creates a new instance of this class item by using the constructor that matches the given parameter types.

Parameters:
types - the types of the constructor arguments
values - the arguments values
Returns:
the newly created instance
InstantiationException
IllegalAccessException
NoSuchMethodException
InvocationTargetException

newInstance

public Object newInstance(Object[] parameters)
                   throws InstantiationException,
                          IllegalAccessException,
                          NoSuchMethodException,
                          InvocationTargetException
Create a new instance of the class, using the first constructor suitable for the given parameters.

Parameters:
parameters - parameters of the constructor
InstantiationException
IllegalAccessException
NoSuchMethodException
InvocationTargetException

getActualClass

public Class getActualClass()
Gets the class represented by this class item.

Returns:
the actual class
See Also:
getType()

getInterfaceItems

public ClassItem[] getInterfaceItems()
Returns the interfaces implemented by this class.


setSuperClass

protected void setSuperClass(ClassItem superClass)
Set the super class of this class and updates the children of the super class.

Parameters:
superClass - the super class

getSuperclass

public ClassItem getSuperclass()
Gets the superclass of this class item.

Returns:
the superclass, null if the superclass is Object

getChildren

public Collection getChildren()

addChild

public void addChild(ClassItem child)

isSubClassOf

public boolean isSubClassOf(RE classNameRE)
Tells wether the class inherits from a subclass whose name matches a regular expression.

Parameters:
classNameRE - the regular expression

isSubClassOf

public boolean isSubClassOf(ClassItem cl)
Tells wether the class inherits from a subclass whose name matches a regular expression.


getModifiers

public int getModifiers()
Description copied from class: MetaItemDelegate
Get the modifiers (see java.lang.reflect) of the meta item.

Overrides:
getModifiers in class MetaItemDelegate
Returns:
an int representing the modifiers
See Also:
Modifier

getType

public Class getType()
Synonym of getActualClass.

Specified by:
getType in class MetaItemDelegate
Returns:
the actual class
See Also:
getActualClass()

addMethod

public void addMethod(MethodItem method)
Add a method item to this class item.

Parameters:
method - the new method

addConstructor

public void addConstructor(ConstructorItem constructor)
Add a constructor item to this class item.

Parameters:
constructor - the new constructor

hasMethod

public boolean hasMethod(String name)
Tests if a method exist in this class item.

Returns:
true if exist

hasMethod

public boolean hasMethod(MethodItem method)

hasField

public boolean hasField(String name)
Tests if a field exist in this class item.

Returns:
true if exist

getName

public String getName()
Description copied from class: MetaItem
This method gets the name of the meta item by delegating to the actual java.lang.reflect meta item.

Specified by:
getName in class MetaItem
Returns:
the item name

getShortName

public String getShortName()

invoke

public Object invoke(Object object,
                     String methodName,
                     Object[] parameters)
              throws IllegalAccessException,
                     InvocationTargetException
A shortcut to invoke a method (avoid to get the method item).

Parameters:
object - the object to perform the invocation on (may be null for a static method)
methodName - the name of the method to invoke
parameters - the parameters passed to the method
IllegalAccessException
InvocationTargetException
See Also:
MethodItem.invoke(Object,Object[])

isInner

public boolean isInner()
Tells wether this class is an inner class of some other class

Returns:
true if the class is an inner class

isAbstract

public boolean isAbstract()

getOwnerClassItem

public ClassItem getOwnerClassItem()
Gets the class this class is an inner class of.

Returns:
the ClassItem this class is an inner class of, or null.

findCollectionFor

public CollectionItem findCollectionFor(Object substance,
                                        Object object)
Finds the collection of this class item that contains the given object.

Parameters:
substance - the instance of the current class item to seek in
object - the object to find
Returns:
the collection item, null if not found

getAttribute

public Object getAttribute(String name)
Get an attribute by searching recursively through all super classes.

Overrides:
getAttribute in class MetaItem
Parameters:
name - the name of the attribute
Returns:
the value of the attribute

superGetAttribute

public Object superGetAttribute(String name)

getConstraints

public Collection getConstraints()
Return all field and collection items whose component type is this class.

Returns:
a collection of FieldItem

Contact JAC development team:
Renaud Pawlak
Lionel Seinturier
Laurent Martelli