private void addAnnotations(Class<? extends Annotation> annotationClass, Annotation annotation, EJBContainer container, String methodName, MethodParametersMetaData params)
{
try
{
AnnotationRepository annotations = container.getAnnotations();
if (methodName.equals("*"))
{
log.debug("adding " + annotationClass.getName() + " annotation to "
+ ejbClass.getName() + "." + methodName);
for (java.lang.reflect.Method declaredMethod : ejbClass
.getDeclaredMethods())
{
annotations.addAnnotation(declaredMethod, annotationClass,
annotation);
overrideAnnotations(container, declaredMethod, annotationClass
.getName(), annotation);
}
} else
{
if (params == null)
{
java.lang.reflect.Method[] methods = ejbClass.getMethods();
boolean foundMethod = false;
for (int methodIndex = 0; methodIndex < methods.length; ++methodIndex)
{
if (methods[methodIndex].getName().equals(methodName))
{
log.debug("adding " + annotationClass.getName()
+ " method annotation to " + methods[methodIndex]);
annotations.addAnnotation(methods[methodIndex],
annotationClass, annotation);
overrideAnnotations(container, methods[methodIndex],
annotationClass.getName(), annotation);
foundMethod = true;
}
}
if (!foundMethod)
{
methods = ejbClass.getDeclaredMethods();
for (int methodIndex = 0; methodIndex < methods.length; ++methodIndex)
{
if (methods[methodIndex].getName().equals(methodName))
{
log.debug("adding " + annotationClass.getName()
+ " method annotation to " + methods[methodIndex]);
annotations.addAnnotation(methods[methodIndex],
annotationClass, annotation);
overrideAnnotations(container, methods[methodIndex],
annotationClass.getName(), annotation);
foundMethod = true;
}
}
}
if (!foundMethod)
{
java.lang.reflect.Field member = ejbClass
.getDeclaredField(methodName);
if (member != null)
{
log.debug("adding " + annotationClass.getName()
+ " field annotation to " + member);
annotations
.addAnnotation(member, annotationClass, annotation);
overrideAnnotations(container, member, annotationClass
.getName(), annotation);
}
}
} else
{
Class<?>[] methodSignature = new Class[params.size()];
int paramIndex = 0;
for(String param : params)
{
Class<?> paramClass = null;
if (param.equals("boolean"))
paramClass = boolean.class;
else if (param.equals("int"))
paramClass = int.class;
else if (param.equals("long"))
paramClass = long.class;
else if (param.equals("short"))
paramClass = short.class;
else if (param.equals("byte"))
paramClass = byte.class;
else if (param.equals("char"))
paramClass = char.class;
else
paramClass = di.getClassLoader().loadClass(param);
methodSignature[paramIndex++] = paramClass;
}
if(log.isTraceEnabled())
log.trace("Looking for method " + methodName + Arrays.toString(methodSignature) + " on class " + ejbClass);
Member member = ClassHelper.getPrivateMethod(ejbClass, methodName, methodSignature);
log.debug("adding " + annotationClass.getName()
+ " method annotation to " + member);
annotations.addAnnotation(member, annotationClass, annotation);
overrideAnnotations(container, member, annotationClass.getName(),
annotation);
}
}
}