private boolean lookupUpdateConfigurationMethod() { if (updateConfigurationMethod == null) { Collection<Method> candidateMethods = getAllMethods(originalLogger.getClass(), withName("updateConfiguration"), withParameters(Configuration.class)); if (candidateMethods.size() == 1) { updateConfigurationMethod = candidateMethods.iterator().next(); updateConfigurationMethod.setAccessible(true); } } return updateConfigurationMethod != null; }
private boolean lookupUpdateConfigurationMethod() { if (updateConfigurationMethod == null) { Collection<Method> candidateMethods = getAllMethods(originalLogger.getClass(), withName("updateConfiguration"), withParameters(Configuration.class)); if (candidateMethods.size() == 1) { updateConfigurationMethod = candidateMethods.iterator().next(); updateConfigurationMethod.setAccessible(true); } } return updateConfigurationMethod != null; }
private boolean lookupUpdateConfigurationMethod() { if (updateConfigurationMethod == null) { Collection<Method> candidateMethods = getAllMethods(originalLogger.getClass(), withName("updateConfiguration"), withParameters(Configuration.class)); if (candidateMethods.size() == 1) { updateConfigurationMethod = candidateMethods.iterator().next(); updateConfigurationMethod.setAccessible(true); } } return updateConfigurationMethod != null; }
@Override public Object process(Object object) { for (Field field : getAllFields(object.getClass(), withAnnotation(Inject.class), withType(Registry.class))) { try { field.setAccessible(true); field.set(object, new DefaultRegistry(context)); } catch (Exception e) { throw new RuntimeException(format("Could not inject dependency on field %s of type %s", field.getName(), object.getClass().getName()), e); } } for (Method method : getAllMethods(object.getClass(), withAnnotation(Inject.class), withParameters(Registry.class))) { try { method.invoke(object, new DefaultRegistry(context)); } catch (Exception e) { throw new RuntimeException(format("Could not inject dependency on method %s of type %s", method.getName(), object.getClass().getName()), e); } } return object; } }
private <T extends Exception> ConstructorDelegate<T> selectMostCompleteConstructor(Class<T> exceptionType) { Collection<Constructor> candidate = getConstructors(exceptionType, withParameters(ValidationResult.class, MuleEvent.class)); if (!CollectionUtils.isEmpty(candidate)) { return new ValidationResultAndEventConstructorDelegate<>((Constructor<T>) candidate.iterator().next()); } candidate = getConstructors(exceptionType, withParameters(ValidationResult.class)); if (!CollectionUtils.isEmpty(candidate)) { return new ValidationResultConstructorDelegate((Constructor<T>) candidate.iterator().next()); } candidate = getConstructors(exceptionType, withParameters(String.class)); if (CollectionUtils.isEmpty(candidate)) { throw new IllegalArgumentException( String.format( "Exception type %s was expected to contain at least one accessible constructor with eia single String argument but a matching constructor " + "could not be found.", exceptionType.getCanonicalName())); } return new DirectMessageConstructorDelegate((Constructor<T>) candidate.iterator().next()); }
public static Method getOperationMethod(Class<?> declaringClass, Operation operation) { Class<?>[] parameterTypes; if (operation.getParameters().isEmpty()) { parameterTypes = org.apache.commons.lang.ArrayUtils.EMPTY_CLASS_ARRAY; } else { parameterTypes = new Class<?>[operation.getParameters().size()]; int i = 0; for (Parameter parameter : operation.getParameters()) { parameterTypes[i++] = parameter.getType().getRawType(); } } Collection<Method> methods = getAllMethods(declaringClass, withAnnotation(org.mule.extension.annotations.Operation.class), withModifier(Modifier.PUBLIC), withName(operation.getName()), withParameters(parameterTypes)); checkArgument(!methods.isEmpty(), String.format("Could not find method %s in class %s", operation.getName(), declaringClass.getName())); checkArgument(methods.size() == 1, String.format("More than one matching method was found in class %s for operation %s", declaringClass.getName(), operation.getName())); return methods.iterator().next(); }