|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.attributes.RuntimeAttributeRepository
Class used to define attributes programmatically for a class. It is recommended that this class is used in the static initializer for a class:
public class RuntimeSample extends SuperSample implements SampleIFJoin {
static {
try {
RuntimeAttributeRepository rar =
new RuntimeAttributeRepository (RuntimeSample.class);
rar.addClassAttribute (new ThreadSafe ());
rar.addFieldAttribute ("field", new ThreadSafe ());
rar.addMethodAttribute ("someMethod", new Class[]{},
new Dependency ( SampleService.class, "sample-some-method1" ));
rar.addParameterAttribute ("methodWithAttributes",
new Class[]{ Integer.TYPE, Integer.TYPE }, 1,
new ThreadSafe ());
rar.addReturnAttribute ("methodWithAttributes",
new Class[]{ Integer.TYPE, Integer.TYPE },
new Dependency ( SampleService.class, "sample-return" ));
rar.addMethodAttribute ("someMethod",
new Class[]{ Integer.TYPE },
new Dependency ( SampleService.class, "sample-some-method2" ));
Attributes.setAttributes (rar);
} catch (Exception e) {
throw new Error ("Unable to set attribute information: " + e.toString ());
}
}
Constructor Summary | |
RuntimeAttributeRepository(Class clazz)
Create a new runtime repository. |
Method Summary | |
void |
addClassAttribute(Object attribute)
Adds a new attribute to the class itself. |
void |
addConstructorAttribute(Class[] parameters,
Object attribute)
Adds an attribute to a constructor. |
void |
addConstructorAttribute(Constructor c,
Object attribute)
Adds an attribute to a constructor. |
void |
addFieldAttribute(Field f,
Object attribute)
Adds an attribute to a field. |
void |
addFieldAttribute(String name,
Object attribute)
Adds an attribute to a field. |
void |
addMethodAttribute(Method m,
Object attribute)
Adds an attribute to a method. |
void |
addMethodAttribute(String name,
Class[] parameters,
Object attribute)
Adds an attribute to a method. |
void |
addParameterAttribute(Class[] parameters,
int parameterIndex,
Object attribute)
Adds an attribute to a parameter of a constructor. |
void |
addParameterAttribute(Constructor c,
int parameterIndex,
Object attribute)
Adds an attribute to a parameter of a constructor. |
void |
addParameterAttribute(Method m,
int parameterIndex,
Object attribute)
Adds an attribute to a parameter of a method. |
void |
addParameterAttribute(String name,
Class[] parameters,
int parameterIndex,
Object attribute)
Adds an attribute to a parameter of a method. |
void |
addReturnAttribute(Method m,
Object attribute)
Adds an attribute to the return value of a method. |
void |
addReturnAttribute(String name,
Class[] parameters,
Object attribute)
Adds an attribute to the return value of a method. |
Set |
getClassAttributes()
Returns a set containing all attributes (instances) associated with this class. |
Map |
getConstructorAttributes()
Returns a map with String keys and List values. |
Class |
getDefinedClass()
Gets the class this repository defines attributes for. |
Map |
getFieldAttributes()
Returns a map with String keys and Set values. |
Map |
getMethodAttributes()
Returns a map with String keys and List values. |
void |
seal()
Seals this repository. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RuntimeAttributeRepository(Class clazz)
Method Detail |
public void addClassAttribute(Object attribute)
public void addFieldAttribute(String name, Object attribute) throws NoSuchFieldException, SecurityException
NoSuchFieldException
SecurityException
public void addFieldAttribute(Field f, Object attribute)
public void addConstructorAttribute(Class[] parameters, Object attribute) throws NoSuchMethodException, SecurityException
NoSuchMethodException
SecurityException
public void addConstructorAttribute(Constructor c, Object attribute)
public void addMethodAttribute(String name, Class[] parameters, Object attribute) throws NoSuchMethodException, SecurityException
NoSuchMethodException
SecurityException
public void addMethodAttribute(Method m, Object attribute)
public void addParameterAttribute(Class[] parameters, int parameterIndex, Object attribute) throws NoSuchMethodException, SecurityException
NoSuchMethodException
SecurityException
public void addParameterAttribute(Constructor c, int parameterIndex, Object attribute)
public void addParameterAttribute(String name, Class[] parameters, int parameterIndex, Object attribute) throws NoSuchMethodException, SecurityException
NoSuchMethodException
SecurityException
public void addParameterAttribute(Method m, int parameterIndex, Object attribute)
public void addReturnAttribute(String name, Class[] parameters, Object attribute) throws NoSuchMethodException, SecurityException
NoSuchMethodException
SecurityException
public void addReturnAttribute(Method m, Object attribute)
public Class getDefinedClass()
public Set getClassAttributes()
AttributeRepositoryClass
getClassAttributes
in interface AttributeRepositoryClass
public Map getFieldAttributes()
AttributeRepositoryClass
getFieldAttributes
in interface AttributeRepositoryClass
public Map getMethodAttributes()
AttributeRepositoryClass
list.get(0) = A Set with the attributes associated with the method.
list.get(1) = A Set with the attributes associated with the method's return value.
list.get(2) = A Set with the attributes associated with the method's first parameter.
list.get(n) = A Set with the attributes associated with the method's (n - 1) th parameter.
All slots in the list must be filled, not just those where there are attributes.
Should not return any attributes of superclasses etc.
getMethodAttributes
in interface AttributeRepositoryClass
public Map getConstructorAttributes()
AttributeRepositoryClass
list.get(0) = A Set with the attributes associated with the constructor.
list.get(1) = A Set with the attributes associated with the constructor's first parameter.
list.get(n) = A Set with the attributes associated with the constructor's (n - 1) th parameter.
All slots in the list must be filled, not just those where there are attributes.
Should not return any attributes of superclasses etc.
getConstructorAttributes
in interface AttributeRepositoryClass
public void seal()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |