[jboss-cvs] JBossCache/src/org/jboss/cache/notifications ...
Manik Surtani
manik at jboss.org
Thu Jul 5 08:11:07 EDT 2007
User: msurtani
Date: 07/07/05 08:11:07
Modified: src/org/jboss/cache/notifications Notifier.java
Log:
Improved error messages
Revision Changes Path
1.38 +19 -17 JBossCache/src/org/jboss/cache/notifications/Notifier.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Notifier.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/notifications/Notifier.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- Notifier.java 5 Jul 2007 02:36:34 -0000 1.37
+++ Notifier.java 5 Jul 2007 12:11:07 -0000 1.38
@@ -69,10 +69,7 @@
*/
private void validateAndAddListenerInvocation(Object listener)
{
- if (!listener.getClass().isAnnotationPresent(CacheListener.class))
- throw new IncorrectCacheListenerException("An Object must have the org.jboss.cache.notifications.annotation.CacheListener annotation to be considered a cache listener, and must be publicly accessible!");
- if (!Modifier.isPublic(listener.getClass().getModifiers()))
- throw new IncorrectCacheListenerException("An Object's class must be publicly accessible to be considered a cache listener!");
+ testListenerClassValidity(listener.getClass());
boolean foundMethods = false;
// now try all methods on the listener for anything that we like. Note that only PUBLIC methods are scanned.
@@ -83,16 +80,10 @@
{
if (m.isAnnotationPresent(allowedMethodAnnotations[i]))
{
- if (isValidListenerMethod(m, parameterTypes[i]))
- {
+ testListenerMethodValidity(m, parameterTypes[i], allowedMethodAnnotations[i].getName());
addListenerInvocation(allowedMethodAnnotations[i], new ListenerInvocation(listener, m));
foundMethods = true;
}
- else
- {
- throw new IncorrectCacheListenerException("Methods annotated with " + allowedMethodAnnotations[i].getName() + " need to be publicly accessible, return void, and accept one, and only one, parameter, assignable from " + parameterTypes[i].getName());
- }
- }
}
}
@@ -100,9 +91,20 @@
log.warn("Attempted to register listener of class " + listener.getClass() + ", but no valid, public methods annotated with method-level event annotations found! Ignoring listener.");
}
- private boolean isValidListenerMethod(Method m, Class allowedParameter)
+ private void testListenerClassValidity(Class listenerClass)
+ {
+ if (!listenerClass.isAnnotationPresent(CacheListener.class))
+ throw new IncorrectCacheListenerException("Cache listener class MUST be annotated with org.jboss.cache.notifications.annotation.CacheListener");
+ if (!Modifier.isPublic(listenerClass.getModifiers()))
+ throw new IncorrectCacheListenerException("Cache listener class MUST be public!");
+ }
+
+ private void testListenerMethodValidity(Method m, Class allowedParameter, String annotationName)
{
- return m.getParameterTypes().length == 1 && m.getParameterTypes()[0].isAssignableFrom(allowedParameter) && m.getReturnType().equals(void.class);
+ if (m.getParameterTypes().length != 1 || !m.getParameterTypes()[0].isAssignableFrom(allowedParameter))
+ throw new IncorrectCacheListenerException("Methods annotated with " + annotationName + " must accept exactly one parameter, of assignable from type " + allowedParameter.getName());
+ if (!m.getReturnType().equals(void.class))
+ throw new IncorrectCacheListenerException("Methods annotated with " + annotationName + " should have a return type of void.");
}
private void addListenerInvocation(Class annotation, ListenerInvocation li)
More information about the jboss-cvs-commits
mailing list