org.apache.commons.attributes
public class RuntimeAttributeRepository extends java.lang.Object implements AttributeRepositoryClass
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 ());
}
}
Modifier and Type | Field and Description |
---|---|
private java.util.Set |
classAttributes
Set of class attributes.
|
private java.lang.Class |
clazz
Class we are defining attributes for.
|
private java.util.Map |
constructorAttributes
Set of ctor attributes.
|
private java.util.Map |
fieldAttributes
Set of field attributes.
|
private java.util.Map |
methodAttributes
Set of method attributes.
|
private boolean |
sealed
Flag indicating whether this repository is modifiable.
|
private java.lang.Object |
syncLock
Synchronization lock for sealing the repository.
|
Constructor and Description |
---|
RuntimeAttributeRepository(java.lang.Class clazz)
Create a new runtime repository.
|
Modifier and Type | Method and Description |
---|---|
void |
addClassAttribute(java.lang.Object attribute)
Adds a new attribute to the class itself.
|
void |
addConstructorAttribute(java.lang.Class[] parameters,
java.lang.Object attribute)
Adds an attribute to a constructor.
|
void |
addConstructorAttribute(java.lang.reflect.Constructor c,
java.lang.Object attribute)
Adds an attribute to a constructor.
|
void |
addFieldAttribute(java.lang.reflect.Field f,
java.lang.Object attribute)
Adds an attribute to a field.
|
void |
addFieldAttribute(java.lang.String name,
java.lang.Object attribute)
Adds an attribute to a field.
|
void |
addMethodAttribute(java.lang.reflect.Method m,
java.lang.Object attribute)
Adds an attribute to a method.
|
void |
addMethodAttribute(java.lang.String name,
java.lang.Class[] parameters,
java.lang.Object attribute)
Adds an attribute to a method.
|
void |
addParameterAttribute(java.lang.Class[] parameters,
int parameterIndex,
java.lang.Object attribute)
Adds an attribute to a parameter of a constructor.
|
void |
addParameterAttribute(java.lang.reflect.Constructor c,
int parameterIndex,
java.lang.Object attribute)
Adds an attribute to a parameter of a constructor.
|
void |
addParameterAttribute(java.lang.reflect.Method m,
int parameterIndex,
java.lang.Object attribute)
Adds an attribute to a parameter of a method.
|
void |
addParameterAttribute(java.lang.String name,
java.lang.Class[] parameters,
int parameterIndex,
java.lang.Object attribute)
Adds an attribute to a parameter of a method.
|
void |
addReturnAttribute(java.lang.reflect.Method m,
java.lang.Object attribute)
Adds an attribute to the return value of a method.
|
void |
addReturnAttribute(java.lang.String name,
java.lang.Class[] parameters,
java.lang.Object attribute)
Adds an attribute to the return value of a method.
|
private void |
checkSealed()
Convenience function to check if the repository is sealed.
|
java.util.Set |
getClassAttributes()
Returns a set containing all attributes (instances) associated with this class.
|
private java.util.List |
getConstructorAttributeBundle(java.lang.reflect.Constructor c)
Convenience method to get and initialize an entry in the constructor map.
|
java.util.Map |
getConstructorAttributes()
Returns a map with String keys and List values.
|
java.lang.Class |
getDefinedClass()
Gets the class this repository defines attributes for.
|
java.util.Map |
getFieldAttributes()
Returns a map with String keys and Set values.
|
private java.util.List |
getMethodAttributeBundle(java.lang.reflect.Method m)
Convenience method to get and initialize an entry in the method map.
|
java.util.Map |
getMethodAttributes()
Returns a map with String keys and List values.
|
private java.util.List |
getMethodOrConstructorAttributeBundle(java.util.Map map,
java.lang.String signature,
int numSlots)
Convenience method to get and initialize an enry in the method or
constructor attribute map.
|
void |
seal()
Seals this repository.
|
private volatile boolean sealed
private final java.util.Set classAttributes
AttributeRepositoryClass
for structure.private final java.util.Map fieldAttributes
AttributeRepositoryClass
for structure.private final java.util.Map constructorAttributes
AttributeRepositoryClass
for structure.private final java.util.Map methodAttributes
AttributeRepositoryClass
for structure.private final java.lang.Class clazz
private final java.lang.Object syncLock
public RuntimeAttributeRepository(java.lang.Class clazz)
public void addClassAttribute(java.lang.Object attribute)
private void checkSealed() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if sealedprivate java.util.List getMethodOrConstructorAttributeBundle(java.util.Map map, java.lang.String signature, int numSlots)
private java.util.List getMethodAttributeBundle(java.lang.reflect.Method m)
AttributeRepositoryClass
interface)
for the given method.private java.util.List getConstructorAttributeBundle(java.lang.reflect.Constructor c)
AttributeRepositoryClass
interface)
for the given constructor.public void addFieldAttribute(java.lang.String name, java.lang.Object attribute) throws java.lang.NoSuchFieldException, java.lang.SecurityException
java.lang.NoSuchFieldException
java.lang.SecurityException
public void addFieldAttribute(java.lang.reflect.Field f, java.lang.Object attribute)
public void addConstructorAttribute(java.lang.Class[] parameters, java.lang.Object attribute) throws java.lang.NoSuchMethodException, java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.SecurityException
public void addConstructorAttribute(java.lang.reflect.Constructor c, java.lang.Object attribute)
public void addMethodAttribute(java.lang.String name, java.lang.Class[] parameters, java.lang.Object attribute) throws java.lang.NoSuchMethodException, java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.SecurityException
public void addMethodAttribute(java.lang.reflect.Method m, java.lang.Object attribute)
public void addParameterAttribute(java.lang.Class[] parameters, int parameterIndex, java.lang.Object attribute) throws java.lang.NoSuchMethodException, java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.SecurityException
public void addParameterAttribute(java.lang.reflect.Constructor c, int parameterIndex, java.lang.Object attribute)
public void addParameterAttribute(java.lang.String name, java.lang.Class[] parameters, int parameterIndex, java.lang.Object attribute) throws java.lang.NoSuchMethodException, java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.SecurityException
public void addParameterAttribute(java.lang.reflect.Method m, int parameterIndex, java.lang.Object attribute)
public void addReturnAttribute(java.lang.String name, java.lang.Class[] parameters, java.lang.Object attribute) throws java.lang.NoSuchMethodException, java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.SecurityException
public void addReturnAttribute(java.lang.reflect.Method m, java.lang.Object attribute)
public java.lang.Class getDefinedClass()
public java.util.Set getClassAttributes()
AttributeRepositoryClass
getClassAttributes
in interface AttributeRepositoryClass
public java.util.Map getFieldAttributes()
AttributeRepositoryClass
getFieldAttributes
in interface AttributeRepositoryClass
public java.util.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 java.util.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()