|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.attributes.Attributes
API for accessing attributes.
RepositoryError
or subclasses thereof.
This Error is thrown if an attribute repository can not be loaded for some Exceptional
reason.
Error
s instead of Exception
s.
This rationale behind this is that:
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.
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 ctor,
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 cons)
Gets all attributes for a constructor. |
static java.util.Collection |
getAttributes(java.lang.reflect.Constructor ctor,
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 ctor,
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 ctor,
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 |
private static final java.util.Map classRepositories
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).
private static java.util.List initList
Constructor Detail |
public Attributes()
Method Detail |
private static CachedRepository getCachedRepository(java.lang.Class clazz) throws RepositoryError, CircularDependencyError
RepositoryError
CircularDependencyError
private static java.lang.Object getAttribute(java.util.Collection attrs, java.lang.Class attributeClass) throws MultipleAttributesError
MultipleAttributesError
- if the collection contains more than one
instance of the specified class.public static java.lang.Object getAttribute(java.lang.Class clazz, java.lang.Class attributeClass) throws RepositoryError, MultipleAttributesError
MultipleAttributesError
- if the collection contains more than one
instance of the specified class.
RepositoryError
public static java.lang.Object getAttribute(java.lang.reflect.Field field, java.lang.Class attributeClass) throws RepositoryError, MultipleAttributesError
MultipleAttributesError
- if the collection contains more than one
instance of the specified class.
RepositoryError
public static java.lang.Object getAttribute(java.lang.reflect.Constructor ctor, java.lang.Class attributeClass) throws RepositoryError, MultipleAttributesError
MultipleAttributesError
- if the collection contains more than one
instance of the specified class.
RepositoryError
public static java.lang.Object getAttribute(java.lang.reflect.Method method, java.lang.Class attributeClass) throws RepositoryError, MultipleAttributesError
MultipleAttributesError
- if the collection contains more than one
instance of the specified class.
RepositoryError
public static java.lang.Object getParameterAttribute(java.lang.reflect.Method method, int parameter, java.lang.Class attributeClass) throws RepositoryError, MultipleAttributesError
MultipleAttributesError
- if the collection contains more than one
instance of the specified class.
RepositoryError
public static java.lang.Object getParameterAttribute(java.lang.reflect.Constructor constructor, int parameter, java.lang.Class attributeClass) throws RepositoryError, MultipleAttributesError
MultipleAttributesError
- if the collection contains more than one
instance of the specified class.
RepositoryError
public static java.lang.Object getReturnAttribute(java.lang.reflect.Method method, java.lang.Class attributeClass) throws RepositoryError, MultipleAttributesError
MultipleAttributesError
- if the collection contains more than one
instance of the specified class.
RepositoryError
public static java.util.Collection getAttributes(java.lang.Class clazz) throws RepositoryError
RepositoryError
public static java.util.Collection getAttributes(java.lang.reflect.Method method) throws RepositoryError
RepositoryError
public static java.util.Collection getParameterAttributes(java.lang.reflect.Method method, int parameter) throws RepositoryError
RepositoryError
public static java.util.Collection getParameterAttributes(java.lang.reflect.Constructor constructor, int parameter) throws RepositoryError
RepositoryError
public static java.util.Collection getReturnAttributes(java.lang.reflect.Method method) throws RepositoryError
RepositoryError
public static java.util.Collection getAttributes(java.lang.reflect.Field field) throws RepositoryError
RepositoryError
public static java.util.Collection getAttributes(java.lang.reflect.Constructor cons) throws RepositoryError
RepositoryError
private static java.util.Collection getAttributes(java.util.Collection attrs, java.lang.Class attributeClass)
public static java.util.Collection getAttributes(java.lang.Class clazz, java.lang.Class attributeClass) throws RepositoryError
o.getClass() == attributeClass
.
RepositoryError
public static java.util.Collection getAttributes(java.lang.reflect.Field field, java.lang.Class attributeClass) throws RepositoryError
o.getClass() == attributeClass
.
RepositoryError
public static java.util.Collection getAttributes(java.lang.reflect.Constructor ctor, java.lang.Class attributeClass) throws RepositoryError
o.getClass() == attributeClass
.
RepositoryError
public static java.util.Collection getAttributes(java.lang.reflect.Method method, java.lang.Class attributeClass) throws RepositoryError
o.getClass() == attributeClass
.
RepositoryError
public static java.util.Collection getParameterAttributes(java.lang.reflect.Method method, int parameter, java.lang.Class attributeClass) throws RepositoryError
o.getClass() == attributeClass
.
RepositoryError
public static java.util.Collection getParameterAttributes(java.lang.reflect.Constructor constructor, int parameter, java.lang.Class attributeClass) throws RepositoryError
o.getClass() == attributeClass
.
RepositoryError
public static java.util.Collection getReturnAttributes(java.lang.reflect.Method method, java.lang.Class attributeClass) throws RepositoryError
o.getClass() == attributeClass
.
RepositoryError
private static boolean hasAttributeType(java.util.Collection attrs, java.lang.Class attributeClass)
public static boolean hasAttributeType(java.lang.Class clazz, java.lang.Class attributeClass) throws RepositoryError
attr
such that attr.getClass() == attributeClass
?
RepositoryError
public static boolean hasAttributeType(java.lang.reflect.Field field, java.lang.Class attributeClass) throws RepositoryError
attr
such that attr.getClass() == attributeClass
?
RepositoryError
public static boolean hasAttributeType(java.lang.reflect.Constructor ctor, java.lang.Class attributeClass) throws RepositoryError
attr
such that attr.getClass() == attributeClass
?
RepositoryError
public static boolean hasAttributeType(java.lang.reflect.Method method, java.lang.Class attributeClass) throws RepositoryError
attr
such that attr.getClass() == attributeClass
?
RepositoryError
public static boolean hasParameterAttributeType(java.lang.reflect.Method method, int parameter, java.lang.Class attributeClass) throws RepositoryError
attr
such that attr.getClass() == attributeClass
?
RepositoryError
public static boolean hasParameterAttributeType(java.lang.reflect.Constructor constructor, int parameter, java.lang.Class attributeClass) throws RepositoryError
attr
such that attr.getClass() == attributeClass
?
RepositoryError
public static boolean hasReturnAttributeType(java.lang.reflect.Method method, java.lang.Class attributeClass) throws RepositoryError
attr
such that attr.getClass() == attributeClass
?
RepositoryError
private static boolean hasAttribute(java.util.Collection attrs, java.lang.Object attribute) throws RepositoryError
RepositoryError
public static boolean hasAttribute(java.lang.Class clazz, java.lang.Object attribute) throws RepositoryError
attr
such that attr.equals(attribute)
?
RepositoryError
public static boolean hasAttribute(java.lang.reflect.Field field, java.lang.Object attribute) throws RepositoryError
attr
such that attr.equals(attribute)
?
RepositoryError
public static boolean hasAttribute(java.lang.reflect.Constructor ctor, java.lang.Object attribute) throws RepositoryError
attr
such that attr.equals(attribute)
?
RepositoryError
public static boolean hasAttribute(java.lang.reflect.Method method, java.lang.Object attribute) throws RepositoryError
attr
such that attr.equals(attribute)
?
RepositoryError
public static boolean hasParameterAttribute(java.lang.reflect.Method method, int parameter, java.lang.Object attribute) throws RepositoryError
attr
such that attr.equals(attribute)
?
RepositoryError
public static boolean hasParameterAttribute(java.lang.reflect.Constructor constructor, int parameter, java.lang.Object attribute) throws RepositoryError
attr
such that attr.equals(attribute)
?
RepositoryError
public static boolean hasReturnAttribute(java.lang.reflect.Method method, java.lang.Object attribute) throws RepositoryError
attr
such that attr.equals(attribute)
?
RepositoryError
public static void setAttributes(RuntimeAttributeRepository repo) throws java.lang.IllegalStateException
repo
- The repository. The repository will be sealed before any attributes are
set. This to guarantee that the repository remains constant
during setting.
java.lang.IllegalStateException
- if the class whose attributes are defined already have
attributes defined for it (even if it has no attributes).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |