use of org.motechproject.event.listener.annotations.MotechListenerAbstractProxy in project motech by motech.
the class EventAnnotationBeanPostProcessor method processAnnotations.
private void processAnnotations(final Object bean, final String beanName) {
if (bean == null) {
return;
}
// Get declared methods from class without superclass methods.
for (Method method : bean.getClass().getDeclaredMethods()) {
Method methodOfOriginalClassIfProxied = ReflectionUtils.findMethod(AopUtils.getTargetClass(bean), method.getName(), method.getParameterTypes());
if (methodOfOriginalClassIfProxied != null) {
MotechListener annotation = methodOfOriginalClassIfProxied.getAnnotation(MotechListener.class);
if (annotation != null) {
final List<String> subjects = Arrays.asList(annotation.subjects());
MotechListenerAbstractProxy proxy = null;
switch(annotation.type()) {
case MOTECH_EVENT:
proxy = new MotechListenerEventProxy(getFullyQualifiedBeanName(bean.getClass(), beanName), bean, method);
break;
case NAMED_PARAMETERS:
proxy = new MotechListenerNamedParametersProxy(getFullyQualifiedBeanName(bean.getClass(), beanName), bean, method);
break;
default:
}
LOGGER.info(String.format("Registering listener type(%20s) bean: %s, method: %s, for subjects: " + "%s", annotation.type().toString() + ":" + beanName, bean.getClass().getName(), method.toGenericString(), subjects));
if (eventListenerRegistry != null) {
eventListenerRegistry.registerListener(proxy, subjects);
} else {
LOGGER.error("Null eventListenerRegistry. Unable to register listener");
}
}
}
}
}
use of org.motechproject.event.listener.annotations.MotechListenerAbstractProxy in project motech by motech.
the class HandlerPredicatesTest method shouldFoundCorrectObject.
@Test
public void shouldFoundCorrectObject() {
MotechListenerEventProxy expected = new MotechListenerEventProxy("def", null, null);
List<MotechListenerAbstractProxy> list = new ArrayList<>();
list.add(new MotechListenerNamedParametersProxy("abc", null, null));
list.add(expected);
list.add(new MotechListenerEventProxy("ghi", null, null));
MotechListenerAbstractProxy actual = (MotechListenerAbstractProxy) find(list, HandlerPredicates.withServiceName("def"));
assertTrue(actual instanceof MotechListenerEventProxy);
assertEquals(expected.getIdentifier(), actual.getIdentifier());
}
use of org.motechproject.event.listener.annotations.MotechListenerAbstractProxy in project motech by motech.
the class HandlerPredicatesTest method shouldNotFoundCorrectObject.
@Test
public void shouldNotFoundCorrectObject() {
List<MotechListenerAbstractProxy> list = new ArrayList<>();
list.add(new MotechListenerNamedParametersProxy("abc", null, null));
list.add(new MotechListenerEventProxy("def", null, null));
list.add(new MotechListenerEventProxy("ghi", null, null));
MotechListenerAbstractProxy actual = (MotechListenerAbstractProxy) find(list, HandlerPredicates.withServiceName("abc"));
assertNull(actual);
}
Aggregations