本文整理汇总了Java中org.springframework.util.ReflectionUtils.getAllDeclaredMethods方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils.getAllDeclaredMethods方法的具体用法?Java ReflectionUtils.getAllDeclaredMethods怎么用?Java ReflectionUtils.getAllDeclaredMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.getAllDeclaredMethods方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCandidateMethods
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* Retrieve all candidate methods for the given class, considering
* the {@link RootBeanDefinition#isNonPublicAccessAllowed()} flag.
* Called as the starting point for factory method determination.
*/
private Method[] getCandidateMethods(final Class<?> factoryClass, final RootBeanDefinition mbd) {
if (System.getSecurityManager() != null) {
return AccessController.doPrivileged(new PrivilegedAction<Method[]>() {
@Override
public Method[] run() {
return (mbd.isNonPublicAccessAllowed() ?
ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods());
}
});
}
else {
return (mbd.isNonPublicAccessAllowed() ?
ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods());
}
}
示例2: onApplicationEvent
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public synchronized void onApplicationEvent(ContextRefreshedEvent event) {
if(isRepeat){
return;
}
this.isRepeat = true;
this.applicationContext = event.getApplicationContext();
for(String beanName : this.applicationContext.getBeanDefinitionNames()){
Class<?> clz = this.applicationContext.getType(beanName);
if(clz == null) continue;
Method[] methods = ReflectionUtils.getAllDeclaredMethods(clz);
if(methods == null || methods.length <= 0){
continue;
}
for(Method method : methods){
QueueListener queueListener = AnnotationUtils.findAnnotation(method, QueueListener.class);
String registerBeanName = null;
String retryRegisterBeanName = null;
if(queueListener != null){
registerBeanName = "queueConsumer" + count.getAndIncrement();
this.registerListener(
registerBeanName,
new ActiveMQQueue(queueListener.name()),
this.applicationContext.getBean(beanName),
method,
queueListener.retryTimes(),
false);
retryRegisterBeanName = "retryQueueConsumer" + count.getAndIncrement();
this.registerListener(
retryRegisterBeanName,
new ActiveMQQueue(queueListener.name() + MQConstant.RETRY_QUEUE_SUFFIX),
this.applicationContext.getBean(beanName),
method,
0,
true);
}
TopicListnener topicListnener = AnnotationUtils.findAnnotation(method, TopicListnener.class);
if(topicListnener != null){
registerBeanName = "topicConsumer" + count.getAndIncrement();
this.registerListener(
registerBeanName,
new ActiveMQTopic(topicListnener.name()),
this.applicationContext.getBean(beanName),
method,
topicListnener.retryTimes(),
false);
retryRegisterBeanName = "retryTopicConsumer" + count.getAndIncrement();
this.registerListener(
retryRegisterBeanName,
new ActiveMQTopic(topicListnener.name() + MQConstant.RETRY_QUEUE_SUFFIX),
this.applicationContext.getBean(beanName),
method,
0,
true);
}
start(registerBeanName);
start(retryRegisterBeanName);
}
}
}
示例3: SpringExpressionParser
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
SpringExpressionParser(Class<?>... functionHolders) {
for (Class<?> functionHolder : functionHolders) {
for (Method method : ReflectionUtils.getAllDeclaredMethods(functionHolder)) {
if (isPublic(method.getModifiers()) && isStatic(method.getModifiers())) {
evalContext.registerFunction(method.getName(), method);
}
}
}
}
示例4: getCandidateFactoryMethods
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private Method[] getCandidateFactoryMethods(BeanDefinition definition,
Class<?> factoryClass) {
return shouldConsiderNonPublicMethods(definition)
? ReflectionUtils.getAllDeclaredMethods(factoryClass)
: factoryClass.getMethods();
}
示例5: doFindMatchingMethod
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* Actually find a method with matching parameter type, i.e. where each
* argument value is assignable to the corresponding parameter type.
* @param arguments the argument values to match against method parameters
* @return a matching method, or {@code null} if none
*/
protected Method doFindMatchingMethod(Object[] arguments) {
TypeConverter converter = getTypeConverter();
if (converter != null) {
String targetMethod = getTargetMethod();
Method matchingMethod = null;
int argCount = arguments.length;
Method[] candidates = ReflectionUtils.getAllDeclaredMethods(getTargetClass());
int minTypeDiffWeight = Integer.MAX_VALUE;
Object[] argumentsToUse = null;
for (Method candidate : candidates) {
if (candidate.getName().equals(targetMethod)) {
// Check if the inspected method has the correct number of parameters.
Class<?>[] paramTypes = candidate.getParameterTypes();
if (paramTypes.length == argCount) {
Object[] convertedArguments = new Object[argCount];
boolean match = true;
for (int j = 0; j < argCount && match; j++) {
// Verify that the supplied argument is assignable to the method parameter.
try {
convertedArguments[j] = converter.convertIfNecessary(arguments[j], paramTypes[j]);
}
catch (TypeMismatchException ex) {
// Ignore -> simply doesn't match.
match = false;
}
}
if (match) {
int typeDiffWeight = getTypeDifferenceWeight(paramTypes, convertedArguments);
if (typeDiffWeight < minTypeDiffWeight) {
minTypeDiffWeight = typeDiffWeight;
matchingMethod = candidate;
argumentsToUse = convertedArguments;
}
}
}
}
}
if (matchingMethod != null) {
setArguments(argumentsToUse);
return matchingMethod;
}
}
return null;
}