org.apache.commons.attributes
Class Attributes

java.lang.Object
  extended by org.apache.commons.attributes.Attributes

public class Attributes
extends java.lang.Object

API for accessing attributes.

General Notes on Errors

All Methods in this class may throw RepositoryError or subclasses thereof. This Error is thrown if an attribute repository can not be loaded for some Exceptional reason.

Rationale for Errors instead of Exceptions

The methods in this class throws Errors instead of Exceptions. This rationale behind this is that:

Null References

If a parameter to a method may not be null, and a null is passed to the method, a NullPointerException will be thrown, with the parameter name in the message.

Rationale for using this instead of IllegalArgumentException is that it is more precise - the reference was null.

Performance Notes

The process of loading attributes for a class is a (relatively) time-consuming process, as it involves some dynamic linking in the form of inheritable attributes, a lot of reflection and so on. However, once loaded the attributes are cached, so repeated access to them are fast. But despite this the process of finding one attribute of a given type or such operations does involve some iteration of HashSets that runs in linear time in the number of attributes associated with the program element, and you should avoid accessing attributes in your innermost loops if you can avoid it. For example, instead of:


 Class myClass = ...;
 for (int i = 0; i < 10000; i++) {
     if (Attributes.hasAttributeType (myClass, MyAttribute.class)) {
         doThis(myClass);
     } else {
         doThat(myClass);
     }
 }
 
do:

 Class myClass = ...;
 boolean shouldDoThis = Attributes.hasAttributeType (myClass, MyAttribute.class);
 for (int i = 0; i < 10000; i++) {
     if (shouldDoThis) {
         doThis(myClass);
     } else {
         doThat(myClass);
     }
 }
 
if the loop should run at maximum speed.

Since:
2.1

Field Summary
private static java.util.Map classRepositories
          A cache of attribute repositories.
private static java.util.List initList
          List used to keep track of the initialization list in getCachedRepository.
 
Constructor Summary
Attributes()
           
 
Method Summary
static java.lang.Object getAttribute(java.lang.Class clazz, java.lang.Class attributeClass)
          Get one attributes of a given type from a class.
private static java.lang.Object getAttribute(java.util.Collection attrs, java.lang.Class attributeClass)
          Selects from a collection of attributes one attribute with a given class.
static java.lang.Object getAttribute(java.lang.reflect.Constructor constructor, java.lang.Class attributeClass)
          Get one attributes of a given type from a constructor.
static java.lang.Object getAttribute(java.lang.reflect.Field field, java.lang.Class attributeClass)
          Get one attributes of a given type from a field.
static java.lang.Object getAttribute(java.lang.reflect.Method method, java.lang.Class attributeClass)
          Get one attributes of a given type from a method.
static java.util.Collection getAttributes(java.lang.Class clazz)
          Gets all attributes for a class.
static java.util.Collection getAttributes(java.lang.Class clazz, java.lang.Class attributeClass)
          Get all attributes of a given type from a class.
private static java.util.Collection getAttributes(java.util.Collection attrs, java.lang.Class attributeClass)
          Selects from a collection of attributes only those with a given class.
static java.util.Collection getAttributes(java.lang.reflect.Constructor constructor)
          Gets all attributes for a constructor.
static java.util.Collection getAttributes(java.lang.reflect.Constructor constructor, java.lang.Class attributeClass)
          Get all attributes of a given type from a constructor.
static java.util.Collection getAttributes(java.lang.reflect.Field field)
          Gets all attributes for a field.
static java.util.Collection getAttributes(java.lang.reflect.Field field, java.lang.Class attributeClass)
          Get all attributes of a given type from a field.
static java.util.Collection getAttributes(java.lang.reflect.Method method)
          Gets all attributes for a method.
static java.util.Collection getAttributes(java.lang.reflect.Method method, java.lang.Class attributeClass)
          Get all attributes of a given type from a method.
private static CachedRepository getCachedRepository(java.lang.Class clazz)
           
static java.lang.Object getParameterAttribute(java.lang.reflect.Constructor constructor, int parameter, java.lang.Class attributeClass)
          Get one attributes of a given type from a constructor's parameter.
static java.lang.Object getParameterAttribute(java.lang.reflect.Method method, int parameter, java.lang.Class attributeClass)
          Get one attributes of a given type from a parameter.
static java.util.Collection getParameterAttributes(java.lang.reflect.Constructor constructor, int parameter)
          Gets all attributes for a parameter of a constructor.
static java.util.Collection getParameterAttributes(java.lang.reflect.Constructor constructor, int parameter, java.lang.Class attributeClass)
          Get all attributes of a given type from a method's parameter.
static java.util.Collection getParameterAttributes(java.lang.reflect.Method method, int parameter)
          Gets all attributes for a parameter of a method.
static java.util.Collection getParameterAttributes(java.lang.reflect.Method method, int parameter, java.lang.Class attributeClass)
          Get all attributes of a given type from a method's parameter.
static java.lang.Object getReturnAttribute(java.lang.reflect.Method method, java.lang.Class attributeClass)
          Get one attributes of a given type from a method's return value.
static java.util.Collection getReturnAttributes(java.lang.reflect.Method method)
          Gets all attributes for the return value of a method.
static java.util.Collection getReturnAttributes(java.lang.reflect.Method method, java.lang.Class attributeClass)
          Get all attributes of a given type from a method's return value.
static boolean hasAttribute(java.lang.Class clazz, java.lang.Object attribute)
          Tests if a class has an attribute.
private static boolean hasAttribute(java.util.Collection attrs, java.lang.Object attribute)
          Convenience function to test whether a collection of attributes contain an attribute.
static boolean hasAttribute(java.lang.reflect.Constructor constructor, java.lang.Object attribute)
          Tests if a constructor has an attribute.
static boolean hasAttribute(java.lang.reflect.Field field, java.lang.Object attribute)
          Tests if a field has an attribute.
static boolean hasAttribute(java.lang.reflect.Method method, java.lang.Object attribute)
          Tests if a method has an attribute.
static boolean hasAttributeType(java.lang.Class clazz, java.lang.Class attributeClass)
          Tests if a class has an attribute of a given type.
private static boolean hasAttributeType(java.util.Collection attrs, java.lang.Class attributeClass)
          Convenience function to test whether a collection of attributes contain an attribute of a given class.
static boolean hasAttributeType(java.lang.reflect.Constructor constructor, java.lang.Class attributeClass)
          Tests if a constructor has an attribute of a given type.
static boolean hasAttributeType(java.lang.reflect.Field field, java.lang.Class attributeClass)
          Tests if a field has an attribute of a given type.
static boolean hasAttributeType(java.lang.reflect.Method method, java.lang.Class attributeClass)
          Tests if a method has an attribute of a given type.
static boolean hasParameterAttribute(java.lang.reflect.Constructor constructor, int parameter, java.lang.Object attribute)
          Tests if a constructor's parameter has an attribute.
static boolean hasParameterAttribute(java.lang.reflect.Method method, int parameter, java.lang.Object attribute)
          Tests if a method's parameter has an attribute.
static boolean hasParameterAttributeType(java.lang.reflect.Constructor constructor, int parameter, java.lang.Class attributeClass)
          Tests if a constructor's parameter has an attribute of a given type.
static boolean hasParameterAttributeType(java.lang.reflect.Method method, int parameter, java.lang.Class attributeClass)
          Tests if a method's parameter has an attribute of a given type.
static boolean hasReturnAttribute(java.lang.reflect.Method method, java.lang.Object attribute)
          Tests if a method's return value has an attribute.
static boolean hasReturnAttributeType(java.lang.reflect.Method method, java.lang.Class attributeClass)
          Tests if a method's return value has an attribute of a given type.
static void setAttributes(RuntimeAttributeRepository repo)
          Set attributes for a given class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classRepositories

private static final java.util.Map classRepositories
A cache of attribute repositories. The map used is a WeakHashMap keyed on the Class owning the attribute repository. This works because Class objects use the identity function to compare for equality - i.e. if the two classes have the same name, and are loaded from the same two ClassLoaders, then class1 == class2. Also, (class1.equals(class2)) == (class1 == class2). This means that a once a Class reference has been garbage-collected, it can't be re-created. Thus we can treat the cache map as a normal map - the only entries that will ever disappear are those we can't look up anyway because we can't ever create the key for them!

Also, this will keep the cache from growing too big in environments where classes are loaded and unloaded all the time (i.e. application servers).


initList

private static java.util.List initList
List used to keep track of the initialization list in getCachedRepository. Since the method is synchronized static, we only need one list.

Constructor Detail

Attributes

public Attributes()
Method Detail

getCachedRepository

private static CachedRepository getCachedRepository(java.lang.Class clazz)
                                             throws RepositoryError,
                                                    CircularDependencyError
Throws:
RepositoryError
CircularDependencyError

getAttribute

private static java.lang.Object getAttribute(java.util.Collection attrs,
                                             java.lang.Class attributeClass)
                                      throws MultipleAttributesError
Selects from a collection of attributes one attribute with a given class.

Parameters:
attrs - the collection of attribute instances to select from.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Returns:
the attribute instance, or null of none could be found.
Throws:
MultipleAttributesError - if the collection contains more than one instance of the specified class.

getAttribute

public static java.lang.Object getAttribute(java.lang.Class clazz,
                                            java.lang.Class attributeClass)
                                     throws RepositoryError,
                                            MultipleAttributesError
Get one attributes of a given type from a class.

Parameters:
clazz - the class. May not be null.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Returns:
the attribute instance, or null of none could be found.
Throws:
MultipleAttributesError - if the collection contains more than one instance of the specified class.
RepositoryError
Since:
2.1

getAttribute

public static java.lang.Object getAttribute(java.lang.reflect.Field field,
                                            java.lang.Class attributeClass)
                                     throws RepositoryError,
                                            MultipleAttributesError
Get one attributes of a given type from a field.

Parameters:
field - the field. May not be null.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Returns:
the attribute instance, or null of none could be found.
Throws:
MultipleAttributesError - if the collection contains more than one instance of the specified class.
RepositoryError
Since:
2.1

getAttribute

public static java.lang.Object getAttribute(java.lang.reflect.Constructor constructor,
                                            java.lang.Class attributeClass)
                                     throws RepositoryError,
                                            MultipleAttributesError
Get one attributes of a given type from a constructor.

Parameters:
constructor - the constructor. May not be null.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Returns:
the attribute instance, or null of none could be found.
Throws:
MultipleAttributesError - if the collection contains more than one instance of the specified class.
RepositoryError
Since:
2.1

getAttribute

public static java.lang.Object getAttribute(java.lang.reflect.Method method,
                                            java.lang.Class attributeClass)
                                     throws RepositoryError,
                                            MultipleAttributesError
Get one attributes of a given type from a method.

Parameters:
method - the method. May not be null.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Returns:
the attribute instance, or null of none could be found.
Throws:
MultipleAttributesError - if the collection contains more than one instance of the specified class.
RepositoryError
Since:
2.1

getParameterAttribute

public static java.lang.Object getParameterAttribute(java.lang.reflect.Method method,
                                                     int parameter,
                                                     java.lang.Class attributeClass)
                                              throws RepositoryError,
                                                     MultipleAttributesError
Get one attributes of a given type from a parameter.

Parameters:
method - the method. May not be null.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
parameter - index of the parameter in the method's parameter list.
Returns:
the attribute instance, or null of none could be found.
Throws:
MultipleAttributesError - if the collection contains more than one instance of the specified class.
ParameterIndexOutOfBoundsException - if the parameter index is < 0 or greater than the number of parameters the method accepts.
RepositoryError
Since:
2.1

getParameterAttribute

public static java.lang.Object getParameterAttribute(java.lang.reflect.Constructor constructor,
                                                     int parameter,
                                                     java.lang.Class attributeClass)
                                              throws RepositoryError,
                                                     MultipleAttributesError
Get one attributes of a given type from a constructor's parameter.

Parameters:
constructor - the constructor. May not be null.
parameter - index of the parameter in the method's parameter list.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Returns:
the attribute instance, or null of none could be found.
Throws:
MultipleAttributesError - if the collection contains more than one instance of the specified class.
ParameterIndexOutOfBoundsException - if the parameter index is < 0 or greater than the number of parameters the constructor accepts.
RepositoryError
Since:
2.1

getReturnAttribute

public static java.lang.Object getReturnAttribute(java.lang.reflect.Method method,
                                                  java.lang.Class attributeClass)
                                           throws RepositoryError,
                                                  MultipleAttributesError
Get one attributes of a given type from a method's return value.

Parameters:
method - the method. May not be null.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Returns:
the attribute instance, or null of none could be found.
Throws:
MultipleAttributesError - if the collection contains more than one instance of the specified class.
RepositoryError
Since:
2.1

getAttributes

public static java.util.Collection getAttributes(java.lang.Class clazz)
                                          throws RepositoryError
Gets all attributes for a class.

Parameters:
clazz - the class. May not be null.
Throws:
RepositoryError
Since:
2.1

getAttributes

public static java.util.Collection getAttributes(java.lang.reflect.Method method)
                                          throws RepositoryError
Gets all attributes for a method.

Parameters:
method - the method. May not be null.
Throws:
RepositoryError
Since:
2.1

getParameterAttributes

public static java.util.Collection getParameterAttributes(java.lang.reflect.Method method,
                                                          int parameter)
                                                   throws RepositoryError
Gets all attributes for a parameter of a method.

Parameters:
method - the method. May not be null.
parameter - the index of the parameter in the method's parameter list.
Throws:
ParameterIndexOutOfBoundsException - if the parameter index is < 0 or greater than the number of parameters the method accepts.
RepositoryError
Since:
2.1

getParameterAttributes

public static java.util.Collection getParameterAttributes(java.lang.reflect.Constructor constructor,
                                                          int parameter)
                                                   throws RepositoryError
Gets all attributes for a parameter of a constructor.

Parameters:
constructor - the constructor. May not be null.
parameter - the index of the parameter in the constructor's parameter list.
Throws:
ParameterIndexOutOfBoundsException - if the parameter index is < 0 or greater than the number of parameters the constructor accepts.
RepositoryError
Since:
2.1

getReturnAttributes

public static java.util.Collection getReturnAttributes(java.lang.reflect.Method method)
                                                throws RepositoryError
Gets all attributes for the return value of a method.

Parameters:
method - the method. May not be null.
Throws:
RepositoryError
Since:
2.1

getAttributes

public static java.util.Collection getAttributes(java.lang.reflect.Field field)
                                          throws RepositoryError
Gets all attributes for a field.

Parameters:
field - the field. May not be null.
Throws:
RepositoryError
Since:
2.1

getAttributes

public static java.util.Collection getAttributes(java.lang.reflect.Constructor constructor)
                                          throws RepositoryError
Gets all attributes for a constructor.

Parameters:
constructor - the constructor. May not be null.
Throws:
RepositoryError
Since:
2.1

getAttributes

private static java.util.Collection getAttributes(java.util.Collection attrs,
                                                  java.lang.Class attributeClass)
Selects from a collection of attributes only those with a given class.

Since:
2.1

getAttributes

public static java.util.Collection getAttributes(java.lang.Class clazz,
                                                 java.lang.Class attributeClass)
                                          throws RepositoryError
Get all attributes of a given type from a class. For all objects o in the returned collection, o.getClass() == attributeClass.

Parameters:
clazz - the class. May not be null.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Throws:
RepositoryError
Since:
2.1

getAttributes

public static java.util.Collection getAttributes(java.lang.reflect.Field field,
                                                 java.lang.Class attributeClass)
                                          throws RepositoryError
Get all attributes of a given type from a field. For all objects o in the returned collection, o.getClass() == attributeClass.

Parameters:
field - the field. May not be null.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Throws:
RepositoryError
Since:
2.1

getAttributes

public static java.util.Collection getAttributes(java.lang.reflect.Constructor constructor,
                                                 java.lang.Class attributeClass)
                                          throws RepositoryError
Get all attributes of a given type from a constructor. For all objects o in the returned collection, o.getClass() == attributeClass.

Parameters:
constructor - the constructor. May not be null.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Throws:
RepositoryError
Since:
2.1

getAttributes

public static java.util.Collection getAttributes(java.lang.reflect.Method method,
                                                 java.lang.Class attributeClass)
                                          throws RepositoryError
Get all attributes of a given type from a method. For all objects o in the returned collection, o.getClass() == attributeClass.

Parameters:
method - the method. May not be null.
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Throws:
RepositoryError
Since:
2.1

getParameterAttributes

public static java.util.Collection getParameterAttributes(java.lang.reflect.Method method,
                                                          int parameter,
                                                          java.lang.Class attributeClass)
                                                   throws RepositoryError
Get all attributes of a given type from a method's parameter. For all objects o in the returned collection, o.getClass() == attributeClass.

Parameters:
method - the method. May not be null.
parameter - index of the parameter in the method's parameter list
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Throws:
ParameterIndexOutOfBoundsException - if the parameter index is < 0 or greater than the number of parameters the method accepts.
RepositoryError
Since:
2.1

getParameterAttributes

public static java.util.Collection getParameterAttributes(java.lang.reflect.Constructor constructor,
                                                          int parameter,
                                                          java.lang.Class attributeClass)
                                                   throws RepositoryError
Get all attributes of a given type from a method's parameter. For all objects o in the returned collection, o.getClass() == attributeClass.

Parameters:
constructor - the constructor. May not be null.
parameter - index of the parameter in the constructor's parameter list
attributeClass - the type of attribute. May be null, but this will not match anything.
Throws:
ParameterIndexOutOfBoundsException - if the parameter index is < 0 or greater than the number of parameters the constructor accepts.
RepositoryError
Since:
2.1

getReturnAttributes

public static java.util.Collection getReturnAttributes(java.lang.reflect.Method method,
                                                       java.lang.Class attributeClass)
                                                throws RepositoryError
Get all attributes of a given type from a method's return value. For all objects o in the returned collection, o.getClass() == attributeClass.

Parameters:
method - the method
attributeClass - the type of attribute wanted. May be null, but this will not match anything.
Throws:
RepositoryError
Since:
2.1

hasAttributeType

private static boolean hasAttributeType(java.util.Collection attrs,
                                        java.lang.Class attributeClass)
Convenience function to test whether a collection of attributes contain an attribute of a given class.

Since:
2.1

hasAttributeType

public static boolean hasAttributeType(java.lang.Class clazz,
                                       java.lang.Class attributeClass)
                                throws RepositoryError
Tests if a class has an attribute of a given type. That is, is there any attribute attr such that attr.getClass() == attributeClass?

Parameters:
clazz - the class. May not be null.
attributeClass - the type of attribute. May be null, but this will not match anything.
Throws:
RepositoryError
Since:
2.1

hasAttributeType

public static boolean hasAttributeType(java.lang.reflect.Field field,
                                       java.lang.Class attributeClass)
                                throws RepositoryError
Tests if a field has an attribute of a given type. That is, is there any attribute attr such that attr.getClass() == attributeClass?

Parameters:
field - the field. May not be null.
attributeClass - the type of attribute. May be null, but this will not match anything.
Throws:
RepositoryError
Since:
2.1

hasAttributeType

public static boolean hasAttributeType(java.lang.reflect.Constructor constructor,
                                       java.lang.Class attributeClass)
                                throws RepositoryError
Tests if a constructor has an attribute of a given type. That is, is there any attribute attr such that attr.getClass() == attributeClass?

Parameters:
constructor - the constructor. May not be null.
attributeClass - the type of attribute. May be null, but this will not match anything.
Throws:
RepositoryError
Since:
2.1

hasAttributeType

public static boolean hasAttributeType(java.lang.reflect.Method method,
                                       java.lang.Class attributeClass)
                                throws RepositoryError
Tests if a method has an attribute of a given type. That is, is there any attribute attr such that attr.getClass() == attributeClass?

Parameters:
method - the method. May not be null.
attributeClass - the type of attribute. May be null, but this will not match anything.
Throws:
RepositoryError
Since:
2.1

hasParameterAttributeType

public static boolean hasParameterAttributeType(java.lang.reflect.Method method,
                                                int parameter,
                                                java.lang.Class attributeClass)
                                         throws RepositoryError
Tests if a method's parameter has an attribute of a given type. That is, is there any attribute attr such that attr.getClass() == attributeClass?

Parameters:
method - the method. May not be null.
parameter - the index of the parameter in the method's parameter list.
attributeClass - the type of attribute. May be null, but this will not match anything.
Throws:
ParameterIndexOutOfBoundsException - if the parameter index is < 0 or greater than the number of parameters the method accepts.
RepositoryError
Since:
2.1

hasParameterAttributeType

public static boolean hasParameterAttributeType(java.lang.reflect.Constructor constructor,
                                                int parameter,
                                                java.lang.Class attributeClass)
                                         throws RepositoryError
Tests if a constructor's parameter has an attribute of a given type. That is, is there any attribute attr such that attr.getClass() == attributeClass?

Parameters:
constructor - the constructor. May not be null.
parameter - the index of the parameter in the constructor's parameter list.
attributeClass - the type of attribute. May be null, but this will not match anything.
Throws:
ParameterIndexOutOfBoundsException - if the parameter index is < 0 or greater than the number of parameters the constructor accepts.
RepositoryError
Since:
2.1

hasReturnAttributeType

public static boolean hasReturnAttributeType(java.lang.reflect.Method method,
                                             java.lang.Class attributeClass)
                                      throws RepositoryError
Tests if a method's return value has an attribute of a given type. That is, is there any attribute attr such that attr.getClass() == attributeClass?

Parameters:
method - the method. May not be null.
attributeClass - the type of attribute. May be null, but this will not match anything.
Throws:
RepositoryError
Since:
2.1

hasAttribute

private static boolean hasAttribute(java.util.Collection attrs,
                                    java.lang.Object attribute)
                             throws RepositoryError
Convenience function to test whether a collection of attributes contain an attribute.

Throws:
RepositoryError
Since:
2.1

hasAttribute

public static boolean hasAttribute(java.lang.Class clazz,
                                   java.lang.Object attribute)
                            throws RepositoryError
Tests if a class has an attribute. That is, is there any attribute attr such that attr.equals(attribute)?

Parameters:
clazz - the class. May not be null.
attribute - the attribute to compare to.
Throws:
RepositoryError
Since:
2.1

hasAttribute

public static boolean hasAttribute(java.lang.reflect.Field field,
                                   java.lang.Object attribute)
                            throws RepositoryError
Tests if a field has an attribute. That is, is there any attribute attr such that attr.equals(attribute)?

Parameters:
field - the field. May not be null.
attribute - the attribute to compare to.
Throws:
RepositoryError
Since:
2.1

hasAttribute

public static boolean hasAttribute(java.lang.reflect.Constructor constructor,
                                   java.lang.Object attribute)
                            throws RepositoryError
Tests if a constructor has an attribute. That is, is there any attribute attr such that attr.equals(attribute)?

Parameters:
constructor - the constructor. May not be null.
attribute - the attribute to compare to.
Throws:
RepositoryError
Since:
2.1

hasAttribute

public static boolean hasAttribute(java.lang.reflect.Method method,
                                   java.lang.Object attribute)
                            throws RepositoryError
Tests if a method has an attribute. That is, is there any attribute attr such that attr.equals(attribute)?

Parameters:
method - the method. May not be null.
attribute - the attribute to compare to.
Throws:
RepositoryError
Since:
2.1

hasParameterAttribute

public static boolean hasParameterAttribute(java.lang.reflect.Method method,
                                            int parameter,
                                            java.lang.Object attribute)
                                     throws RepositoryError
Tests if a method's parameter has an attribute. That is, is there any attribute attr such that attr.equals(attribute)?

Parameters:
method - the method. May not be null.
parameter - the index of the parameter in the method's parameter list.
attribute - the attribute to compare to.
Throws:
ParameterIndexOutOfBoundsException - if the parameter index is < 0 or greater than the number of parameters the method accepts.
RepositoryError
Since:
2.1

hasParameterAttribute

public static boolean hasParameterAttribute(java.lang.reflect.Constructor constructor,
                                            int parameter,
                                            java.lang.Object attribute)
                                     throws RepositoryError
Tests if a constructor's parameter has an attribute. That is, is there any attribute attr such that attr.equals(attribute)?

Parameters:
constructor - the constructor. May not be null.
parameter - the index of the parameter in the constructor's parameter list.
attribute - the attribute to compare to.
Throws:
ParameterIndexOutOfBoundsException - if the parameter index is < 0 or greater than the number of parameters the constructor accepts.
RepositoryError
Since:
2.1

hasReturnAttribute

public static boolean hasReturnAttribute(java.lang.reflect.Method method,
                                         java.lang.Object attribute)
                                  throws RepositoryError
Tests if a method's return value has an attribute. That is, is there any attribute attr such that attr.equals(attribute)?

Parameters:
method - the method. May not be null.
attribute - the attribute to compare to.
Throws:
RepositoryError
Since:
2.1

setAttributes

public static void setAttributes(RuntimeAttributeRepository repo)
                          throws java.lang.IllegalStateException
Set attributes for a given class. The class must not have attributes set for it already (i.e. you can't redefine the attributes of a class at runtime). This because it really messes up the concept of inheritable attributes, and because the attribute set associated with a class is immutable, like the set of methods and fields.

Parameters:
repo - The repository. The repository will be sealed before any attributes are set. This to guarantee that the repository remains constant during setting.
Throws:
java.lang.IllegalStateException - if the class whose attributes are defined already have attributes defined for it (even if it has no attributes).
Since:
2.1