JAC project
AOPSYS
CEDRIC & LIP6 labs

org.objectweb.jac.core.rtti
Class FieldItem

java.lang.Object
  |
  +--org.objectweb.jac.core.rtti.MetaItem
        |
        +--org.objectweb.jac.core.rtti.MetaItemDelegate
              |
              +--org.objectweb.jac.core.rtti.MemberItem
                    |
                    +--org.objectweb.jac.core.rtti.FieldItem
Direct Known Subclasses:
CollectionItem

public class FieldItem
extends MemberItem

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

In addition to the java.lang.reflect classical features, this RTTI method element is able to tell if a field is accessed for reading or writting by a given method.

It also provides some modification methods that are aspect compliant.

For the moment, default meta informations are setted by the ClassRepository class using some naming conventions. In a close future, these informations will be deduced from the class bytecodes analysis at load-time.

Author:
Renaud Pawlak, Laurent Martelli
See Also:
Field, getWritingMethods(), getAccessingMethods()

Field Summary
 
Fields inherited from class org.objectweb.jac.core.rtti.MemberItem
role, roleClassType, roleName, roleType
 
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
FieldItem(ClassItem parent)
           
FieldItem(Field delegate, ClassItem parent)
          Default contructor to create a new field item object.
FieldItem(String expression, List path, ClassItem parent)
          Creates an expression FieldItem
FieldItem(String name, MethodItem getter, ClassItem parent)
          Creates a calculated FieldItem
FieldItem(String name, MethodItem getter, MethodItem setter, ClassItem parent)
          Creates a FieldItem with specific getter and setter
 
Method Summary
 void addAccessingMethod(MethodItem accessingMethod)
          Add a new accessing method for this field.
 void addDependentField(FieldItem field)
           
 void addWritingMethod(MethodItem writingMethod)
          Add a new writing method for this field.
 void clearMethods()
          Remove accessing and writing methods
 FieldItem clone(ClassItem parent)
           
 Object get(Object object)
          Get the value of this field item for a given object.
 MethodItem[] getAccessingMethods()
          Get the methods that access this field for reading.
 Field getActualField()
          Get the field represented by this field item.
 Object getAttribute(String name)
          If the field does not have a value for the request attribute, tries on the superclass.
 FieldItem[] getDependentFields()
          Returns an array of calculated fields which depend on the field.
 FieldItem getField()
          Returns the actual field.
 MethodItem getGetter()
          Returns the getter of the field, if any.
 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.
 FieldItem getPathTop()
           
 MethodItem getSetter()
           
 Object getSubstance(Object substance)
          Returns proper substance to invoke methods on for expression fields.
 Object getThroughAccessor(Object substance)
          Get a field value through accessor if it exists.
 Class getType()
          This method gets the type of the meta item by delegating to the actual java.lang.reflect meta item.
 MethodItem[] getWritingMethods()
          Get the methods that access this field for writing.
 boolean hasAccessingMethods()
           
 boolean hasWritingMethods()
           
 boolean isCalculated()
          Tells whether the field is transient or not.
 boolean isFinal()
           
 boolean isPrimitive()
          Tells if this field item represents a primitive type (that is to say it is of a type that is not a reference towards a Jac object).
 boolean isReference()
          Tells if this field item represents a reference type (that is to say it is of a type that is a reference towards a Jac object).
 boolean isStatic()
           
 boolean isTransient()
          Tells whether the field is transient or not.
 boolean isWrappable(Object substance)
          Tells if the field item represents a wrappable type.
protected  FieldItem lastField()
           
 void set(Object object, Object value)
          Sets the value of this field item for a given object.
 void setAccessingMethods(MethodItem[] accessingMethods)
          Set the methods that access this field for reading.
 void setGetter(MethodItem getter)
           
 void setSetter(MethodItem setter)
           
 void setThroughWriter(Object substance, Object value)
          Sets the value of this field item by using its setter method if any (else use the set method.
 void setType(Class type)
           
 void setWritingMethods(MethodItem[] writingMethods)
          Set the methods that access this field for writing.
static Field[] toFields(FieldItem[] fieldItems)
          Transforms a field items array into a fields array containing the java.lang.reflect fields wrapped by the method items.
 String toString()
          Overloads the default method to call the delegate one.
 
Methods inherited from class org.objectweb.jac.core.rtti.MemberItem
addDependentMethod, equals, getClassItem, getDependentMethods, getLongName, getMemberFromFullName, getTypeItem, isRole, setRole
 
Methods inherited from class org.objectweb.jac.core.rtti.MetaItemDelegate
getDelegate, getParent, setParent
 
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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FieldItem

public FieldItem(Field delegate,
                 ClassItem parent)
          throws InvalidDelegateException
Default contructor to create a new field item object.

Parameters:
delegate - the java.lang.reflect.Field actual meta item

FieldItem

public FieldItem(ClassItem parent)

FieldItem

public FieldItem(String name,
                 MethodItem getter,
                 ClassItem parent)
Creates a calculated FieldItem

Parameters:
name - name of the field
getter - the getter method of the field

FieldItem

public FieldItem(String name,
                 MethodItem getter,
                 MethodItem setter,
                 ClassItem parent)
Creates a FieldItem with specific getter and setter

Parameters:
name - name of the field
getter - the getter method of the field
setter - the setter method of the field

FieldItem

public FieldItem(String expression,
                 List path,
                 ClassItem parent)
Creates an expression FieldItem

Parameters:
expression - expression of the field
Method Detail

toFields

public static Field[] toFields(FieldItem[] fieldItems)
Transforms a field items array into a fields array containing the java.lang.reflect fields wrapped by the method items.

Parameters:
fieldItems - the field items
Returns:
the actual fields in java.lang.reflect

getPathTop

public FieldItem getPathTop()

getAttribute

public final Object getAttribute(String name)
If the field does not have a value for the request attribute, tries on the superclass.

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

getAccessingMethods

public final MethodItem[] getAccessingMethods()
Get the methods that access this field for reading.

Returns:
value of accessingMethods.

hasAccessingMethods

public final boolean hasAccessingMethods()

setAccessingMethods

public final void setAccessingMethods(MethodItem[] accessingMethods)
Set the methods that access this field for reading.

Parameters:
accessingMethods - value to assign to accessingMethods.

addAccessingMethod

public final void addAccessingMethod(MethodItem accessingMethod)
Add a new accessing method for this field.

Parameters:
accessingMethod - the method to add

getWritingMethods

public final MethodItem[] getWritingMethods()
Get the methods that access this field for writing.

Returns:
value of writingMethods.

hasWritingMethods

public final boolean hasWritingMethods()

setWritingMethods

public final void setWritingMethods(MethodItem[] writingMethods)
Set the methods that access this field for writing.

Parameters:
writingMethods - value to assign to writingMethods.

addWritingMethod

public final void addWritingMethod(MethodItem writingMethod)
Add a new writing method for this field.

Parameters:
writingMethod - the method to add

clearMethods

public void clearMethods()
Remove accessing and writing methods


addDependentField

public final void addDependentField(FieldItem field)
See Also:
getDependentFields()

getDependentFields

public final FieldItem[] getDependentFields()
Returns an array of calculated fields which depend on the field.

See Also:
addDependentField(FieldItem)

getActualField

public final Field getActualField()
Get the field represented by this field item.

Returns:
the actual field

getSubstance

public Object getSubstance(Object substance)
Returns proper substance to invoke methods on for expression fields.


getField

public FieldItem getField()
Returns the actual field. In the case of an expression field, this is the last element of the path, otherwise it is the field itself.


get

public final Object get(Object object)
Get the value of this field item for a given object.

Parameters:
object - the object that supports the field
Returns:
the field value in the given object
See Also:
set(Object,Object)

getThroughAccessor

public Object getThroughAccessor(Object substance)
Get a field value through accessor if it exists.


set

public final void set(Object object,
                      Object value)
               throws IllegalAccessException,
                      IllegalArgumentException
Sets the value of this field item for a given object.

Parameters:
object - the object that supports the field
value - the value to set
IllegalAccessException
IllegalArgumentException
See Also:
get(Object)

setThroughWriter

public final void setThroughWriter(Object substance,
                                   Object value)
                            throws IllegalAccessException,
                                   IllegalArgumentException
Sets the value of this field item by using its setter method if any (else use the set method.

Parameters:
value - the new value of the field
IllegalAccessException
IllegalArgumentException
See Also:
set(Object,Object)

getSetter

public MethodItem getSetter()

setSetter

public void setSetter(MethodItem setter)

getGetter

public MethodItem getGetter()
Returns the getter of the field, if any.


setGetter

public void setGetter(MethodItem getter)

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

getType

public Class getType()
Description copied from class: MetaItemDelegate
This method gets the type of the meta item by delegating to the actual java.lang.reflect meta item.

Specified by:
getType in class MemberItem
Returns:
the item type

setType

public void setType(Class type)

isPrimitive

public boolean isPrimitive()
Tells if this field item represents a primitive type (that is to say it is of a type that is not a reference towards a Jac object).

Allways returns false on collections (use isWrappable to know if the field is wrappable).

Returns:
true if primitive
See Also:
isReference()

isReference

public boolean isReference()
Tells if this field item represents a reference type (that is to say it is of a type that is a reference towards a Jac object).

Allways returns false on collections (use isWrappable to know if the field is wrappable).

Returns:
true if reference
See Also:
isPrimitive(), isWrappable(Object)

isWrappable

public boolean isWrappable(Object substance)
Tells if the field item represents a wrappable type.

This method can be used on all kinds of field item including collections (on contrary to isPrimitive and isReference).

Returns:
true if wrappable
See Also:
isPrimitive(), isReference()

isTransient

public boolean isTransient()
Tells whether the field is transient or not.


isFinal

public boolean isFinal()

isStatic

public boolean isStatic()

getModifiers

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

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

lastField

protected FieldItem lastField()

isCalculated

public boolean isCalculated()
Tells whether the field is transient or not.


clone

public FieldItem clone(ClassItem parent)

toString

public String toString()
Description copied from class: MetaItemDelegate
Overloads the default method to call the delegate one.

Overrides:
toString in class MetaItemDelegate
Returns:
a textual representation of the object

Contact JAC development team:
Renaud Pawlak
Lionel Seinturier
Laurent Martelli