List of usage examples for org.springframework.util ReflectionUtils findMethod
@Nullable public static Method findMethod(Class<?> clazz, String name, @Nullable Class<?>... paramTypes)
From source file:org.springframework.webflow.validation.ValidationHelper.java
private Method findValidationMethod(Object model, Object validator, String methodName, Class<?> context) { Class<?> modelClass = AopUtils.getTargetClass(model); List<Class<?>> modelSearchClasses = new ArrayList<Class<?>>(); while (modelClass != null) { modelSearchClasses.add(modelClass); modelClass = modelClass.getSuperclass(); }/*from w w w . j av a2 s . c o m*/ for (Class<?> searchClass : modelSearchClasses) { Method method = ReflectionUtils.findMethod(validator.getClass(), methodName, new Class[] { searchClass, context }); if (method != null) { return method; } } return null; }
From source file:org.springframework.xd.reactor.BroadcasterMessageHandler.java
/** * Construct a new BroadcasterMessageHandler given the reactor based Processor to delegate * processing to.//from ww w .j a v a2 s .co m * * @param processor The stream based reactor processor */ @SuppressWarnings({ "unchecked", "rawtypes" }) public BroadcasterMessageHandler(Processor processor) { Assert.notNull(processor, "processor cannot be null."); this.reactorProcessor = processor; Environment.initializeIfEmpty(); // This by default uses SynchronousDispatcher Method method = ReflectionUtils.findMethod(this.reactorProcessor.getClass(), "process", Stream.class); this.inputType = ResolvableType.forMethodParameter(method, 0).getNested(2); //Stream with a SynchronousDispatcher as this handler is called by Message Listener managed threads this.stream = SerializedBroadcaster.create(); //user defined stream processing Stream<?> outputStream = processor.process(stream); //Simple log error handling outputStream.when(Throwable.class, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) { logger.error(throwable); } }); this.control = outputStream.consume(new Consumer<Object>() { @Override public void accept(Object outputObject) { if (ClassUtils.isAssignable(Message.class, outputObject.getClass())) { getOutputChannel().send((Message) outputObject); } else { getOutputChannel().send(MessageBuilder.withPayload(outputObject).build()); } } }); if (logger.isDebugEnabled()) { logger.debug(control.debug()); } }
From source file:org.springframework.xd.reactor.MultipleBroadcasterMessageHandler.java
/** * Construct a new SynchronousDispatcherMessageHandler given the reactor based Processor to delegate * processing to.//from w w w . j av a 2 s . c o m * * @param processor The stream based reactor processor */ @SuppressWarnings({ "unchecked", "rawtypes" }) public MultipleBroadcasterMessageHandler(Processor processor, String partitionExpression) { Assert.notNull(processor, "processor cannot be null."); Assert.notNull(partitionExpression, "Partition expression can not be null"); this.processor = processor; this.partitionExpression = spelExpressionParser.parseExpression(partitionExpression); environment = Environment.initializeIfEmpty(); // This by default uses SynchronousDispatcher Method method = ReflectionUtils.findMethod(this.processor.getClass(), "process", Stream.class); this.inputType = ResolvableType.forMethodParameter(method, 0).getNested(2); }
From source file:org.springframework.xd.reactor.SynchronousDispatcherMessageHandler.java
/** * Construct a new SynchronousDispatcherMessageHandler given the reactor based Processor to delegate * processing to.//from www. j a v a 2s . c o m * * @param processor The stream based reactor processor */ @SuppressWarnings({ "unchecked", "rawtypes" }) public SynchronousDispatcherMessageHandler(Processor processor) { Assert.notNull(processor, "processor cannot be null."); this.reactorProcessor = processor; Environment.initializeIfEmpty(); // This by default uses SynchronousDispatcher Method method = ReflectionUtils.findMethod(this.reactorProcessor.getClass(), "process", Stream.class); this.inputType = ResolvableType.forMethodParameter(method, 0).getNested(2); //Stream with a SynchronousDispatcher as this handler is called by Message Listener managed threads this.stream = Streams.broadcast(); //user defined stream processing Stream<?> outputStream = processor.process(stream); //Simple log error handling outputStream.when(Throwable.class, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) { logger.error(throwable); } }); this.consume = outputStream.consume(new Consumer<Object>() { @Override public void accept(Object outputObject) { if (ClassUtils.isAssignable(Message.class, outputObject.getClass())) { getOutputChannel().send((Message) outputObject); } else { //TODO handle copy of header values when possible getOutputChannel().send(MessageBuilder.withPayload(outputObject).build()); } //TODO handle Void } }); if (logger.isDebugEnabled()) { logger.debug(consume.debug()); } }
From source file:org.springframework.xd.rxjava.MultipleSubjectMessageHandler.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public MultipleSubjectMessageHandler(Processor processor, String partitionExpression) { Assert.notNull(processor, "processor cannot be null."); Assert.notNull(partitionExpression, "Partition expression can not be null"); this.processor = processor; this.partitionExpression = spelExpressionParser.parseExpression(partitionExpression); Method method = ReflectionUtils.findMethod(this.processor.getClass(), "process", Observable.class); this.inputType = ResolvableType.forMethodParameter(method, 0).getNested(2); }
From source file:org.springframework.xd.rxjava.SubjectMessageHandler.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public SubjectMessageHandler(Processor processor) { Assert.notNull(processor, "processor cannot be null."); this.processor = processor; Method method = ReflectionUtils.findMethod(this.processor.getClass(), "process", Observable.class); this.inputType = ResolvableType.forMethodParameter(method, 0).getNested(2); subject = new SerializedSubject(PublishSubject.create()); Observable<?> outputStream = processor.process(subject); subscription = outputStream.subscribe(new Action1<Object>() { @Override/*from ww w . j a va 2s . co m*/ public void call(Object outputObject) { if (ClassUtils.isAssignable(Message.class, outputObject.getClass())) { getOutputChannel().send((Message) outputObject); } else { getOutputChannel().send(MessageBuilder.withPayload(outputObject).build()); } } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { logger.error(throwable); } }, new Action0() { @Override public void call() { logger.error("Subscription close for [" + subscription + "]"); } }); }
From source file:org.springframework.yarn.support.compat.NMTokenCacheCompat.java
public static boolean containsToken(NMTokenCache nmTokenCache, String nodeId) { if (nmTokenCache != null) { Method method = ReflectionUtils.findMethod(NMTokenCache.class, "containsNMToken", String.class); if (method == null) { method = ReflectionUtils.findMethod(NMTokenCache.class, "containsToken", String.class); }/*from w ww . j a va 2 s . com*/ if (method != null) { boolean results = (Boolean) ReflectionUtils.invokeMethod(method, nmTokenCache, nodeId); log.debug("NMTokenCache method " + method.getName() + " returned " + results); return results; } else { log.debug("Unable to determine the name for 'containsToken' method on NMTokenCache class"); } } return false; }
From source file:org.springframework.yarn.support.compat.ResourceCompat.java
/** * Invokes {@link Resource#setVirtualCores(int)}. * * @param resource the target object/*from w w w . j a v a 2s. com*/ * @param vCores the vCores */ public static void setVirtualCores(Resource resource, int vCores) { if (setVirtualCores == null) { setVirtualCores = ReflectionUtils.findMethod(Resource.class, "setVirtualCores", int.class); } if (setVirtualCores != null) { ReflectionUtils.invokeMethod(setVirtualCores, resource, vCores); } else { log.warn("Method setVirtualCores(int) is not implemented"); } }
From source file:org.squashtest.tm.service.internal.batchimport.excel.ReflectionMutatorSetter.java
/** * @see org.squashtest.tm.service.internal.batchimport.excel.PropertySetter#set(java.lang.Object, java.lang.Object) *///ww w . j av a 2s.c o m @Override public void set(VAL value, TARGET target) { if (optionalValue && value == null) { return; } if (!optionalValue && value == null) { throw new NullMandatoryValueException(mutatorName); } if (mutator == null) { mutator = ReflectionUtils.findMethod(target.getClass(), mutatorName, paramType(value)); if (mutator == null) { throw new IllegalStateException("Could not find method named '" + mutatorName + "(" + paramType(value) + ")' in object of type '" + target.getClass() + "'. Maybe you mistyped field name."); } mutator.setAccessible(true); } ReflectionUtils.invokeMethod(mutator, target, value); }
From source file:org.statefulj.framework.core.actions.MethodInvocationAction.java
protected Object invoke(Object context, List<Object> invokeParmList) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { Method method = ReflectionUtils.findMethod(context.getClass(), this.method, this.parameters); if (method == null) { throw new NoSuchMethodException(this.method); }// w w w . j a va 2 s . co m Object[] methodParms = invokeParmList.subList(0, this.parameters.length).toArray(); method.setAccessible(true); return method.invoke(context, methodParms); }