protected MethodInvoker getMethodInvokerByName(String methodName, Object candidate, Class<?>... params) { if (methodName != null) { return MethodInvokerUtils.getMethodInvokerByName(candidate, methodName, false, params); } else { return null; } }
invoker = getMethodInvokerForInterface(metaData.getListenerInterface(), metaData.getMethodName(), delegate, metaData.getParamTypes()); if (invoker != null) { invoker = getMethodInvokerByAnnotation(metaData.getAnnotation(), delegate, metaData.getParamTypes()); if (invoker != null) { invokers.add(invoker);
MethodInvoker mi = MethodInvokerUtils.getMethodInvokerByAnnotation(annotationType, target); final Class<?> targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource() .getTargetClass() : target.getClass(); String errorMsg = "The method [" + method.getName() + "] on target class [" + targetClass.getSimpleName() + "] is incompatible with the signature [" + getParamTypesString(expectedParamTypes) + "] expected for the annotation [" + annotationType.getSimpleName() + "].";
if (MethodInvokerUtils.getMethodInvokerByAnnotation(metaData.getAnnotation(), target) != null) { return true;
/** * Create a {@link MethodInvoker} using the provided method name to search. * * @param object to be invoked * @param methodName of the method to be invoked * @param paramsRequired boolean indicating whether the parameters are * required, if false, a no args version of the method will be searched for. * @param paramTypes - parameter types of the method to search for. * @return MethodInvoker if the method is found, null if it is not. */ public static MethodInvoker getMethodInvokerByName(Object object, String methodName, boolean paramsRequired, Class<?>... paramTypes) { Assert.notNull(object, "Object to invoke must not be null"); Method method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName, paramTypes); if (method == null) { String errorMsg = "no method found with name [" + methodName + "] on class [" + object.getClass().getSimpleName() + "] compatible with the signature [" + getParamTypesString(paramTypes) + "]."; Assert.isTrue(!paramsRequired, errorMsg); // if no method was found for the given parameters, and the // parameters aren't required, then try with no params method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName); Assert.notNull(method, errorMsg); } return new SimpleMethodInvoker(object, method); }
if (MethodInvokerUtils.getMethodInvokerByAnnotation(metaData.getAnnotation(), target) != null) { return true;
/** * Create a {@link MethodInvoker} using the provided method name to search. * * @param object to be invoked * @param methodName of the method to be invoked * @param paramsRequired boolean indicating whether the parameters are * required, if false, a no args version of the method will be searched for. * @param paramTypes - parameter types of the method to search for. * @return MethodInvoker if the method is found, null if it is not. */ public static MethodInvoker getMethodInvokerByName(Object object, String methodName, boolean paramsRequired, Class<?>... paramTypes) { Assert.notNull(object, "Object to invoke must not be null"); Method method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName, paramTypes); if (method == null) { String errorMsg = "no method found with name [" + methodName + "] on class [" + object.getClass().getSimpleName() + "] compatible with the signature [" + getParamTypesString(paramTypes) + "]."; Assert.isTrue(!paramsRequired, errorMsg); // if no method was found for the given parameters, and the // parameters aren't required, then try with no params method = ClassUtils.getMethodIfAvailable(object.getClass(), methodName); Assert.notNull(method, errorMsg); } return new SimpleMethodInvoker(object, method); }
Set<MethodInvoker> invokers = new NullIgnoringSet<MethodInvoker>(); invokers.add(getMethodInvokerByName(entry.getValue(), delegate, metaData.getParamTypes())); invokers.add(getMethodInvokerForInterface(metaData.getListenerInterface(), metaData.getMethodName(), delegate, metaData.getParamTypes())); invokers.add(getMethodInvokerByAnnotation(metaData.getAnnotation(), delegate, metaData.getParamTypes())); if (!invokers.isEmpty()) { invokerMap.put(metaData.getMethodName(), invokers);
/** * Create a {@link MethodInvoker} using the provided interface, and method * name from that interface. * * @param cls the interface to search for the method named * @param methodName of the method to be invoked * @param object to be invoked * @param paramTypes - parameter types of the method to search for. * @return MethodInvoker if the method is found, null if it is not. */ public static MethodInvoker getMethodInvokerForInterface(Class<?> cls, String methodName, Object object, Class<?>... paramTypes) { if (cls.isAssignableFrom(object.getClass())) { return MethodInvokerUtils.getMethodInvokerByName(object, methodName, true, paramTypes); } else { return null; } }
/** * Convenience method to check whether the given object is or can be made * into a listener. * * @param target the object to check * @return true if the delegate is an instance of any of the listener * interface, or contains the marker annotations */ public static boolean isListener(Object target, Class<?> listenerType, ListenerMetaData[] metaDataValues) { if (target == null) { return false; } if (listenerType.isInstance(target)) { return true; } if (target instanceof Advised) { TargetSource targetSource = ((Advised) target).getTargetSource(); if (targetSource!=null && targetSource.getTargetClass()!=null && listenerType.isAssignableFrom(targetSource.getTargetClass())) { return true; } } for (ListenerMetaData metaData : metaDataValues) { if (MethodInvokerUtils.getMethodInvokerByAnnotation(metaData.getAnnotation(), target) != null) { return true; } } return false; } }
MethodInvoker mi = MethodInvokerUtils.getMethodInvokerByAnnotation(annotationType, target); final Class<?> targetClass = (target instanceof Advised) ? ((Advised) target).getTargetSource() .getTargetClass() : target.getClass(); String errorMsg = "The method [" + method.getName() + "] on target class [" + targetClass.getSimpleName() + "] is incompatible with the signature [" + getParamTypesString(expectedParamTypes) + "] expected for the annotation [" + annotationType.getSimpleName() + "].";
invoker = getMethodInvokerForInterface(metaData.getListenerInterface(), metaData.getMethodName(), delegate, metaData.getParamTypes()); if (invoker != null) { invoker = getMethodInvokerByAnnotation(metaData.getAnnotation(), delegate, metaData.getParamTypes()); if (invoker != null) { invokers.add(invoker);
@Test public void testExitStatusReturn() throws Throwable{ Map<String, Set<MethodInvoker>> invokerMap = new HashMap<>(); Set<MethodInvoker> invokers = asSet(MethodInvokerUtils.getMethodInvokerByName(testClass, "method3", false)); invokers.add(MethodInvokerUtils.getMethodInvokerByName(testClass, "method3", false)); invokerMap.put("method3", invokers); interceptor = new MethodInvokerMethodInterceptor(invokerMap); assertEquals(ExitStatus.COMPLETED, interceptor.invoke(new StubMethodInvocation(TestClass.class.getMethod("method3")))); }
if (MethodInvokerUtils.getMethodInvokerByAnnotation(metaData.getAnnotation(), target) != null) { return true;
invoker = getMethodInvokerForInterface(metaData.getListenerInterface(), metaData.getMethodName(), delegate, metaData.getParamTypes()); if (invoker != null) { invoker = getMethodInvokerByAnnotation(metaData.getAnnotation(), delegate, metaData.getParamTypes()); if (invoker != null) { invokers.add(invoker);
@Test public void testMultipleInvokersPerName() throws Throwable{ Map<String, Set<MethodInvoker>> invokerMap = new HashMap<>(); Set<MethodInvoker> invokers = asSet(MethodInvokerUtils.getMethodInvokerByName(testClass, "method1", false)); invokers.add(MethodInvokerUtils.getMethodInvokerByName(testClass, "method2", false)); invokerMap.put("method1", invokers); interceptor = new MethodInvokerMethodInterceptor(invokerMap); interceptor.invoke(new StubMethodInvocation(TestClass.class.getMethod("method1"))); assertEquals(1, testClass.method1Count); interceptor.invoke(new StubMethodInvocation(TestClass.class.getMethod("method2"))); assertEquals(1, testClass.method2Count); }
if (MethodInvokerUtils.getMethodInvokerByAnnotation(metaData.getAnnotation(), target) != null) { return true;
invoker = getMethodInvokerForInterface(metaData.getListenerInterface(), metaData.getMethodName(), delegate, metaData.getParamTypes()); if (invoker != null) { invoker = getMethodInvokerByAnnotation(metaData.getAnnotation(), delegate, metaData.getParamTypes()); if (invoker != null) { invokers.add(invoker);
protected MethodInvoker getMethodInvokerByName(String methodName, Object candidate, Class<?>... params) { if (methodName != null) { return MethodInvokerUtils.getMethodInvokerByName(candidate, methodName, false, params); } else { return null; } }
protected MethodInvoker getMethodInvokerByName(String methodName, Object candidate, Class<?>... params) { if (methodName != null) { return MethodInvokerUtils.getMethodInvokerByName(candidate, methodName, false, params); } else { return null; } }