[jboss-cvs] aop-mc-int/src/main/org/jboss/aop/microcontainer/integration ...
Kabir Khan
kkhan at jboss.com
Tue Jul 11 09:36:38 EDT 2006
User: kkhan
Date: 06/07/11 09:36:38
Modified: src/main/org/jboss/aop/microcontainer/integration
AOPDependencyBuilder.java
Log:
[JBAOP-239] Tests for dependencies coming from nested annotations on class
Revision Changes Path
1.12 +104 -19 aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPDependencyBuilder.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AOPDependencyBuilder.java
===================================================================
RCS file: /cvsroot/jboss/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPDependencyBuilder.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- AOPDependencyBuilder.java 5 Jul 2006 16:33:56 -0000 1.11
+++ AOPDependencyBuilder.java 11 Jul 2006 13:36:37 -0000 1.12
@@ -42,11 +42,16 @@
import org.jboss.classadapter.spi.Dependency;
import org.jboss.reflect.plugins.AnnotationValueFactory;
import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactoryImpl;
+import org.jboss.reflect.spi.AnnotationAttribute;
import org.jboss.reflect.spi.AnnotationInfo;
import org.jboss.reflect.spi.AnnotationValue;
+import org.jboss.reflect.spi.ArrayInfo;
+import org.jboss.reflect.spi.ArrayValue;
import org.jboss.reflect.spi.ClassInfo;
import org.jboss.reflect.spi.MethodInfo;
import org.jboss.reflect.spi.StringValue;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.Value;
import org.jboss.repository.spi.MetaDataContext;
/**
@@ -54,7 +59,7 @@
* @todo document this class
* @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
* @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public class AOPDependencyBuilder extends AbstractDependencyBuilder
{
@@ -138,23 +143,24 @@
private void getClassAnnotationDependencies(ClassInfo classInfo, MetaDataContext metaDataContext, HashSet<Object> dependencies) throws Exception
{
- HashMap<String, Object> dependencyMap = new HashMap<String, Object>();
- getRealClassAnnotationDependencies(classInfo, dependencyMap);
- getMetaDataContextClassAnnotationDependencies(metaDataContext, dependencyMap);
- dependencies.addAll(dependencyMap.values());
+ HashMap<String, ArrayList<String>> realMap = new HashMap<String, ArrayList<String>>();
+ getRealClassAnnotationDependencies(classInfo, realMap);
+ HashMap<String, ArrayList<String>> metaMap = new HashMap<String, ArrayList<String>>();
+ getMetaDataContextClassAnnotationDependencies(metaDataContext, metaMap);
+ addAllDependenciesToSet(dependencies, realMap, metaMap);
}
- private void getRealClassAnnotationDependencies(ClassInfo classInfo, HashMap<String, Object> dependencies) throws Exception
+ private void getRealClassAnnotationDependencies(ClassInfo classInfo, HashMap<String, ArrayList<String>> dependencies) throws Exception
{
AnnotationValue[] annotations = classInfo.getAnnotations();
for (int i = 0 ; i < annotations.length ; i++)
{
- getDependenciesForAnnotation(annotations[i], dependencies);
+ getDependenciesForAnnotation(annotations[i].getType().getName(), annotations[i], dependencies);
}
}
- private void getMetaDataContextClassAnnotationDependencies(MetaDataContext metaDataContext, HashMap<String, Object> dependencies) throws Exception
+ private void getMetaDataContextClassAnnotationDependencies(MetaDataContext metaDataContext, HashMap<String, ArrayList<String>> dependencies) throws Exception
{
if (metaDataContext != null)
{
@@ -176,28 +182,29 @@
MethodInfo method = (MethodInfo)it.next();
if (Advisable.isAdvisableMethod(method.getModifiers(), method.getName()))
{
- HashMap<String, Object> dependencyMap = new HashMap<String, Object>();
- getRealMethodAnnotationDependencies(method, dependencyMap);
- getMetaDataContextMethodAnnotationDependencies(method.getName(), metaDataContext, dependencyMap);
- dependencies.addAll(dependencyMap.values());
+ HashMap<String, ArrayList<String>> classMap = new HashMap<String, ArrayList<String>>();
+ getRealMethodAnnotationDependencies(method, classMap);
+ HashMap<String, ArrayList<String>> overrideMap = new HashMap<String, ArrayList<String>>();
+ getMetaDataContextMethodAnnotationDependencies(method.getName(), metaDataContext, overrideMap);
+ addAllDependenciesToSet(dependencies, classMap, overrideMap);
}
}
}
}
- private void getRealMethodAnnotationDependencies(MethodInfo methodInfo, HashMap<String, Object> dependencies) throws Exception
+ private void getRealMethodAnnotationDependencies(MethodInfo methodInfo, HashMap<String, ArrayList<String>> dependencies) throws Exception
{
AnnotationValue[] annotations = methodInfo.getAnnotations();
if (annotations != null)
{
for (int i = 0 ; i < annotations.length ; i++)
{
- getDependenciesForAnnotation(annotations[i], dependencies);
+ getDependenciesForAnnotation(annotations[i].getType().getName(), annotations[i], dependencies);
}
}
}
- private void getMetaDataContextMethodAnnotationDependencies(String methodName, MetaDataContext metaDataContext, HashMap<String, Object> dependencies) throws Exception
+ private void getMetaDataContextMethodAnnotationDependencies(String methodName, MetaDataContext metaDataContext, HashMap<String, ArrayList<String>> dependencies) throws Exception
{
if (metaDataContext != null)
{
@@ -210,7 +217,7 @@
}
}
- private void getDependenciesForMetaDataAnnotation(Object annotation, HashMap<String, Object> dependencies) throws Exception
+ private void getDependenciesForMetaDataAnnotation(Object annotation, HashMap<String, ArrayList<String>> dependencies) throws Exception
{
AnnotationInfo info;
Class clazz = annotation.getClass().getInterfaces()[0];
@@ -224,13 +231,15 @@
throw new RuntimeException("Error creating annotation for " + clazz.getName(), e);
}
AnnotationValue value = AnnotationValueFactory.createAnnotationValue(typeInfoFactory, typeInfoFactory, info, annotation);
- getDependenciesForAnnotation(value, dependencies);
+ getDependenciesForAnnotation(info.getType().getName(), value, dependencies);
}
- private void getDependenciesForAnnotation(AnnotationValue annotation, HashMap<String, Object> dependencies)
+ private void getDependenciesForAnnotation(String topLevelAnnotationName, AnnotationValue annotation, HashMap<String, ArrayList<String>> dependencies)
{
if (annotation != null)
{
+ addAnnotationAttributeDependencies(topLevelAnnotationName, annotation, dependencies);
+
AnnotationValue[] annotationAnnotations = annotation.getAnnotationType().getAnnotations();
for (int i = 0 ; i < annotationAnnotations.length ; i++)
{
@@ -238,9 +247,85 @@
{
StringValue value = (StringValue)annotationAnnotations[i].getValue(DEPENDENCY_NAME_ATTRIBUTE);
StringValue dependency = (StringValue)annotation.getValue(value.getValue());
- dependencies.put(annotation.getAnnotationType().getName(), dependency.getValue());
+ addDependency(topLevelAnnotationName, dependency, dependencies);
+ }
+ }
+ }
+ }
+
+ private void addAnnotationAttributeDependencies(String topLevelAnnotationName, AnnotationValue annotation, HashMap<String, ArrayList<String>> dependencies)
+ {
+ MethodInfo[] attributes = annotation.getAnnotationType().getDeclaredMethods();
+ if (attributes != null)
+ {
+ for (int i = 0 ; i < attributes.length ; i++)
+ {
+ Value value = annotation.getValue(attributes[i].getName());
+
+ if (value instanceof AnnotationValue)
+ {
+ getDependenciesForAnnotation(topLevelAnnotationName, (AnnotationValue)value, dependencies);
+ }
+ else if (value instanceof ArrayValue)
+ {
+ ArrayValue arrVal = (ArrayValue)value;
+ TypeInfo type = ((ArrayInfo)arrVal.getType()).getComponentType();
+ if (type instanceof AnnotationInfo)
+ {
+ Value[] values = arrVal.getValues();
+ for (int j = 0 ; j < values.length ; j++)
+ {
+ getDependenciesForAnnotation(topLevelAnnotationName, (AnnotationValue)values[j], dependencies);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void addDependency(String topLevelAnnotationName, StringValue dependency, HashMap<String, ArrayList<String>> dependencies)
+ {
+ ArrayList<String> list = dependencies.get(topLevelAnnotationName);
+ if (list == null)
+ {
+ list = new ArrayList<String>();
+ dependencies.put(topLevelAnnotationName, list);
+ }
+
+ list.add(dependency.getValue());
+ }
+
+ private void addAllDependenciesToSet(HashSet<Object> dependencies, HashMap<String, ArrayList<String>> classMap, HashMap<String, ArrayList<String>> overrideMap)
+ {
+ HashMap<String, ArrayList<String>> dependencyMap = mergeClassAndOverrideMaps(classMap, overrideMap);
+ if (dependencyMap.size() > 0)
+ {
+ for (ArrayList<String> deps : dependencyMap.values())
+ {
+ dependencies.addAll(deps);
+ }
}
}
+
+ private HashMap<String, ArrayList<String>> mergeClassAndOverrideMaps(HashMap<String, ArrayList<String>> classMap, HashMap<String, ArrayList<String>> overrideMap)
+ {
+ if (classMap.size() == 0 && overrideMap.size() == 0)
+ {
+ return classMap;
+ }
+ if (classMap.size() > 0 && overrideMap.size() == 0)
+ {
+ return classMap;
+ }
+ if (classMap.size() == 0 && overrideMap.size() > 0)
+ {
+ return overrideMap;
+ }
+
+ for (String key : overrideMap.keySet())
+ {
+ classMap.put(key, overrideMap.get(key));
}
+ return classMap;
}
}
More information about the jboss-cvs-commits
mailing list