当前位置: 首页>>代码示例>>Java>>正文


Java GenericTypeResolver类代码示例

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


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

示例1: getPropertyType

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
@Override
public synchronized Class<?> getPropertyType() {
	if (this.propertyType == null) {
		if (this.readMethod != null) {
			this.propertyType = GenericTypeResolver.resolveReturnType(this.readMethod, this.beanClass);
		}
		else {
			MethodParameter writeMethodParam = getWriteMethodParameter();
			if (writeMethodParam != null) {
				this.propertyType = writeMethodParam.getParameterType();
			}
			else {
				this.propertyType = super.getPropertyType();
			}
		}
	}
	return this.propertyType;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:GenericTypeAwarePropertyDescriptor.java

示例2: addFormatterForFieldAnnotation

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void addFormatterForFieldAnnotation(AnnotationFormatterFactory annotationFormatterFactory) {
	final Class<? extends Annotation> annotationType = (Class<? extends Annotation>)
			GenericTypeResolver.resolveTypeArgument(annotationFormatterFactory.getClass(), AnnotationFormatterFactory.class);
	if (annotationType == null) {
		throw new IllegalArgumentException("Unable to extract parameterized Annotation type argument from AnnotationFormatterFactory [" +
				annotationFormatterFactory.getClass().getName() + "]; does the factory parameterize the <A extends Annotation> generic type?");
	}
	if (this.embeddedValueResolver != null && annotationFormatterFactory instanceof EmbeddedValueResolverAware) {
		((EmbeddedValueResolverAware) annotationFormatterFactory).setEmbeddedValueResolver(this.embeddedValueResolver);
	}
	Set<Class<?>> fieldTypes = annotationFormatterFactory.getFieldTypes();
	for (final Class<?> fieldType : fieldTypes) {
		addConverter(new AnnotationPrinterConverter(annotationType, annotationFormatterFactory, fieldType));
		addConverter(new AnnotationParserConverter(annotationType, annotationFormatterFactory, fieldType));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:FormattingConversionService.java

示例3: cronyxQuartzConverterPairs

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
public static <T> List<Pair<Class, T>> cronyxQuartzConverterPairs(Class<T> tClass) {

        List<Pair<Class, T>> results = new ArrayList<>();

        ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
        provider.addIncludeFilter(new AssignableTypeFilter(tClass));

        Set<BeanDefinition> components = provider.findCandidateComponents(PACKAGE);
        for (BeanDefinition component : components) {
            try {
                Class cls = Class.forName(component.getBeanClassName());
                Class<?> typeArgument = GenericTypeResolver.resolveTypeArgument(cls, tClass);
                results.add(new ImmutablePair<>(typeArgument, (T) cls.newInstance()));

            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                throw new CronyxException("Could not instantiate cronyxToQuartzConverters", e);
            }
        }
        return results;
    }
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:21,代码来源:ConfigUtil.java

示例4: setup

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
@Before
public void setup() throws Exception {
	@SuppressWarnings("resource")
	GenericApplicationContext cxt = new GenericApplicationContext();
	cxt.refresh();
	this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), cxt.getBeanFactory());

	Method method = getClass().getDeclaredMethod("handleMessage",
			String.class, String.class, String.class, String.class, String.class);
	this.paramRequired = new SynthesizingMethodParameter(method, 0);
	this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 1);
	this.paramSystemProperty = new SynthesizingMethodParameter(method, 2);
	this.paramNotAnnotated = new SynthesizingMethodParameter(method, 3);
	this.paramNativeHeader = new SynthesizingMethodParameter(method, 4);

	this.paramRequired.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
	GenericTypeResolver.resolveParameterType(this.paramRequired, HeaderMethodArgumentResolver.class);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:HeaderMethodArgumentResolverTests.java

示例5: resolveHandlerArguments

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
/**
 * Resolves the arguments for the given method. Delegates to {@link #resolveCommonArgument}.
 */
private Object[] resolveHandlerArguments(Method handlerMethod, Object handler,
		NativeWebRequest webRequest, Exception thrownException) throws Exception {

	Class<?>[] paramTypes = handlerMethod.getParameterTypes();
	Object[] args = new Object[paramTypes.length];
	Class<?> handlerType = handler.getClass();
	for (int i = 0; i < args.length; i++) {
		MethodParameter methodParam = new SynthesizingMethodParameter(handlerMethod, i);
		GenericTypeResolver.resolveParameterType(methodParam, handlerType);
		Class<?> paramType = methodParam.getParameterType();
		Object argValue = resolveCommonArgument(methodParam, webRequest, thrownException);
		if (argValue != WebArgumentResolver.UNRESOLVED) {
			args[i] = argValue;
		}
		else {
			throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
					"] for @ExceptionHandler method: " + handlerMethod);
		}
	}
	return args;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:AnnotationMethodHandlerExceptionResolver.java

示例6: selectImports

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
/**
 * This implementation resolves the type of annotation from generic metadata and
 * validates that (a) the annotation is in fact present on the importing
 * {@code @Configuration} class and (b) that the given annotation has an
 * {@linkplain #getAdviceModeAttributeName() advice mode attribute} of type
 * {@link AdviceMode}.
 * <p>The {@link #selectImports(AdviceMode)} method is then invoked, allowing the
 * concrete implementation to choose imports in a safe and convenient fashion.
 * @throws IllegalArgumentException if expected annotation {@code A} is not present
 * on the importing {@code @Configuration} class or if {@link #selectImports(AdviceMode)}
 * returns {@code null}
 */
@Override
public final String[] selectImports(AnnotationMetadata importingClassMetadata) {
	Class<?> annoType = GenericTypeResolver.resolveTypeArgument(getClass(), AdviceModeImportSelector.class);
	AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(importingClassMetadata, annoType);
	if (attributes == null) {
		throw new IllegalArgumentException(String.format(
			"@%s is not present on importing class '%s' as expected",
			annoType.getSimpleName(), importingClassMetadata.getClassName()));
	}

	AdviceMode adviceMode = attributes.getEnum(this.getAdviceModeAttributeName());
	String[] imports = selectImports(adviceMode);
	if (imports == null) {
		throw new IllegalArgumentException(String.format("Unknown AdviceMode: '%s'", adviceMode));
	}
	return imports;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:AdviceModeImportSelector.java

示例7: customizeContext

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
/**
 * Customize the {@link ConfigurableWebApplicationContext} created by this
 * ContextLoader after config locations have been supplied to the context
 * but before the context is <em>refreshed</em>.
 * <p>The default implementation {@linkplain #determineContextInitializerClasses(ServletContext)
 * determines} what (if any) context initializer classes have been specified through
 * {@linkplain #CONTEXT_INITIALIZER_CLASSES_PARAM context init parameters} and
 * {@linkplain ApplicationContextInitializer#initialize invokes each} with the
 * given web application context.
 * <p>Any {@code ApplicationContextInitializers} implementing
 * {@link org.springframework.core.Ordered Ordered} or marked with @{@link
 * org.springframework.core.annotation.Order Order} will be sorted appropriately.
 * @param sc the current servlet context
 * @param wac the newly created application context
 * @see #CONTEXT_INITIALIZER_CLASSES_PARAM
 * @see ApplicationContextInitializer#initialize(ConfigurableApplicationContext)
 */
protected void customizeContext(ServletContext sc, ConfigurableWebApplicationContext wac) {
	List<Class<ApplicationContextInitializer<ConfigurableApplicationContext>>> initializerClasses =
			determineContextInitializerClasses(sc);

	for (Class<ApplicationContextInitializer<ConfigurableApplicationContext>> initializerClass : initializerClasses) {
		Class<?> initializerContextClass =
				GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class);
		if (initializerContextClass != null) {
			Assert.isAssignable(initializerContextClass, wac.getClass(), String.format(
					"Could not add context initializer [%s] since its generic parameter [%s] " +
					"is not assignable from the type of application context used by this " +
					"context loader [%s]: ", initializerClass.getName(), initializerContextClass.getName(),
					wac.getClass().getName()));
		}
		this.contextInitializers.add(BeanUtils.instantiateClass(initializerClass));
	}

	AnnotationAwareOrderComparator.sort(this.contextInitializers);
	for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : this.contextInitializers) {
		initializer.initialize(wac);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ContextLoader.java

示例8: resolvePreparedArguments

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
/**
 * Resolve the prepared arguments stored in the given bean definition.
 */
private Object[] resolvePreparedArguments(
		String beanName, RootBeanDefinition mbd, BeanWrapper bw, Member methodOrCtor, Object[] argsToResolve) {

	Class<?>[] paramTypes = (methodOrCtor instanceof Method ?
			((Method) methodOrCtor).getParameterTypes() : ((Constructor<?>) methodOrCtor).getParameterTypes());
	TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ?
			this.beanFactory.getCustomTypeConverter() : bw);
	BeanDefinitionValueResolver valueResolver =
			new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
	Object[] resolvedArgs = new Object[argsToResolve.length];
	for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
		Object argValue = argsToResolve[argIndex];
		MethodParameter methodParam = MethodParameter.forMethodOrConstructor(methodOrCtor, argIndex);
		GenericTypeResolver.resolveParameterType(methodParam, methodOrCtor.getDeclaringClass());
		if (argValue instanceof AutowiredArgumentMarker) {
			argValue = resolveAutowiredArgument(methodParam, beanName, null, converter);
		}
		else if (argValue instanceof BeanMetadataElement) {
			argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
		}
		else if (argValue instanceof String) {
			argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
		}
		Class<?> paramType = paramTypes[argIndex];
		try {
			resolvedArgs[argIndex] = converter.convertIfNecessary(argValue, paramType, methodParam);
		}
		catch (TypeMismatchException ex) {
			String methodType = (methodOrCtor instanceof Constructor ? "constructor" : "factory method");
			throw new UnsatisfiedDependencyException(
					mbd.getResourceDescription(), beanName, argIndex, paramType,
					"Could not convert " + methodType + " argument value of type [" +
					ObjectUtils.nullSafeClassName(argValue) +
					"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
		}
	}
	return resolvedArgs;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:42,代码来源:ConstructorResolver.java

示例9: registerConversion

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
private void registerConversion(Object converter) {
	Class<?> type = converter.getClass();
	boolean isWriting = type.isAnnotationPresent(WritingConverter.class);
	boolean isReading = type.isAnnotationPresent(ReadingConverter.class);

	if (!isReading && !isWriting) {
		isReading = true;
		isWriting = true;
	}

	if (converter instanceof GenericConverter) {
		GenericConverter genericConverter = (GenericConverter) converter;
		for (ConvertiblePair pair : genericConverter.getConvertibleTypes()) {
			register(new ConvertibleContext(pair, isReading, isWriting));
		}
	} else if (converter instanceof Converter) {
		Class<?>[] arguments = GenericTypeResolver.resolveTypeArguments(converter.getClass(), Converter.class);
		register(new ConvertibleContext(arguments[0], arguments[1], isReading, isWriting));
	} else {
		throw new IllegalArgumentException("Unsupported Converter type! Expected either GenericConverter if Converter.");
	}
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:23,代码来源:CustomConversions.java

示例10: registerConversion

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
/**
 * Registers a conversion for the given converter. Inspects either generics or the convertible pairs returned
 * by a {@link GenericConverter}.
 *
 * @param converter the converter to register.
 */
private void registerConversion(final Object converter) {
  Class<?> type = converter.getClass();
  boolean isWriting = type.isAnnotationPresent(WritingConverter.class);
  boolean isReading = type.isAnnotationPresent(ReadingConverter.class);

  if (converter instanceof GenericConverter) {
    GenericConverter genericConverter = (GenericConverter) converter;
    for (GenericConverter.ConvertiblePair pair : genericConverter.getConvertibleTypes()) {
      register(new ConverterRegistration(pair, isReading, isWriting));
    }
  } else if (converter instanceof Converter) {
    Class<?>[] arguments = GenericTypeResolver.resolveTypeArguments(converter.getClass(), Converter.class);
    register(new ConverterRegistration(arguments[0], arguments[1], isReading, isWriting));
  } else {
    throw new IllegalArgumentException("Unsupported Converter type!");
  }
}
 
开发者ID:KPTechnologyLab,项目名称:spring-data-crate,代码行数:24,代码来源:CustomConversions.java

示例11: getRepository

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
@Override
public <T> T getRepository(Class<T> repositoryInterface, Object customImplementation) {
	if (RevisionRepository.class.isAssignableFrom(repositoryInterface)) {
		Class<?>[] typeArguments = GenericTypeResolver.resolveTypeArguments(repositoryInterface, RevisionRepository.class);
		Class<?> revisionNumberType = typeArguments[2];

		if (!revisionEntityInformation.getRevisionNumberType().equals(revisionNumberType)) {
			throw new IllegalStateException(String.format(
					"Configured a revision entity type of %s with a revision type of %s "
							+ "but the repository interface is typed to a revision type of %s!", repositoryInterface,
					revisionEntityInformation.getRevisionNumberType(), revisionNumberType));
		}
	}

	return super.getRepository(repositoryInterface, customImplementation);
}
 
开发者ID:zakyalvan,项目名称:spring-envers-audit,代码行数:17,代码来源:RevisionAwareJpaRepositoryFactoryBean.java

示例12: resolveHandlerArguments

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
/**
 * Resolves the arguments for the given method. Delegates to {@link #resolveCommonArgument}.
 */
private Object[] resolveHandlerArguments(Method handlerMethod, Object handler,
		NativeWebRequest webRequest, Exception thrownException) throws Exception {

	Class<?>[] paramTypes = handlerMethod.getParameterTypes();
	Object[] args = new Object[paramTypes.length];
	Class<?> handlerType = handler.getClass();
	for (int i = 0; i < args.length; i++) {
		MethodParameter methodParam = new MethodParameter(handlerMethod, i);
		GenericTypeResolver.resolveParameterType(methodParam, handlerType);
		Class<?> paramType = methodParam.getParameterType();
		Object argValue = resolveCommonArgument(methodParam, webRequest, thrownException);
		if (argValue != WebArgumentResolver.UNRESOLVED) {
			args[i] = argValue;
		}
		else {
			throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
					"] for @ExceptionHandler method: " + handlerMethod);
		}
	}
	return args;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:25,代码来源:AnnotationMethodHandlerExceptionResolver.java

示例13: addFormatterForFieldAnnotation

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void addFormatterForFieldAnnotation(AnnotationFormatterFactory annotationFormatterFactory) {
	final Class<? extends Annotation> annotationType = (Class<? extends Annotation>)
			GenericTypeResolver.resolveTypeArgument(annotationFormatterFactory.getClass(), AnnotationFormatterFactory.class);
	if (annotationType == null) {
		throw new IllegalArgumentException("Unable to extract parameterized Annotation type argument from AnnotationFormatterFactory [" +
				annotationFormatterFactory.getClass().getName() + "]; does the factory parameterize the <A extends Annotation> generic type?");
	}
	if (this.embeddedValueResolver != null && annotationFormatterFactory instanceof EmbeddedValueResolverAware) {
		((EmbeddedValueResolverAware) annotationFormatterFactory).setEmbeddedValueResolver(this.embeddedValueResolver);
	}
	Set<Class<?>> fieldTypes = annotationFormatterFactory.getFieldTypes();
	for (final Class<?> fieldType : fieldTypes) {
		addConverter(new AnnotationPrinterConverter(annotationType, annotationFormatterFactory, fieldType));
		addConverter(new AnnotationParserConverter(annotationType, annotationFormatterFactory, fieldType));
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:18,代码来源:FormattingConversionService.java

示例14: loadInitializer

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private ApplicationContextInitializer<ConfigurableApplicationContext> loadInitializer(
		String className, ConfigurableApplicationContext wac) {
	try {
		Class<?> initializerClass = ClassUtils.forName(className, wac.getClassLoader());
		Class<?> initializerContextClass =
				GenericTypeResolver.resolveTypeArgument(initializerClass, ApplicationContextInitializer.class);
		if (initializerContextClass != null) {
			Assert.isAssignable(initializerContextClass, wac.getClass(), String.format(
					"Could not add context initializer [%s] since its generic parameter [%s] " +
					"is not assignable from the type of application context used by this " +
					"framework servlet [%s]: ", initializerClass.getName(), initializerContextClass.getName(),
					wac.getClass().getName()));
		}
		return BeanUtils.instantiateClass(initializerClass, ApplicationContextInitializer.class);
	}
	catch (Exception ex) {
		throw new IllegalArgumentException(String.format("Could not instantiate class [%s] specified " +
				"via 'contextInitializerClasses' init-param", className), ex);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:22,代码来源:FrameworkServlet.java

示例15: createEntityInformation

import org.springframework.core.GenericTypeResolver; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private EntityInformation<T, ID> createEntityInformation() {

    Class<T> entityType = (Class<T>) GenericTypeResolver.resolveTypeArguments(getClass(),
                                                                              JdbcRepository.class)[0];

    return createEntityInformation(entityType);
}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:9,代码来源:BaseJdbcRepository.java


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