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


Java GenericTypeResolver.resolveTypeArguments方法代码示例

本文整理汇总了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.");
	}
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:23,代码来源:CustomConversions.java

示例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!");
  }
}
 
开发者ID:KPTechnologyLab,项目名称:spring-data-crate,代码行数:24,代码来源:CustomConversions.java

示例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);
}
 
开发者ID:zakyalvan,项目名称:spring-envers-audit,代码行数:17,代码来源:RevisionAwareJpaRepositoryFactoryBean.java

示例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);
}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:9,代码来源:BaseJdbcRepository.java

示例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];
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:11,代码来源:TProtobufProcessor.java

示例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;
}
 
开发者ID:candrews,项目名称:hibernate-springcache,代码行数:10,代码来源:SpringCacheToJCache.java

示例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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:ConvertingEncoderDecoderSupport.java

示例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;
}
 
开发者ID:slyak,项目名称:spring-data-jpa-extra,代码行数:10,代码来源:RepoBasedConverter.java

示例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);
        }
    }
}
 
开发者ID:castlemock,项目名称:castlemock,代码行数:18,代码来源:ServiceRegistry.java

示例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]);
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:10,代码来源:GenericEntityTypeResolver.java

示例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];
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:10,代码来源:GenericEntityTypeResolver.java

示例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();
}
 
开发者ID:nielsbasjes,项目名称:yauaa,代码行数:65,代码来源:UserAgentAnnotationAnalyzer.java

示例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);
}
 
开发者ID:nickevin,项目名称:Qihua,代码行数:7,代码来源:JdbcRepository.java

示例14: AbstractOneWayConverter

import org.springframework.core.GenericTypeResolver; //导入方法依赖的package包/类
public AbstractOneWayConverter() {
  parameterizedTypeClass =
      GenericTypeResolver.resolveTypeArguments(this.getClass(), AbstractOneWayConverter.class);
}
 
开发者ID:epam-debrecen-rft-2015,项目名称:atsy,代码行数:5,代码来源:AbstractOneWayConverter.java

示例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;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:7,代码来源:HibernateCrudRepository.java


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