org.apache.commons.attributes
Class RuntimeAttributeRepository

java.lang.Object
  extended byorg.apache.commons.attributes.RuntimeAttributeRepository
All Implemented Interfaces:
AttributeRepositoryClass

public class RuntimeAttributeRepository
extends Object
implements AttributeRepositoryClass

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 ());
         }
     }
 

Since:
2.1

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

RuntimeAttributeRepository

public RuntimeAttributeRepository(Class clazz)
Create a new runtime repository.

Since:
2.1
Method Detail

addClassAttribute

public void addClassAttribute(Object attribute)
Adds a new attribute to the class itself.

Since:
2.1

addFieldAttribute

public void addFieldAttribute(String name,
                              Object attribute)
                       throws NoSuchFieldException,
                              SecurityException
Adds an attribute to a field.

Throws:
NoSuchFieldException
SecurityException
Since:
2.1

addFieldAttribute

public void addFieldAttribute(Field f,
                              Object attribute)
Adds an attribute to a field.

Since:
2.1

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.

Throws:
NoSuchMethodException
SecurityException
Since:
2.1

addConstructorAttribute

public void addConstructorAttribute(Constructor c,
                                    Object attribute)
Adds an attribute to a constructor.

Since:
2.1

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.

Throws:
NoSuchMethodException
SecurityException
Since:
2.1

addMethodAttribute

public void addMethodAttribute(Method m,
                               Object attribute)
Adds an attribute to a method.

Since:
2.1

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.

Throws:
NoSuchMethodException
SecurityException
Since:
2.1

addParameterAttribute

public void addParameterAttribute(Constructor c,
                                  int parameterIndex,
                                  Object attribute)
Adds an attribute to a parameter of a constructor.

Since:
2.1

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.

Throws:
NoSuchMethodException
SecurityException
Since:
2.1

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.

Since:
2.1

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.

Throws:
NoSuchMethodException
SecurityException
Since:
2.1

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.

Since:
2.1

getDefinedClass

public Class getDefinedClass()
Gets the class this repository defines attributes for.

Since:
2.1

getClassAttributes

public Set getClassAttributes()
Description copied from interface: AttributeRepositoryClass
Returns a set containing all attributes (instances) associated with this class. Should not return any attributes of superclasses etc.

Specified by:
getClassAttributes in interface AttributeRepositoryClass

getFieldAttributes

public Map getFieldAttributes()
Description copied from interface: AttributeRepositoryClass
Returns a map with String keys and Set values. The keys correspond to field names, and their associated Set values are the set of all attributes (instances) associated with that field. Should not return any attributes of superclasses etc.

Specified by:
getFieldAttributes in interface AttributeRepositoryClass

getMethodAttributes

public Map getMethodAttributes()
Description copied from interface: AttributeRepositoryClass
Returns a map with String keys and List values. The keys correspond to method signatures, given by get Util.getSignature method, and the lists are as follows:

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.

Specified by:
getMethodAttributes in interface AttributeRepositoryClass

getConstructorAttributes

public Map getConstructorAttributes()
Description copied from interface: AttributeRepositoryClass
Returns a map with String keys and List values. The keys correspond to constructor signatures, given by get Util.getSignature method, and the lists are as follows:

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.

Specified by:
getConstructorAttributes in interface AttributeRepositoryClass

seal

public void seal()
Seals this repository. A sealed repository can't be modified.

Since:
2.1


Copyright © The Apache Software Foundation. All Rights Reserved.