• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MethodCallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.util.ReflectionUtils.MethodCallback的典型用法代码示例。如果您正苦于以下问题:Java MethodCallback类的具体用法?Java MethodCallback怎么用?Java MethodCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MethodCallback类属于org.springframework.util.ReflectionUtils包,在下文中一共展示了MethodCallback类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: findFactoryMethod

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
private Method findFactoryMethod(String beanName) {
    if (!this.beans.containsKey(beanName)) {
        return null;
    }
    final AtomicReference<Method> found = new AtomicReference<Method>(null);
    MetaData meta = this.beans.get(beanName);
    final String factory = meta.getMethod();
    Class<?> type = this.beanFactory.getType(meta.getBean());
    ReflectionUtils.doWithMethods(type, new MethodCallback() {
        @Override
        public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
            if (method.getName().equals(factory)) {
                found.compareAndSet(null, method);
            }
        }
    });
    return found.get();
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:19,代码来源:ConfigurationBeanFactoryMetaData.java


示例2: findFactoryMethod

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
private Method findFactoryMethod(String beanName) {
	if (!this.beans.containsKey(beanName)) {
		return null;
	}
	final AtomicReference<Method> found = new AtomicReference<Method>(null);
	MetaData meta = this.beans.get(beanName);
	final String factory = meta.getMethod();
	Class<?> type = this.beanFactory.getType(meta.getBean());
	ReflectionUtils.doWithMethods(type, new MethodCallback() {
		@Override
		public void doWith(Method method)
				throws IllegalArgumentException, IllegalAccessException {
			if (method.getName().equals(factory)) {
				found.compareAndSet(null, method);
			}
		}
	});
	return found.get();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:ConfigurationBeanFactoryMetaData.java


示例3: addDeducedBeanTypeForBeanMethod

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
private void addDeducedBeanTypeForBeanMethod(ConditionContext context,
		AnnotatedTypeMetadata metadata, final List<String> beanTypes,
		final MethodMetadata methodMetadata) {
	try {
		// We should be safe to load at this point since we are in the
		// REGISTER_BEAN phase
		Class<?> configClass = ClassUtils.forName(
				methodMetadata.getDeclaringClassName(), context.getClassLoader());
		ReflectionUtils.doWithMethods(configClass, new MethodCallback() {
			@Override
			public void doWith(Method method)
					throws IllegalArgumentException, IllegalAccessException {
				if (methodMetadata.getMethodName().equals(method.getName())) {
					beanTypes.add(method.getReturnType().getName());
				}
			}
		});
	}
	catch (Throwable ex) {
		throw new BeanTypeDeductionException(
				methodMetadata.getDeclaringClassName(),
				methodMetadata.getMethodName(), ex);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:25,代码来源:OnBeanCondition.java


示例4: DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
public DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl(final Class<T> domainType) {
	super(domainType);
	this.hashAndRangeKeyMethodExtractor = new DynamoDBHashAndRangeKeyMethodExtractorImpl<T>(getJavaType());
	ReflectionUtils.doWithMethods(domainType, new MethodCallback() {
		public void doWith(Method method) {
			if (method.getAnnotation(DynamoDBHashKey.class) != null) {
				String setterMethodName = toSetterMethodNameFromAccessorMethod(method);
				if (setterMethodName != null) {
					hashKeySetterMethod = ReflectionUtils.findMethod(domainType, setterMethodName, method.getReturnType());
				}
			}
		}
	});
	ReflectionUtils.doWithFields(domainType, new FieldCallback() {
		public void doWith(Field field) {
			if (field.getAnnotation(DynamoDBHashKey.class) != null) {
				
				hashKeyField = ReflectionUtils.findField(domainType, field.getName());
				
			}
		}
	});
	Assert.isTrue(hashKeySetterMethod != null || hashKeyField != null, "Unable to find hash key field or setter method on " + domainType + "!");
	Assert.isTrue(hashKeySetterMethod == null || hashKeyField == null, "Found both hash key field and setter method on " + domainType + "!");

}
 
开发者ID:michaellavelle,项目名称:spring-data-dynamodb,代码行数:27,代码来源:DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl.java


示例5: postProcessAfterInitialization

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
@Override
public Object postProcessAfterInitialization(final Object bean, String beanName) {
	Class<?> targetClass = AopUtils.getTargetClass(bean);
	ReflectionUtils.doWithMethods(targetClass, new MethodCallback() {
		@Override
		public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
			for (Scheduled scheduled : AnnotationUtils.getRepeatableAnnotation(method, Schedules.class, Scheduled.class)) {
				processScheduled(scheduled, method, bean);
			}
		}
	});
	return bean;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:ScheduledAnnotationBeanPostProcessor.java


示例6: getInterceptors0

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
private Map<Integer, Set<Interceptor>> getInterceptors0(final Object bean, final Class<? extends Annotation> annotationClass) {
	final Map<Integer, Set<Interceptor>> interceptorMap = Maps.newTreeMap();

	ReflectionUtils.doWithMethods(bean.getClass(), new MethodCallback() {
		private Set<Class<? extends Annotation>> getAnnotations(Class<? extends Annotation>[] annotations) {
			if (ArrayUtils.isEmpty(annotations)) {
				return null;
			}

			Set<Class<? extends Annotation>> set = Sets.newLinkedHashSetWithExpectedSize(annotations.length);
			Collections.addAll(set, annotations);
			return set;
		}

		@Override
		@SuppressWarnings("unchecked")
		public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
			Annotation annotation = method.getAnnotation(annotationClass);
			Map<String, Object> annotationAttributes = AnnotationUtils.getAnnotationAttributes(annotation);

			int priority = MapUtils.getIntValue(annotationAttributes, "priority", 0);
			Set<Class<? extends Annotation>> only = getAnnotations((Class<? extends Annotation>[]) annotationAttributes.get("only"));
			Set<Class<? extends Annotation>> unless = getAnnotations((Class<? extends Annotation>[]) annotationAttributes.get("unless"));

			Set<Interceptor> interceptors = interceptorMap.get(priority);

			if (interceptors == null) {
				interceptors = Sets.newLinkedHashSet();
			}

			interceptors.add(new Interceptor(bean, method, only, unless));
			interceptorMap.put(priority, interceptors);
		}
	}, method -> method.isAnnotationPresent(annotationClass));

	return interceptorMap;
}
 
开发者ID:iceize,项目名称:netty-http-3.x,代码行数:38,代码来源:InterceptorManager.java


示例7: assertHasNoBeanMethods

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
private void assertHasNoBeanMethods(Class<?> testClass) {
	ReflectionUtils.doWithMethods(testClass, new MethodCallback() {

		@Override
		public void doWith(Method method) {
			Assert.state(!AnnotatedElementUtils.isAnnotated(method, Bean.class),
					"Test classes cannot include @Bean methods");
		}

	});

}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:ImportsContextCustomizerFactory.java


示例8: addDeducedBeanTypeForBeanMethod

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
private void addDeducedBeanTypeForBeanMethod(ConditionContext context,
		AnnotatedTypeMetadata metadata, final List<String> beanTypes,
		final MethodMetadata methodMetadata) {
	try {
		// We should be safe to load at this point since we are in the
		// REGISTER_BEAN phase
		Class<?> configClass = ClassUtils.forName(
				methodMetadata.getDeclaringClassName(), context.getClassLoader());
		ReflectionUtils.doWithMethods(configClass, new MethodCallback() {
			@Override
			public void doWith(Method method)
					throws IllegalArgumentException, IllegalAccessException {
				if (methodMetadata.getMethodName().equals(method.getName())) {
					beanTypes.add(method.getReturnType().getName());
				}
			}
		});
	}
	catch (Throwable ex) {
		// swallow exception and continue
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to deduce bean type for "
					+ methodMetadata.getDeclaringClassName() + "."
					+ methodMetadata.getMethodName(), ex);
		}
	}
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:28,代码来源:OnBeanCondition.java


示例9: getIndexRangeKeyPropertyNames

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
@Override
public Set<String> getIndexRangeKeyPropertyNames() {
	final Set<String> propertyNames = new HashSet<String>();
	ReflectionUtils.doWithMethods(getJavaType(), new MethodCallback() {
		public void doWith(Method method) {
			if (method.getAnnotation(DynamoDBIndexRangeKey.class) != null) {
				if ((method.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName() != null && method
						.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName().trim().length() > 0)
						|| (method.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames() != null && method
								.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames().length > 0)) {
					propertyNames.add(getPropertyNameForAccessorMethod(method));
				}
			}
		}
	});
	ReflectionUtils.doWithFields(getJavaType(), new FieldCallback() {
		public void doWith(Field field) {
			if (field.getAnnotation(DynamoDBIndexRangeKey.class) != null) {
				if ((field.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName() != null && field
						.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexName().trim().length() > 0)
						|| (field.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames() != null && field
								.getAnnotation(DynamoDBIndexRangeKey.class).localSecondaryIndexNames().length > 0)) {
					propertyNames.add(getPropertyNameForField(field));
				}
			}
		}
	});
	return propertyNames;
}
 
开发者ID:michaellavelle,项目名称:spring-data-dynamodb,代码行数:30,代码来源:DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl.java


示例10: FieldAndGetterReflectionEntityInformation

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
/**
 * Creates a new {@link FieldAndGetterReflectionEntityInformation} inspecting the
 * given domain class for a getter carrying the given annotation.
 * 
 * @param domainClass
 *            must not be {@literal null}.
 * @param annotation
 *            must not be {@literal null}.
 */
public FieldAndGetterReflectionEntityInformation(Class<T> domainClass, final Class<? extends Annotation> annotation) {

	super(domainClass);
	Assert.notNull(annotation);

	ReflectionUtils.doWithMethods(domainClass, new MethodCallback() {
		public void doWith(Method method) {
			if (method.getAnnotation(annotation) != null) {
				FieldAndGetterReflectionEntityInformation.this.method = method;
				return;
			}
		}
	});
	
	if (method == null)
	{
		ReflectionUtils.doWithFields(domainClass, new FieldCallback() {
			public void doWith(Field field) {
				if (field.getAnnotation(annotation) != null) {
					FieldAndGetterReflectionEntityInformation.this.field = field;
					return;
				}
			}
		});
	}

	Assert.isTrue(this.method != null || this.field != null, String.format("No field or method annotated with %s found!", annotation.toString()));
	Assert.isTrue(this.method == null || this.field == null, String.format("Both field and method annotated with %s found!", annotation.toString()));

	if (method != null)
	{
		ReflectionUtils.makeAccessible(method);
	}
}
 
开发者ID:michaellavelle,项目名称:spring-data-dynamodb,代码行数:44,代码来源:FieldAndGetterReflectionEntityInformation.java


示例11: findAnnotatedElements

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
/**
 * Find annotated elements on types
 * @param ann annotation to search
 * @param clazz class to search on.
 * @return List with annotated elements
 */
public static List<AnnotatedElement> findAnnotatedElements(final Class<? extends Annotation> annotationType, Class<?> clazz) {
	final ArrayList<AnnotatedElement> elements = new ArrayList<AnnotatedElement>();
	// Lookup fields
	ReflectionUtils.doWithFields(clazz, new FieldCallback() {
		
		@Override
		public void doWith(Field field) throws IllegalArgumentException,
				IllegalAccessException {
			if (field.getAnnotation(annotationType) != null) {
				elements.add(field);
			}
			
		}
	});
	// Lookup methods
	ReflectionUtils.doWithMethods(clazz, new MethodCallback() {
		
		@Override
		public void doWith(Method method) throws IllegalArgumentException,
				IllegalAccessException {
			
			if (org.springframework.core.annotation.AnnotationUtils.getAnnotation(method, annotationType) != null)
				elements.add(method);
		}
	});
	
	return elements;
}
 
开发者ID:chelu,项目名称:jdal,代码行数:35,代码来源:AnnotatedElementAccessor.java


示例12: restOperationsAreAvailable

import org.springframework.util.ReflectionUtils.MethodCallback; //导入依赖的package包/类
@Test
public void restOperationsAreAvailable() throws Exception {
	RestTemplate delegate = mock(RestTemplate.class);
	final TestRestTemplate restTemplate = new TestRestTemplate(delegate);
	ReflectionUtils.doWithMethods(RestOperations.class, new MethodCallback() {

		@Override
		public void doWith(Method method)
				throws IllegalArgumentException, IllegalAccessException {
			Method equivalent = ReflectionUtils.findMethod(TestRestTemplate.class,
					method.getName(), method.getParameterTypes());
			try {
				equivalent.invoke(restTemplate,
						mockArguments(method.getParameterTypes()));
			}
			catch (Exception ex) {
				throw new IllegalStateException(ex);
			}
		}

		private Object[] mockArguments(Class<?>[] parameterTypes) throws Exception {
			Object[] arguments = new Object[parameterTypes.length];
			for (int i = 0; i < parameterTypes.length; i++) {
				arguments[i] = mockArgument(parameterTypes[i]);
			}
			return arguments;
		}

		private Object mockArgument(Class<?> type) throws Exception {
			if (String.class.equals(type)) {
				return "String";
			}
			if (Object[].class.equals(type)) {
				return new Object[0];
			}
			if (URI.class.equals(type)) {
				return new URI("http://localhost");
			}
			if (HttpMethod.class.equals(type)) {
				return HttpMethod.GET;
			}
			if (Class.class.equals(type)) {
				return Object.class;
			}
			return mock(type);
		}

	});

}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:51,代码来源:TestRestTemplateTests.java



注:本文中的org.springframework.util.ReflectionUtils.MethodCallback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OFFlowStatsReply类代码示例发布时间:2022-05-21
下一篇:
Java GamesOptions类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap