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 ());
}
}
classAttributes
private final Set classAttributes
clazz
private final Class clazz
Class we are defining attributes for.
constructorAttributes
private final Map constructorAttributes
fieldAttributes
private final Map fieldAttributes
methodAttributes
private final Map methodAttributes
sealed
private boolean sealed
Flag indicating whether this repository is modifiable.
Once sealed, a repository can't be un-sealed.
syncLock
private final Object syncLock
Synchronization lock for sealing the repository. We use this instead of
synchronizing on the instance (this), since the sync:ing was added
in 2.2 and we don't want to break any code.
addClassAttribute
public void addClassAttribute(Object attribute)
Adds a new attribute to the class itself.
addConstructorAttribute
public void addConstructorAttribute(Class[] parameters,
Object attribute)
throws NoSuchMethodException,
SecurityException
Adds an attribute to a constructor. The constructor is obtained via the getDeclaredConstrutor method
of the class this repository defines.
addConstructorAttribute
public void addConstructorAttribute(Constructor c,
Object attribute)
Adds an attribute to a constructor.
addFieldAttribute
public void addFieldAttribute(Field f,
Object attribute)
Adds an attribute to a field.
addFieldAttribute
public void addFieldAttribute(String name,
Object attribute)
throws NoSuchFieldException,
SecurityException
Adds an attribute to a field.
addMethodAttribute
public void addMethodAttribute(Method m,
Object attribute)
Adds an attribute to a method.
addMethodAttribute
public void addMethodAttribute(String name,
Class[] parameters,
Object attribute)
throws NoSuchMethodException,
SecurityException
Adds an attribute to a method. The method is obtained via the getDeclaredMethod method
of the class this repository defines.
addParameterAttribute
public void addParameterAttribute(Class[] parameters,
int parameterIndex,
Object attribute)
throws NoSuchMethodException,
SecurityException
Adds an attribute to a parameter of a constructor. The constructor is obtained via the getDeclaredConstrutor method
of the class this repository defines.
addParameterAttribute
public void addParameterAttribute(Constructor c,
int parameterIndex,
Object attribute)
Adds an attribute to a parameter of a constructor.
addParameterAttribute
public void addParameterAttribute(Method m,
int parameterIndex,
Object attribute)
Adds an attribute to a parameter of a method. The method is obtained via the getDeclaredMethod method
of the class this repository defines.
addParameterAttribute
public void addParameterAttribute(String name,
Class[] parameters,
int parameterIndex,
Object attribute)
throws NoSuchMethodException,
SecurityException
Adds an attribute to a parameter of a method. The method is obtained via the getDeclaredMethod method
of the class this repository defines.
addReturnAttribute
public void addReturnAttribute(Method m,
Object attribute)
Adds an attribute to the return value of a method. The method is obtained via the getDeclaredMethod method
of the class this repository defines.
addReturnAttribute
public void addReturnAttribute(String name,
Class[] parameters,
Object attribute)
throws NoSuchMethodException,
SecurityException
Adds an attribute to the return value of a method. The method is obtained via the getDeclaredMethod method
of the class this repository defines.
checkSealed
private void checkSealed()
throws IllegalStateException
Convenience function to check if the repository is sealed.
getConstructorAttributeBundle
private List getConstructorAttributeBundle(Constructor c)
Convenience method to get and initialize an entry in the constructor map.
getDefinedClass
public Class getDefinedClass()
Gets the class this repository defines attributes for.
getMethodAttributeBundle
private List getMethodAttributeBundle(Method m)
Convenience method to get and initialize an entry in the method map.
getMethodOrConstructorAttributeBundle
private List getMethodOrConstructorAttributeBundle(Map map,
String signature,
int numSlots)
Convenience method to get and initialize an enry in the method or
constructor attribute map.
seal
public void seal()
Seals this repository. A sealed repository can't be modified.