本文整理汇总了Java中org.springframework.core.GenericTypeResolver.resolveTypeArguments方法的典型用法代码示例。如果您正苦于以下问题:Java GenericTypeResolver.resolveTypeArguments方法的具体用法?Java GenericTypeResolver.resolveTypeArguments怎么用?Java GenericTypeResolver.resolveTypeArguments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.core.GenericTypeResolver
的用法示例。
在下文中一共展示了GenericTypeResolver.resolveTypeArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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.");
}
}
示例2: 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!");
}
}
示例3: 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);
}
示例4: 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);
}
示例5: getParameterizedType
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
private Class<?> getParameterizedType(Object target) throws TException {
Class<?>[] arguments = GenericTypeResolver.resolveTypeArguments(
target.getClass(), Controller.class);
if (arguments.length != 2)
throw new TException(
"Error to resolve request type, please make sure "
+ target.getClass()
+ " has provided type arguments for Controller class.");
return arguments[0];
}
示例6: SpringCacheToJCache
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public SpringCacheToJCache(final CacheManager cacheManager, final org.springframework.cache.Cache springCache) {
super();
final Class<?>[] genericArguments = GenericTypeResolver.resolveTypeArguments(
getClass(), SpringCacheToJCache.class );
this.cacheManager = cacheManager;
this.valueClass = (Class<V>) (genericArguments == null ? Object.class : genericArguments[1]);
this.springCache = springCache;
}
示例7: resolveTypeArguments
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
private Class<?>[] resolveTypeArguments() {
Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(getClass(), ConvertingEncoderDecoderSupport.class);
if (resolved == null) {
throw new IllegalStateException("ConvertingEncoderDecoderSupport's generic types T and M " +
"need to be substituted in subclass: " + getClass());
}
return resolved;
}
示例8: setApplicationContext
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
Class<?>[] classes = GenericTypeResolver.resolveTypeArguments(this.getClass(), RepoBasedConverter.class);
Class<?> clazz = classes[0];
this.repositories = new Repositories(context);
this.entityInformation = (JpaEntityInformation<S, ID>) repositories.getEntityInformationFor(clazz);
this.genericJpaRepository = (GenericJpaRepository<S, ID>) repositories.getRepositoryFor(clazz);
this.useCache = genericJpaRepository instanceof CachingJpaRepository;
}
示例9: initialize
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
/**
* The initialize method is responsible for initializing the service registry.
* The initialize method will search for all the classes with the @service annotation and
* store all the classes that are an instance of the Service class.
*/
public void initialize(){
final Map<String, Object> components = applicationContext.getBeansWithAnnotation(org.springframework.stereotype.Service.class);
for(Map.Entry<String, Object> entry : components.entrySet()){
final Object value = entry.getValue();
if(value instanceof Service){
final Service service = (Service) value;
final Class<?>[] processorInputOutputClasses = GenericTypeResolver.resolveTypeArguments(service.getClass(), Service.class);
final Class<I> processorInputClass = (Class<I>) processorInputOutputClasses[0];
services.put(processorInputClass, service);
}
}
}
示例10: resolveTypeParameters
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
/**
* @return the resolved entity key type parameter (K) and entity type parameter (E), or {@code null} if not resolvable
*/
@SuppressWarnings("unchecked")
public static <K extends Serializable & Comparable<K>, E extends GenericEntity<K, E>>
Pair<Class<K>, Class<E>> resolveTypeParameters(Class<? extends E> clazz) {
Class<?>[] typeParameters = GenericTypeResolver.resolveTypeArguments(clazz, GenericEntity.class);
return typeParameters == null ? null : Pair.of((Class<K>) typeParameters[0], (Class<E>) typeParameters[1]);
}
示例11: resolveKeyTypeParameter
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
/**
* @return the resolved entity key type parameter (K), or {@code null} if not resolvable
*/
@SuppressWarnings("unchecked")
public static <K extends Serializable & Comparable<K>, E extends GenericEntity<K, ?>>
Class<K> resolveKeyTypeParameter(Class<E> clazz) {
Class<?>[] typeParameters = GenericTypeResolver.resolveTypeArguments(clazz, GenericEntity.class);
return typeParameters == null ? null : (Class<K>) typeParameters[0];
}
示例12: initialize
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
public void initialize(UserAgentAnnotationMapper<T> theMapper) {
mapper = theMapper;
if (mapper == null) {
throw new InvalidParserConfigurationException("The mapper instance is null.");
}
Class classOfT = GenericTypeResolver.resolveTypeArguments(mapper.getClass(), UserAgentAnnotationMapper.class)[0];
if (classOfT == null) {
throw new InvalidParserConfigurationException("Couldn't find the used annotation.");
}
// Get all methods of the correct signature that have been annotated with YauaaField
for (final Method method : mapper.getClass().getDeclaredMethods()) {
final YauaaField field = method.getAnnotation(YauaaField.class);
if (field != null) {
final Class<?> returnType = method.getReturnType();
final Class<?>[] parameters = method.getParameterTypes();
if (returnType.getCanonicalName().equals("void") &&
parameters.length == 2 &&
parameters[0] == classOfT &&
parameters[1] == String.class) {
if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(classOfT.getModifiers())) {
throw new InvalidParserConfigurationException("Method annotated with YauaaField is not public: " +
method.getName());
}
if (method.getDeclaringClass().isAnonymousClass()) {
String methodName =
method.getReturnType().getName() + " " +
method.getName() + "(" +
parameters[0].getSimpleName()+ " ," +
parameters[1].getSimpleName()+ ");";
LOG.warn("Trying to make anonymous {} {} accessible.", method.getDeclaringClass(), methodName);
method.setAccessible(true);
}
for (String fieldName : field.value()) {
List<Method> methods = fieldSetters
.computeIfAbsent(fieldName, k -> new ArrayList<>());
methods.add(method);
}
} else {
throw new InvalidParserConfigurationException(
"In class [" + method.getDeclaringClass() + "] the method [" + method.getName() + "] " +
"has been annotated with YauaaField but it has the wrong method signature. " +
"It must look like [ public void " + method.getName() + "(" + classOfT.getSimpleName() + " record, String value) ]");
}
}
}
if (fieldSetters.isEmpty()) {
throw new InvalidParserConfigurationException("You MUST specify at least 1 field to extract.");
}
UserAgentAnalyzerBuilder builder = UserAgentAnalyzer.newBuilder();
builder.hideMatcherLoadStats();
if (!fieldSetters.isEmpty()) {
builder.withFields(fieldSetters.keySet());
}
userAgentAnalyzer = builder.build();
}
示例13: createEntityInformation
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private EntityInformation<T, ID> createEntityInformation() {
Class<T> clazz = (Class<T>) GenericTypeResolver.resolveTypeArguments(getClass(), JdbcRepository.class)[0];
return new ReflectionEntityInformation(clazz);
}
示例14: AbstractOneWayConverter
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
public AbstractOneWayConverter() {
parameterizedTypeClass =
GenericTypeResolver.resolveTypeArguments(this.getClass(), AbstractOneWayConverter.class);
}
示例15: HibernateCrudRepository
import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public HibernateCrudRepository() {
Class<?>[] classes = GenericTypeResolver.resolveTypeArguments(this.getClass(), Repository.class);
domainClass = (classes != null && classes.length == 2) ? (Class<T>) classes[0] : null;
}