Commit 78df5d60 authored by Lionel Seinturier's avatar Lionel Seinturier

Support annotations defined in inherited classes (requested by Philippe.)

parent 93b11a30
......@@ -3,6 +3,7 @@ Tinfi 1.3
* fix for services and references with generic types (reported by Philippe)
* support inherited non public field injection point in component
implementations (requested by Philippe)
* support annotations defined in inherited classes (requested by Philippe)
* remove @EagerDestroy
* new @Start and @Stop annotations for triggering actions when a component is
started and stopped (requested by Philippe and Jonathan)
......
......@@ -176,12 +176,12 @@ public class ContentClassMetaData {
/*
* Retrieve the scope policy of the content class.
*/
scope = fcContentClass.getAnnotation(Scope.class);
scope = Util.getAnnotation(fcContentClass,Scope.class);
/*
* Retrieve the scope eager init policy of the content class, if any.
*/
eagerinit = fcContentClass.getAnnotation(EagerInit.class);
eagerinit = Util.getAnnotation(fcContentClass,EagerInit.class);
if( eagerinit != null ) {
if( scope==null || !scope.value().equals("COMPOSITE") ) {
String msg =
......@@ -194,7 +194,8 @@ public class ContentClassMetaData {
/*
* Retrieve the conversation attributes of the content class.
*/
convattr = fcContentClass.getAnnotation(ConversationAttributes.class);
convattr =
Util.getAnnotation(fcContentClass,ConversationAttributes.class);
if( convattr != null ) {
String ma = convattr.maxAge();
convMaxAge = convDurationToMilli(ma);
......
......@@ -30,10 +30,8 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
......@@ -41,11 +39,6 @@ import org.objectweb.fractal.juliac.runtime.ClassLoaderFcItf;
import org.objectweb.fractal.juliac.runtime.ClassLoaderItf;
import org.objectweb.fractal.juliac.runtime.Juliac;
import org.ow2.frascati.tinfi.TinfiRuntimeException;
import org.ow2.frascati.tinfi.reflect.AnnotatedElementFilter;
import org.ow2.frascati.tinfi.reflect.Filter;
import org.ow2.frascati.tinfi.reflect.Filters;
import org.ow2.frascati.tinfi.reflect.SetterMethodFilter;
import org.ow2.frascati.tinfi.reflect.UnAnnotatedElementFilter;
/**
* Utility methods.
......@@ -111,26 +104,14 @@ public class Util {
}
/**
* Return all fields, declared ones whatever their access modifier is and
* inherited public ones, in the specified class.
* Return all fields declared by the specified class and all fields declared
* by parent classes, except {@link java.lang.Object}, of the specified
* class. All fields are included whatever their access modifier is.
*
* @param cl the class
* @since 1.1.2
*/
private static Field[] getAllFields( Class<?> cl ) {
/*
* Declared private to avoid regressions due to a change in the
* semantics of the method. This method used to return declared and
* public inherited fields. Since 1.3, this method returns all fields.
*
* This method is used by getAllAnnotatedSettersAndFields().
*
* We can move back this method to public as soon as we are sure that
* it is not used in other locations than the previous one where the
* change could introduce regressions.
*/
public static Field[] getAllFields( Class<?> cl ) {
List<Field> result = new ArrayList<Field>();
addAllFields(cl,result);
return result.toArray(new Field[result.size()]);
......@@ -162,34 +143,43 @@ public class Util {
}
/**
* Return all methods, declared ones whatever their access modifier is and
* inherited public ones, in the specified class.
* Return all methods declared by the specified class and all methods
* declared by parent classes, except {@link java.lang.Object}, of the
* specified class. All methods are included whatever their access modifier
* is.
*
* @param cl the class
* @since 1.1.2
*/
public static Method[] getAllMethods( Class<?> cl ) {
/*
* Use a set instead to accomodate duplicate insertions of public
* declared elements, e.g. public methods which are returned both by
* getDeclaredMethods and getMethods.
*/
Set<Method> result = new HashSet<Method>();
List<Method> result = new ArrayList<Method>();
addAllMethods(cl,result);
return result.toArray(new Method[result.size()]);
}
/**
* Add to the specified list, all methods declared by the specified class
* and all methods declared by parent classes, except {@link
* java.lang.Object}, of the specified class. All methods are included
* whatever their access modifier is.
*
* @param cl the class
* @param list the list where methods are to be added
* @since 1.3
*/
public static void addAllMethods( Class<?> cl, List<Method> list ) {
// Declared methods
Method[] methods = cl.getDeclaredMethods();
for (Method method : methods) {
result.add(method);
}
// Inherited public methods
methods = cl.getMethods();
for (Method method : methods) {
result.add(method);
list.add(method);
}
return result.toArray(new Method[result.size()]);
// Recurse in the parent class up to java.lang.Object
Class<?> supercl = cl.getSuperclass();
if( ! supercl.equals(Object.class) ) {
addAllMethods(supercl,list);
}
}
/**
......@@ -224,6 +214,31 @@ public class Util {
return aos;
}
/**
* Return the annotation of type <code>annotationClass</code> associated
* with <code>cl</code>. If no such annotation exists, recurse into the
* inheritance hierarchy up to {@link java.lang.Object}. Return
* <code>null</code> if no such annotation is found.
*/
public static <A extends Annotation> A getAnnotation(
Class<?> cl, Class<A> annotationClass ) {
A annot = cl.getAnnotation(annotationClass);
if( annot != null ) {
return annot;
}
// Recurse in the parent class up to java.lang.Object
Class<?> supercl = cl.getSuperclass();
if( ! supercl.equals(Object.class) ) {
annot = getAnnotation(supercl,annotationClass);
return annot;
}
// No such annotation found
return null;
}
/**
* Return the getter method corresponding to the specified setter.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment