org.codehaus.metaclass
Class Attributes

java.lang.Object
  extended byorg.codehaus.metaclass.Attributes

public class Attributes
extends java.lang.Object

Utility class to make it easy to access attributes for classes and methods. The utility class makes it possible to access attributes for methods and fields by using one method call such as;

    //Get all Class attributes for 'MyClass'
    Attribute[] attributes =
           Attributes.getAttributes( MyClass.class );

    //Get all Class attributes for 'MyClass'
    //that have name 'dna.service'
    Attribute[] attributes =
           Attributes.getAttributes( MyClass.class, "dna.service" );

    //Get attribute named 'dna.component' for 'MyClass'
    //Note: that this may return null
    Attribute attribute =
           Attributes.getAttribute( MyClass.class, "dna.component" );
 

Note that none of the methods in this class throw an exception. If an error occurs retrieving attributes for a particular artefact (such as being unable to load ClassDescriptor for class) then either an empty array or a null will be returned depending on the method.

Version:
$Revision: 1.11 $ $Date: 2003/10/14 01:24:23 $

Constructor Summary
Attributes()
           
 
Method Summary
static Attribute getAttribute(java.lang.Class clazz, java.lang.String name)
          Return the attribute for specified Class that has the specified name.
static Attribute getAttribute(java.lang.reflect.Constructor constructor, java.lang.String name)
          Return the attribute for specified Constructor that has the specified name.
static Attribute getAttribute(java.lang.reflect.Field field, java.lang.String name)
          Return the attribute for specified Field that has the specified name.
static Attribute getAttribute(java.lang.reflect.Method method, java.lang.String name)
          Return the attribute for specified Method that has the specified name.
static Attribute getAttributeByName(Attribute[] attributes, java.lang.String name)
          Return the Attributes with specified name from specified attributes.
static Attribute[] getAttributes(java.lang.Class clazz)
          Return the attributes for specified Class.
static Attribute[] getAttributes(java.lang.Class clazz, java.lang.String name)
          Return the attributes for specified Class that have specified name.
static Attribute[] getAttributes(java.lang.reflect.Constructor constructor)
          Return the attributes for specified Constructor.
static Attribute[] getAttributes(java.lang.reflect.Constructor constructor, java.lang.String name)
          Return the attributes for specified Constructor that have specified name.
static Attribute[] getAttributes(java.lang.reflect.Field field)
          Return the attributes for specified Class.
static Attribute[] getAttributes(java.lang.reflect.Field field, java.lang.String name)
          Return the attributes for specified Field that have specified name.
static Attribute[] getAttributes(java.lang.reflect.Method method)
          Return the attributes for specified Method.
static Attribute[] getAttributes(java.lang.reflect.Method method, java.lang.String name)
          Return the attributes for specified Method that have specified name.
static Attribute[] getAttributesByName(Attribute[] attributes, java.lang.String name)
          Return the set of Attributes with specified name from specified attributes.
static MethodDescriptor getConstructor(java.lang.reflect.Constructor constructor)
          Get the MethodDescriptor for specified Constructor.
static FieldDescriptor getField(java.lang.reflect.Field field)
          Get the FieldDescriptor with specified name for specified Class.
static MethodDescriptor getMethod(java.lang.reflect.Method method)
          Get the MethodDescriptor for specified method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Attributes

public Attributes()
Method Detail

getAttributeByName

public static Attribute getAttributeByName(Attribute[] attributes,
                                           java.lang.String name)
Return the Attributes with specified name from specified attributes.

Parameters:
attributes - the attributes
name - the name of attribute to collect
Returns:
the attribute from set with specified name

getAttributesByName

public static Attribute[] getAttributesByName(Attribute[] attributes,
                                              java.lang.String name)
Return the set of Attributes with specified name from specified attributes.

Parameters:
attributes - the attributes
name - the name of attributes to collect
Returns:
the attributes from set with specified name

getAttributes

public static Attribute[] getAttributes(java.lang.Class clazz)
Return the attributes for specified Class.

Parameters:
clazz - the class
Returns:
the 'Class' attributes

getAttributes

public static Attribute[] getAttributes(java.lang.Class clazz,
                                        java.lang.String name)
Return the attributes for specified Class that have specified name.

Parameters:
clazz - the class
name - the attribute name
Returns:
the attributes

getAttribute

public static Attribute getAttribute(java.lang.Class clazz,
                                     java.lang.String name)
Return the attribute for specified Class that has the specified name. If there are multiple attributes with the same name then the first attribute will be returned.

Parameters:
clazz - the class
name - the attribute name
Returns:
the attribute or null if no such attribute

getAttributes

public static Attribute[] getAttributes(java.lang.reflect.Field field)
Return the attributes for specified Class.

Parameters:
field - the field
Returns:
the 'Field' attributes

getAttributes

public static Attribute[] getAttributes(java.lang.reflect.Field field,
                                        java.lang.String name)
Return the attributes for specified Field that have specified name.

Parameters:
field - the field
name - the attribute name
Returns:
the 'Field' attributes

getAttribute

public static Attribute getAttribute(java.lang.reflect.Field field,
                                     java.lang.String name)
Return the attribute for specified Field that has the specified name. If there are multiple attributes with the same name then the first attribute will be returned.

Parameters:
field - the field
name - the attribute name
Returns:
the attribute or null if no such attribute

getAttributes

public static Attribute[] getAttributes(java.lang.reflect.Method method)
Return the attributes for specified Method.

Parameters:
method - the method
Returns:
the 'Method' attributes

getAttributes

public static Attribute[] getAttributes(java.lang.reflect.Method method,
                                        java.lang.String name)
Return the attributes for specified Method that have specified name.

Parameters:
method - the Method
name - the attribute name
Returns:
the attributes

getAttribute

public static Attribute getAttribute(java.lang.reflect.Method method,
                                     java.lang.String name)
Return the attribute for specified Method that has the specified name. If there are multiple attributes with the same name then the first attribute will be returned.

Parameters:
method - the method
name - the attribute name
Returns:
the attribute or null if no such attribute

getAttributes

public static Attribute[] getAttributes(java.lang.reflect.Constructor constructor)
Return the attributes for specified Constructor.

Parameters:
constructor - the constructor
Returns:
the 'Constructor' attributes

getAttributes

public static Attribute[] getAttributes(java.lang.reflect.Constructor constructor,
                                        java.lang.String name)
Return the attributes for specified Constructor that have specified name.

Parameters:
constructor - the Constructor
name - the attribute name
Returns:
the attributes

getAttribute

public static Attribute getAttribute(java.lang.reflect.Constructor constructor,
                                     java.lang.String name)
Return the attribute for specified Constructor that has the specified name. If there are multiple attributes with the same name then the first attribute will be returned.

Parameters:
constructor - the constructor
name - the attribute name
Returns:
the attribute or null if no such attribute

getField

public static FieldDescriptor getField(java.lang.reflect.Field field)
                                throws MetaClassException
Get the FieldDescriptor with specified name for specified Class.

Parameters:
field - the field
Returns:
the FieldDescriptor
Throws:
MetaClassException - if unable to locate FieldDescriptor for Field

getMethod

public static MethodDescriptor getMethod(java.lang.reflect.Method method)
                                  throws MetaClassException
Get the MethodDescriptor for specified method.

Parameters:
method - the method
Returns:
the MethodDescriptor
Throws:
MetaClassException - if unable to locate MethodDescriptor for Method

getConstructor

public static MethodDescriptor getConstructor(java.lang.reflect.Constructor constructor)
                                       throws MetaClassException
Get the MethodDescriptor for specified Constructor.

Parameters:
constructor - the Constructor
Returns:
the MethodDescriptor
Throws:
MetaClassException - if unable to locate MethodDescriptor for Constructor


Copyright © 2003-2004 Codehaus. All Rights Reserved.