本文整理汇总了Java中org.springframework.core.ResolvableType类的典型用法代码示例。如果您正苦于以下问题:Java ResolvableType类的具体用法?Java ResolvableType怎么用?Java ResolvableType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResolvableType类属于org.springframework.core包,在下文中一共展示了ResolvableType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveVariable
import org.springframework.core.ResolvableType; //导入依赖的package包/类
private static ResolvableType resolveVariable(TypeVariable<?> typeVariable, ResolvableType contextType) {
ResolvableType resolvedType;
if (contextType.hasGenerics()) {
resolvedType = ResolvableType.forType(typeVariable, contextType);
if (resolvedType.resolve() != null) {
return resolvedType;
}
}
ResolvableType superType = contextType.getSuperType();
if (superType != ResolvableType.NONE) {
resolvedType = resolveVariable(typeVariable, superType);
if (resolvedType.resolve() != null) {
return resolvedType;
}
}
for (ResolvableType ifc : contextType.getInterfaces()) {
resolvedType = resolveVariable(typeVariable, ifc);
if (resolvedType.resolve() != null) {
return resolvedType;
}
}
return ResolvableType.NONE;
}
示例2: ServiceInfoPropertySourceAdapter
import org.springframework.core.ResolvableType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ServiceInfoPropertySourceAdapter() {
Cloud cloud;
try {
cloud = new CloudFactory().getCloud();
}
catch (CloudException e) {
// not running on a known cloud environment, so nothing to do
cloud = null;
}
this.cloud = cloud;
this.serviceInfoType = (Class) ResolvableType.forClass(getClass()).getSuperType()
.getGeneric(0).getRawClass();
}
开发者ID:pivotal-cf,项目名称:spring-cloud-vault-connector,代码行数:18,代码来源:ServiceInfoPropertySourceAdapter.java
示例3: multicastEvent
import org.springframework.core.ResolvableType; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void multicastEvent(ApplicationEvent event, ResolvableType eventType) {
ResolvableType type = eventType == null ? ResolvableType.forInstance(event) : eventType;
Collection<ApplicationListener<?>> listeners = getApplicationListeners(event, type);
if (listeners.isEmpty()) {
return;
}
List<ApplicationListener<?>> transactionalListeners = listeners.stream()//
.filter(PersistentApplicationEventMulticaster::isTransactionalApplicationEventListener)//
.collect(Collectors.toList());
if (!transactionalListeners.isEmpty()) {
Object eventToPersist = getEventToPersist(event);
registry.getObject().store(eventToPersist, transactionalListeners);
// EventStore.persist(eventThis)
// SpringMVC Controller Atom Feed
}
for (ApplicationListener listener : listeners) {
listener.onApplicationEvent(event);
}
}
开发者ID:olivergierke,项目名称:spring-domain-events,代码行数:29,代码来源:PersistentApplicationEventMulticaster.java
示例4: registerBeans
import org.springframework.core.ResolvableType; //导入依赖的package包/类
@Override
protected void registerBeans(InjectRpcClient annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
String tag = annotation.tag().isEmpty() ? "" : '#' + annotation.tag();
String name = RpcClientBean.class.getName() + tag + "-" + targetType.toString();
if (!registry.containsBeanDefinition(name)) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(RpcClientBean.class)
.setLazyInit(true)
.addPropertyValue("rpcInterface", targetType.getType().getTypeName());
if (!annotation.tag().isEmpty()) {
builder.addPropertyValue("tag", annotation.tag());
}
AbstractBeanDefinition def = builder.getBeanDefinition();
AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(annotation.annotationType());
if (!annotation.tag().isEmpty()) {
qualifier.setAttribute("tag", annotation.tag());
}
def.addQualifier(qualifier);
registry.registerBeanDefinition(name, def);
}
}
示例5: registerBeans
import org.springframework.core.ResolvableType; //导入依赖的package包/类
@Override
protected void registerBeans(InjectLock annotation, ResolvableType targetType, BeanDefinitionRegistry registry) {
String name = LockBean.class.getName() + "-" + annotation.name() + "--" + annotation.name();
if (!registry.containsBeanDefinition(name)) {
AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(LockBean.class)
.setLazyInit(true)
.addPropertyValue("region", annotation.region())
.addPropertyValue("name", annotation.name())
.getBeanDefinition();
AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(annotation.annotationType());
qualifier.addMetadataAttribute(new BeanMetadataAttribute("region", annotation.region()));
qualifier.addMetadataAttribute(new BeanMetadataAttribute("name", annotation.name()));
def.addQualifier(qualifier);
registry.registerBeanDefinition(name, def);
}
}
示例6: getReturnTypeForFactoryMethod
import org.springframework.core.ResolvableType; //导入依赖的package包/类
protected ResolvableType getReturnTypeForFactoryMethod(RootBeanDefinition rbd, DependencyDescriptor descriptor) {
// Should typically be set for any kind of factory method, since the BeanFactory
// pre-resolves them before reaching out to the AutowireCandidateResolver...
Class<?> preResolved = rbd.resolvedFactoryMethodReturnType;
if (preResolved != null) {
return ResolvableType.forClass(preResolved);
}
else {
Method resolvedFactoryMethod = rbd.getResolvedFactoryMethod();
if (resolvedFactoryMethod != null) {
if (descriptor.getDependencyType().isAssignableFrom(resolvedFactoryMethod.getReturnType())) {
// Only use factory method metadata if the return type is actually expressive enough
// for our dependency. Otherwise, the returned instance type may have matched instead
// in case of a singleton instance having been registered with the container already.
return ResolvableType.forMethodReturnType(resolvedFactoryMethod);
}
}
return null;
}
}
示例7: buildConvertersMap
import org.springframework.core.ResolvableType; //导入依赖的package包/类
private void buildConvertersMap() {
beanFactory.getBeansWithAnnotation(Converted.class).values()
.forEach(bean -> {
ResolvableType beanType = ResolvableType.forClass(bean.getClass());
Optional<ResolvableType> converterInterface = Arrays.stream(beanType.getInterfaces())
.filter(iface -> iface.resolve().isAssignableFrom(TypedEventConverter.class))
.findAny();
if (converterInterface.isPresent()) {
ResolvableType genericType = converterInterface.get().getGeneric(0);
if (genericType.equals(ResolvableType.NONE))
throw new RuntimeException("TypedEventConverter must be generified with an event type");
typedConverters.put(genericType.getRawClass(), (TypedEventConverter) bean);
} else {
throw new RuntimeException(
"Beans annotated with @Converted must implement TypedEventConverter"
);
}
});
}
示例8: parseValue
import org.springframework.core.ResolvableType; //导入依赖的package包/类
/**
* Parses a simple value
*
* @param value the value
* @param type the value type
* @return parsed result
*/
private Object parseValue(final Object value, final ResolvableType type) {
Object returnVar = null;
if (isTypeStandard(type.getRawClass())) {
returnVar = value;
} else if (isValueCSVDatabaseIndexes(type)) {
returnVar = parseCSVDatabaseIndexes(value.toString(), type.getGeneric(0).getRawClass());
} else if (isValueDateTime(value, type)) {
returnVar = parseDateTime(value);
} else if (isValueDatabaseIndex(type)) {
returnVar = parseDatabaseIndex(value.toString(), type.getRawClass());
} else if (isValuePeriod(type)) {
returnVar = parsePeriod(value.toString());
} else if (isValueEnum(type)) {
returnVar = parseEnum(value.toString(), type.getRawClass());
}
return returnVar;
}
示例9: parseFlowTxOperate
import org.springframework.core.ResolvableType; //导入依赖的package包/类
private static FlowTxExecutor.FlowTxOperateExecutor parseFlowTxOperate(Method method) {
logger.debug("解析流程事务方法:{}", method);
// 校验方法类型
if (!Modifier.isPublic(method.getModifiers())) {
throw new IllegalArgumentException("流程事务方法" + ClassUtils.getQualifiedMethodName(method) + "必须是public类型");
}
// 校验入参
Class[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length != 1) {
throw new IllegalArgumentException("流程事务方法" + ClassUtils.getQualifiedMethodName(method) + "的入参必须是(TargetContext)");
}
if (parameterTypes[0] != TargetContext.class) {
throw new IllegalArgumentException("流程事务方法" + ClassUtils.getQualifiedMethodName(method) + "的入参必须是(TargetContext)");
}
// 获取目标对象类型
ResolvableType resolvableType = ResolvableType.forMethodParameter(method, 0);
Class classOfTarget = resolvableType.getGeneric(0).resolve(Object.class);
// 校验返回参数
if (method.getReturnType() != classOfTarget) {
throw new IllegalArgumentException("流程事务方法" + ClassUtils.getQualifiedMethodName(method) + "的返回类型必须是目标对象类型");
}
return new FlowTxExecutor.FlowTxOperateExecutor(method, classOfTarget);
}
示例10: parseProcessorMethod
import org.springframework.core.ResolvableType; //导入依赖的package包/类
/**
* 解析处理器方法
*/
private static ProcessorMethodExecutor parseProcessorMethod(Class clazz, Method method) {
logger.debug("解析处理器方法:{}", method);
// 校验方法类型
if (!Modifier.isPublic(method.getModifiers())) {
throw new IllegalArgumentException("处理器方法" + ClassUtils.getQualifiedMethodName(method) + "必须是public类型");
}
// 校验入参
Class[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length != 1) {
throw new IllegalArgumentException("处理器方法" + ClassUtils.getQualifiedMethodName(method) + "入参必须是(TargetContext)");
}
if (parameterTypes[0] != TargetContext.class) {
throw new IllegalArgumentException("处理器方法" + ClassUtils.getQualifiedMethodName(method) + "入参必须是(TargetContext)");
}
// 校验返回类型
if (clazz != ProcessorExecute.class && method.getReturnType() != void.class) {
throw new IllegalArgumentException("非@ProcessorExecute类型的处理器方法" + ClassUtils.getQualifiedMethodName(method) + "的返回类型必须是void");
}
// 获取目标对象类型
ResolvableType resolvableType = ResolvableType.forMethodParameter(method, 0);
Class classOfTarget = resolvableType.getGeneric(0).resolve(Object.class);
return new ProcessorMethodExecutor(method, classOfTarget);
}
示例11: configureBeanGrid
import org.springframework.core.ResolvableType; //导入依赖的package包/类
@Bean
@Scope(scopeName = "prototype")
@SuppressWarnings("unchecked")
public <ITEM> Grid<ITEM> configureBeanGrid(DependencyDescriptor dependencyDescriptor) {
logger.debug("Configuring Vaadin Grid as bean");
long timestamp = System.currentTimeMillis();
ResolvableType injectionPointType = dependencyDescriptor.getResolvableType();
if (!injectionPointType.hasGenerics()) {
throw new IllegalStateException("Grid injection point is expected to declare a static item type");
}
ResolvableType genericType = injectionPointType.getGeneric();
Class<ITEM> itemType = (Class<ITEM>) genericType.resolve();
logger.debug("Vaadin Grid will use " + itemType.getCanonicalName() + " as item type");
Grid<ITEM> grid = configureGridInstance(itemType);
long configTime = System.currentTimeMillis() - timestamp;
logger.debug("Done configuring Grid for " + itemType.getName() + " in " + configTime + "ms");
return grid;
}
示例12: findValueProvider
import org.springframework.core.ResolvableType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <PROPERTY_TYPE> BeanGridValueProvider<PROPERTY_TYPE> findValueProvider(Class<PROPERTY_TYPE> propertyType) {
if (Number.class.isAssignableFrom(propertyType)) {
propertyType = (Class<PROPERTY_TYPE>) Number.class;
}
ResolvableType valueProviderType = ResolvableType.forClassWithGenerics(BeanGridValueProvider.class,
propertyType);
List<String> valueProviderNames = Arrays.asList(appContext.getBeanNamesForType(valueProviderType));
if (valueProviderNames.isEmpty()) {
return (BeanGridValueProvider<PROPERTY_TYPE>) appContext.getBean(BeanGridDefaultValueProvider.class);
}
if (valueProviderNames.size() == 1) {
return appContext.getBean(valueProviderNames.iterator().next(), BeanGridValueProvider.class);
}
throw new ColumnDefinitionException("Could not find unique " + BeanGridValueProvider.class.getSimpleName()
+ " for type " + propertyType.getSimpleName());
}
示例13: init
import org.springframework.core.ResolvableType; //导入依赖的package包/类
@Override
public void init(Method listenMethod) {
ConfigListener configListenerAnnotation = AnnotatedElementUtils.findMergedAnnotation(listenMethod.getDeclaringClass(), ConfigListener.class);
if (configListenerAnnotation == null) {
throw new IllegalArgumentException("@ListenConfigModified只能标注在配置监听器(@ConfigListener)的方法上");
}
// 校验入参
Class[] parameterTypes = listenMethod.getParameterTypes();
if (parameterTypes.length != 1) {
throw new RuntimeException("监听配置被修改方法" + ClassUtils.getQualifiedMethodName(listenMethod) + "的入参必须是(List<ModifiedProperty>)");
}
if (parameterTypes[0] != List.class) {
throw new RuntimeException("监听配置被修改方法" + ClassUtils.getQualifiedMethodName(listenMethod) + "的入参必须是(List<ModifiedProperty>)");
}
ResolvableType resolvableType = ResolvableType.forMethodParameter(listenMethod, 0);
if (resolvableType.getGeneric(0).resolve(Object.class) != ModifiedProperty.class) {
throw new RuntimeException("监听配置被修改方法" + ClassUtils.getQualifiedMethodName(listenMethod) + "的入参必须是(List<ModifiedProperty>)");
}
// 设置事件类型
ListenConfigModified listenConfigModifiedAnnotation = AnnotatedElementUtils.findMergedAnnotation(listenMethod, ListenConfigModified.class);
eventType = new ConfigModifiedEventType(configListenerAnnotation.configContextName(), listenConfigModifiedAnnotation.prefix());
}
示例14: resolveArguments
import org.springframework.core.ResolvableType; //导入依赖的package包/类
/**
* Resolve the method arguments to use for the specified {@link ApplicationEvent}.
* <p>These arguments will be used to invoke the method handled by this instance. Can
* return {@code null} to indicate that no suitable arguments could be resolved and
* therefore the method should not be invoked at all for the specified event.
*/
protected Object[] resolveArguments(ApplicationEvent event) {
ResolvableType declaredEventType = getResolvableType(event);
if (declaredEventType == null) {
return null;
}
if (this.method.getParameterTypes().length == 0) {
return new Object[0];
}
if (!ApplicationEvent.class.isAssignableFrom(declaredEventType.getRawClass())
&& event instanceof PayloadApplicationEvent) {
return new Object[] {((PayloadApplicationEvent) event).getPayload()};
}
else {
return new Object[] {event};
}
}
示例15: resolveDeclaredEventTypes
import org.springframework.core.ResolvableType; //导入依赖的package包/类
private List<ResolvableType> resolveDeclaredEventTypes() {
int count = this.method.getParameterTypes().length;
if (count > 1) {
throw new IllegalStateException(
"Maximum one parameter is allowed for event listener method: " + this.method);
}
EventListener ann = getEventListener();
if (ann != null && ann.classes().length > 0) {
List<ResolvableType> types = new ArrayList<ResolvableType>();
for (Class<?> eventType : ann.classes()) {
types.add(ResolvableType.forClass(eventType));
}
return types;
}
else {
if (count == 0) {
throw new IllegalStateException(
"Event parameter is mandatory for event listener method: " + this.method);
}
return Collections.singletonList(ResolvableType.forMethodParameter(this.method, 0));
}
}