/** * Find a method on a class with a specified parameter list. */ private static Method getMethod(final Class<?> clazz, final String methodName, final Class<?>[] parameterTypes) throws IntrospectionException { if (methodName == null) { return null; } final Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, parameterTypes); if (method != null) { return method; } final int parameterCount = (parameterTypes == null) ? 0 : parameterTypes.length; // No Method found throw new IntrospectionException("No method \"" + methodName + "\" with " + parameterCount + " parameter(s) of matching types."); }
/** * Find a method on a class with a specified parameter list. */ private static Method getMethod(final Class<?> clazz, final String methodName, final Class<?>[] parameterTypes) throws IntrospectionException { if (methodName == null) { return null; } final Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, parameterTypes); if (method != null) { return method; } final int parameterCount = (parameterTypes == null) ? 0 : parameterTypes.length; // No Method found throw new IntrospectionException("No method \"" + methodName + "\" with " + parameterCount + " parameter(s) of matching types."); }
+ propName; final Method readMethod = MethodUtils .getMatchingAccessibleMethod(beanClass, methodName, EMPTY_CLASS_PARAMETERS); if (readMethod != null) { + propName; Method writeMethod = MethodUtils .getMatchingAccessibleMethod(beanClass, methodName, LIST_CLASS_PARAMETER); if (writeMethod == null) {
+ propName; final Method readMethod = MethodUtils .getMatchingAccessibleMethod(beanClass, methodName, EMPTY_CLASS_PARAMETERS); if (readMethod != null) { + propName; Method writeMethod = MethodUtils .getMatchingAccessibleMethod(beanClass, methodName, LIST_CLASS_PARAMETER); if (writeMethod == null) {
final Method method = getMatchingAccessibleMethod( object.getClass(), methodName, final Method method = getMatchingAccessibleMethod( objectClass, methodName,
final Method method = getMatchingAccessibleMethod( object.getClass(), methodName, final Method method = getMatchingAccessibleMethod( objectClass, methodName,
/** * Find a method on a class with a specified parameter list. */ private static Method getMethod(Class clazz, String methodName, Class[] parameterTypes) throws IntrospectionException { if (methodName == null) { return null; } Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, parameterTypes); if (method != null) { return method; } int parameterCount = (parameterTypes == null) ? 0 : parameterTypes.length; // No Method found throw new IntrospectionException("No method \"" + methodName + "\" with " + parameterCount + " parameter(s) of matching types."); }
/** * Find a method on a class with a specified parameter list. */ private static Method getMethod(Class clazz, String methodName, Class[] parameterTypes) throws IntrospectionException { if (methodName == null) { return null; } Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, parameterTypes); if (method != null) { return method; } int parameterCount = (parameterTypes == null) ? 0 : parameterTypes.length; // No Method found throw new IntrospectionException("No method \"" + methodName + "\" with " + parameterCount + " parameter(s) of matching types."); }
/** * Find a method on a class with a specified parameter list. */ private static Method getMethod(Class clazz, String methodName, Class[] parameterTypes) throws IntrospectionException { if (methodName == null) { return null; } Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, parameterTypes); if (method != null) { return method; } int parameterCount = (parameterTypes == null) ? 0 : parameterTypes.length; // No Method found throw new IntrospectionException("No method \"" + methodName + "\" with " + parameterCount + " parameter(s) of matching types."); }
/** * Find a method on a class with a specified parameter list. */ private static Method getMethod(final Class<?> clazz, final String methodName, final Class<?>[] parameterTypes) throws IntrospectionException { if (methodName == null) { return null; } final Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, parameterTypes); if (method != null) { return method; } final int parameterCount = (parameterTypes == null) ? 0 : parameterTypes.length; // No Method found throw new IntrospectionException("No method \"" + methodName + "\" with " + parameterCount + " parameter(s) of matching types."); }
public Object invokeJavaMethod(final String typeOfValueToSet, final Object valueToSetObjectWith, final Object objectToInvokeJavaMethodOn, final String operator, final String operatorParameterClassName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { final Class<?> expressionResultType = getClassOrPrimitiveClass(typeOfValueToSet); final Class<?> dataType = Thread.currentThread().getContextClassLoader().loadClass(objectToInvokeJavaMethodOn.getClass().getName()); final Method method = MethodUtils.getMatchingAccessibleMethod(dataType, operator, new Class[]{getClassOrPrimitiveClass(operatorParameterClassName)}); if (method != null) { final Object o = dataType.cast(objectToInvokeJavaMethodOn); method.invoke(o, expressionResultType.cast(valueToSetObjectWith)); return o; } else { throw new NoSuchMethodException(dataType.toGenericString() + "." + operator + "(" + operatorParameterClassName + ")."); } } }
public Object invokeJavaMethod(final String typeOfValueToSet, final Object valueToSetObjectWith, final Object objectToInvokeJavaMethodOn, final String operator, final String operatorParameterClassName) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { final Class<?> expressionResultType = getClassOrPrimitiveClass(typeOfValueToSet); final Class<?> dataType = Thread.currentThread().getContextClassLoader().loadClass(objectToInvokeJavaMethodOn.getClass().getName()); final Method method = MethodUtils.getMatchingAccessibleMethod(dataType, operator, new Class[]{getClassOrPrimitiveClass(operatorParameterClassName)}); if (method != null) { final Object o = dataType.cast(objectToInvokeJavaMethodOn); method.invoke(o, expressionResultType.cast(valueToSetObjectWith)); return o; } else { throw new NoSuchMethodException(dataType.toGenericString() + "." + operator + "(" + operatorParameterClassName + ")."); } } }
/** * Returns a suitable handler method for an event. First, it searches for a method with a single * argument that assignment-compatible with the event. Failing that, it searches for a method * with no arguments. Failing that, it returns null. * * @param handlerName The name of the handler method (defaults to a method with the same name as * the event type). * @param instance The instance implementing the handler method. * @param event The event. * @return The handler method, or null if a suitable method could not be found. */ public static Method getHandler(String handlerName, Object instance, Event event) { handlerName = handlerName != null ? handlerName : event.getType(); Method method = MethodUtils.getMatchingAccessibleMethod(instance.getClass(), handlerName, new Class<?>[] { event.getClass() }); return method != null ? method : MethodUtils.getAccessibleMethod(instance.getClass(), handlerName, ArrayUtils.EMPTY_CLASS_ARRAY); }
/** * Returns a suitable handler method for an event. First, it searches for a method with a single * argument that assignment-compatible with the event. Failing that, it searches for a method * with no arguments. Failing that, it returns null. * * @param handlerName The name of the handler method (defaults to a method with the same name as * the event type). * @param instance The instance implementing the handler method. * @param event The event. * @return The handler method, or null if a suitable method could not be found. */ public static Method getHandler(String handlerName, Object instance, Event event) { handlerName = handlerName != null ? handlerName : event.getType(); Method method = MethodUtils.getMatchingAccessibleMethod(instance.getClass(), handlerName, new Class<?>[] { event.getClass() }); return method != null ? method : MethodUtils.getAccessibleMethod(instance.getClass(), handlerName, ArrayUtils.EMPTY_CLASS_ARRAY); }
public static Object method(Object obj, String methodName, Object... params) { try { Method method = null; try { method = obj.getClass().getDeclaredMethod(methodName, paramsToTypes(params)); } catch (Exception e) { try { method = obj.getClass().getMethod(methodName, paramsToTypes(params)); } catch (Exception e1) { method = MethodUtils.getMatchingAccessibleMethod(obj.getClass(), methodName, paramsToTypes(params)); } } method.setAccessible(true); return method.invoke(obj, params); } catch (Exception e) { try { ExceptionHandler.renderHandle(e); } catch (Exception e1) { e1.printStackTrace(); } return null; } }
/** * {@inheritDoc} */ public Object getValue(String serviceName, String fieldName) throws MethodInvocationException { if (serviceName == null) { throw new IllegalArgumentException("serviceName argument must not be null!"); } if (fieldName == null) { throw new IllegalArgumentException("fieldName argument must not be null!"); } log.debug("Getting value from service with name='{}', fieldName='{}'.", serviceName, fieldName); Object result = null; OpenLService service = runningServices.get(serviceName); if (service != null) { try { Method serviceMethod = MethodUtils.getMatchingAccessibleMethod(service.getServiceBean().getClass(), ClassUtils.getter(fieldName), new Class<?>[] {}); result = serviceMethod.invoke(service.getServiceBean(), new Object[] {}); } catch (Exception e) { if (e.getCause() instanceof RuleServiceWrapperException) { throw new MethodInvocationException(e.getCause()); } else { log.warn("Error on reading field '{}' from the service '{}'.", fieldName, serviceName, e); } } } return result; }
/** * {@inheritDoc} */ public void addToValue(Object target, int index, Object value) throws IllegalAccessException, InvocationTargetException { if (adderAtMethod == null) { adderAtMethod = MethodUtils.getMatchingAccessibleMethod(getBeanClass(), AccessorInfo.ADDER_PREFIX + capitalizeFirst(getProperty()), new Class[] {Integer.TYPE, getElementClass()}); } try { adderAtMethod.invoke(target, new Object[] {new Integer(index), value}); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof RuntimeException) { throw (RuntimeException) ex.getTargetException(); } throw ex; } }
public static Object staticMethod(Class obj, String methodName, Object... params) { try { Method method = null; try { method = obj.getDeclaredMethod(methodName, paramsToTypes(params)); } catch (Exception e) { try { method = obj.getMethod(methodName, paramsToTypes(params)); } catch (Exception e1) { method = MethodUtils.getMatchingAccessibleMethod(obj, methodName, paramsToTypes(params)); } } if (!Modifier.isPublic(method.getModifiers())) { method.setAccessible(true); } return method.invoke(null, params); } catch (Exception e) { try { ExceptionHandler.renderHandle(e); } catch (Exception e1) { e1.printStackTrace(); } return null; } }
/** * {@inheritDoc} */ public void removeFromValue(Object target, Object value) throws IllegalAccessException, InvocationTargetException { if (removerMethod == null) { removerMethod = MethodUtils.getMatchingAccessibleMethod(getBeanClass(), AccessorInfo.REMOVER_PREFIX + capitalizeFirst(getProperty()), new Class[] {getElementClass()}); } try { removerMethod.invoke(target, new Object[] {value}); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof RuntimeException) { throw (RuntimeException) ex.getTargetException(); } throw ex; } }
/** * {@inheritDoc} */ public void addToValue(Object target, Object value) throws IllegalAccessException, InvocationTargetException { if (adderMethod == null) { adderMethod = MethodUtils.getMatchingAccessibleMethod(getBeanClass(), AccessorInfo.ADDER_PREFIX + capitalizeFirst(getProperty()), new Class[] {getElementClass()}); } try { adderMethod.invoke(target, new Object[] {value}); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof RuntimeException) { throw (RuntimeException) ex.getTargetException(); } throw ex; } }