Java Code Examples for org.springframework.core.ResolvableType#getRawClass()
The following examples show how to use
org.springframework.core.ResolvableType#getRawClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UiEventListenerMethodAdapter.java From cuba with Apache License 2.0 | 6 votes |
/** * 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. */ @Nullable protected Object[] resolveArguments(ApplicationEvent event) { ResolvableType declaredEventType = getResolvableType(event); if (declaredEventType == null || declaredEventType.getRawClass() == 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}; } }
Example 2
Source File: ReturnTypeParser.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * This is a copy of GenericTypeResolver.resolveType which is not available on spring 4. * This also keeps compatibility with spring-boot 1 applications. * Resolve the given generic type against the given context class, * substituting type variables as far as possible. * @param genericType the (potentially) generic type * @param contextClass a context class for the target type, for example a class in which the target type appears in a method signature (can be {@code null}) * @return the resolved type (possibly the given generic type as-is) * @since 5.0 */ static Type resolveType(Type genericType, @Nullable Class<?> contextClass) { if (contextClass != null) { if (genericType instanceof TypeVariable) { ResolvableType resolvedTypeVariable = resolveVariable( (TypeVariable<?>) genericType, ResolvableType.forClass(contextClass)); if (resolvedTypeVariable != ResolvableType.NONE) { Class<?> resolved = resolvedTypeVariable.resolve(); if (resolved != null) { return resolved; } } } else if (genericType instanceof ParameterizedType) { ResolvableType resolvedType = ResolvableType.forType(genericType); if (resolvedType.hasUnresolvableGenerics()) { ParameterizedType parameterizedType = (ParameterizedType) genericType; Class<?>[] generics = new Class<?>[parameterizedType.getActualTypeArguments().length]; Type[] typeArguments = parameterizedType.getActualTypeArguments(); ResolvableType contextType = ResolvableType.forClass(contextClass); findTypeForGenerics(generics, typeArguments, contextType); Class<?> rawClass = resolvedType.getRawClass(); if (rawClass != null) { return ResolvableType.forClassWithGenerics(rawClass, generics).getType(); } } } } return genericType; }
Example 3
Source File: SolaceJmsAutoConfigurationTestBase.java From solace-jms-spring-boot with Apache License 2.0 | 5 votes |
static Set<Object[]> getTestParameters(Set<ResolvableType> testClasses) { Set<Object[]> parameters = new HashSet<>(); for (ResolvableType resolvableRawClass : testClasses) { Class<?> rawClass = resolvableRawClass.resolve(); StringBuilder testName = new StringBuilder(rawClass.getSimpleName()); for (ResolvableType resolvableGeneric : resolvableRawClass.getGenerics()) { Class<?> genericClass = resolvableGeneric.getRawClass(); if (genericClass != null) testName = testName.append('—').append(genericClass.getSimpleName()); } parameters.add(new Object[]{testName.toString(), rawClass}); } return parameters; }
Example 4
Source File: QuerydslJdbcRepositoryFactory.java From infobip-spring-data-querydsl with Apache License 2.0 | 5 votes |
private RelationalPathBase<?> getRelationalPathBase(RepositoryInformation repositoryInformation) { ResolvableType entityType = ResolvableType.forClass(repositoryInformation.getRepositoryInterface()) .as(QuerydslJdbcRepository.class) .getGeneric(0); if (entityType.getRawClass() == null) { throw new IllegalArgumentException("Could not resolve query class for " + repositoryInformation); } return getRelationalPathBase(getQueryClass(entityType.getRawClass())); }
Example 5
Source File: SolaceJavaAutoConfigurationTestBase.java From solace-java-spring-boot with Apache License 2.0 | 5 votes |
static Set<Object[]> getTestParameters(Set<ResolvableType> testClasses) { Set<Object[]> parameters = new HashSet<>(); for (ResolvableType resolvableRawClass : testClasses) { Class<?> rawClass = resolvableRawClass.resolve(); StringBuilder testName = new StringBuilder(rawClass.getSimpleName()); for (ResolvableType resolvableGeneric : resolvableRawClass.getGenerics()) { Class<?> genericClass = resolvableGeneric.getRawClass(); if (genericClass != null) testName = testName.append('—').append(genericClass.getSimpleName()); } parameters.add(new Object[]{testName.toString(), rawClass}); } return parameters; }
Example 6
Source File: GenericApplicationListenerAdapter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public boolean supportsEventType(ResolvableType eventType) { if (this.delegate instanceof SmartApplicationListener) { Class<? extends ApplicationEvent> eventClass = (Class<? extends ApplicationEvent>) eventType.getRawClass(); return ((SmartApplicationListener) this.delegate).supportsEventType(eventClass); } else { return (this.declaredEventType == null || this.declaredEventType.isAssignableFrom(eventType)); } }
Example 7
Source File: KafkaStreamsBindableProxyFactory.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
private void bindInput(ResolvableType arg0, String inputName) { if (arg0.getRawClass() != null) { KafkaStreamsBindableProxyFactory.this.inputHolders.put(inputName, new BoundTargetHolder(getBindingTargetFactory(arg0.getRawClass()) .createInput(inputName), true)); } BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(); rootBeanDefinition.setInstanceSupplier(() -> inputHolders.get(inputName).getBoundTarget()); registry.registerBeanDefinition(inputName, rootBeanDefinition); }
Example 8
Source File: KafkaStreamsFunctionProcessor.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
private void popuateResolvableTypeMap(ResolvableType resolvableType, Map<String, ResolvableType> resolvableTypeMap, Iterator<String> iterator) { final String next = iterator.next(); resolvableTypeMap.put(next, resolvableType.getGeneric(0)); if (resolvableType.getRawClass() != null && (resolvableType.getRawClass().isAssignableFrom(BiFunction.class) || resolvableType.getRawClass().isAssignableFrom(BiConsumer.class)) && iterator.hasNext()) { resolvableTypeMap.put(iterator.next(), resolvableType.getGeneric(1)); } }
Example 9
Source File: UiEventListenerMethodAdapter.java From cuba with Apache License 2.0 | 5 votes |
@Override public boolean supportsEventType(@Nonnull ResolvableType eventType) { for (ResolvableType declaredEventType : this.declaredEventTypes) { if (declaredEventType.isAssignableFrom(eventType)) { return true; } else if (eventType.getRawClass() != null && PayloadApplicationEvent.class.isAssignableFrom(eventType.getRawClass())) { ResolvableType payloadType = eventType.as(PayloadApplicationEvent.class).getGeneric(); if (declaredEventType.isAssignableFrom(payloadType)) { return true; } } } return eventType.hasUnresolvableGenerics(); }
Example 10
Source File: UiEventListenerMethodAdapter.java From cuba with Apache License 2.0 | 5 votes |
@Nullable protected ResolvableType getResolvableType(ApplicationEvent event) { ResolvableType payloadType = null; if (event instanceof PayloadApplicationEvent) { PayloadApplicationEvent<?> payloadEvent = (PayloadApplicationEvent<?>) event; ResolvableType resolvableType = payloadEvent.getResolvableType(); if (resolvableType != null) { payloadType = resolvableType.as(PayloadApplicationEvent.class).getGeneric(); } } for (ResolvableType declaredEventType : this.declaredEventTypes) { Class<?> rawClass = declaredEventType.getRawClass(); if (rawClass != null) { if (!ApplicationEvent.class.isAssignableFrom(rawClass) && payloadType != null) { if (declaredEventType.isAssignableFrom(payloadType)) { return declaredEventType; } } if (rawClass.isInstance(event)) { return declaredEventType; } } } return null; }
Example 11
Source File: AbstractBeanFactory.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public boolean isTypeMatch(String name, ResolvableType typeToMatch) throws NoSuchBeanDefinitionException { String beanName = transformedBeanName(name); // Check manually registered singletons. Object beanInstance = getSingleton(beanName, false); if (beanInstance != null) { if (beanInstance instanceof FactoryBean) { if (!BeanFactoryUtils.isFactoryDereference(name)) { Class<?> type = getTypeForFactoryBean((FactoryBean<?>) beanInstance); return (type != null && typeToMatch.isAssignableFrom(type)); } else { return typeToMatch.isInstance(beanInstance); } } else { return (!BeanFactoryUtils.isFactoryDereference(name) && typeToMatch.isInstance(beanInstance)); } } else if (containsSingleton(beanName) && !containsBeanDefinition(beanName)) { // null instance registered return false; } else { // No singleton instance found -> check bean definition. BeanFactory parentBeanFactory = getParentBeanFactory(); if (parentBeanFactory != null && !containsBeanDefinition(beanName)) { // No bean definition found in this factory -> delegate to parent. return parentBeanFactory.isTypeMatch(originalBeanName(name), typeToMatch); } // Retrieve corresponding bean definition. RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName); Class<?> classToMatch = typeToMatch.getRawClass(); Class<?>[] typesToMatch = (FactoryBean.class == classToMatch ? new Class<?>[] {classToMatch} : new Class<?>[] {FactoryBean.class, classToMatch}); // Check decorated bean definition, if any: We assume it'll be easier // to determine the decorated bean's type than the proxy's type. BeanDefinitionHolder dbd = mbd.getDecoratedDefinition(); if (dbd != null && !BeanFactoryUtils.isFactoryDereference(name)) { RootBeanDefinition tbd = getMergedBeanDefinition(dbd.getBeanName(), dbd.getBeanDefinition(), mbd); Class<?> targetClass = predictBeanType(dbd.getBeanName(), tbd, typesToMatch); if (targetClass != null && !FactoryBean.class.isAssignableFrom(targetClass)) { return typeToMatch.isAssignableFrom(targetClass); } } Class<?> beanType = predictBeanType(beanName, mbd, typesToMatch); if (beanType == null) { return false; } // Check bean class whether we're dealing with a FactoryBean. if (FactoryBean.class.isAssignableFrom(beanType)) { if (!BeanFactoryUtils.isFactoryDereference(name)) { // If it's a FactoryBean, we want to look at what it creates, not the factory class. beanType = getTypeForFactoryBean(beanName, mbd); if (beanType == null) { return false; } } } else if (BeanFactoryUtils.isFactoryDereference(name)) { // Special case: A SmartInstantiationAwareBeanPostProcessor returned a non-FactoryBean // type but we nevertheless are being asked to dereference a FactoryBean... // Let's check the original bean class and proceed with it if it is a FactoryBean. beanType = predictBeanType(beanName, mbd, FactoryBean.class); if (beanType == null || !FactoryBean.class.isAssignableFrom(beanType)) { return false; } } return typeToMatch.isAssignableFrom(beanType); } }
Example 12
Source File: KafkaStreamsBindableProxyFactory.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 4 votes |
@Override public void afterPropertiesSet() { Assert.notEmpty(KafkaStreamsBindableProxyFactory.this.bindingTargetFactories, "'bindingTargetFactories' cannot be empty"); int resolvableTypeDepthCounter = 0; ResolvableType argument = this.type.getGeneric(resolvableTypeDepthCounter++); List<String> inputBindings = buildInputBindings(); Iterator<String> iterator = inputBindings.iterator(); String next = iterator.next(); bindInput(argument, next); if (this.type.getRawClass() != null && (this.type.getRawClass().isAssignableFrom(BiFunction.class) || this.type.getRawClass().isAssignableFrom(BiConsumer.class))) { argument = this.type.getGeneric(resolvableTypeDepthCounter++); next = iterator.next(); bindInput(argument, next); } ResolvableType outboundArgument = this.type.getGeneric(resolvableTypeDepthCounter); while (isAnotherFunctionOrConsumerFound(outboundArgument)) { //The function is a curried function. We should introspect the partial function chain hierarchy. argument = outboundArgument.getGeneric(0); String next1 = iterator.next(); bindInput(argument, next1); outboundArgument = outboundArgument.getGeneric(1); } //Introspect output for binding. if (outboundArgument != null && outboundArgument.getRawClass() != null && (!outboundArgument.isArray() && outboundArgument.getRawClass().isAssignableFrom(KStream.class))) { // if the type is array, we need to do a late binding as we don't know the number of // output bindings at this point in the flow. List<String> outputBindings = streamFunctionProperties.getOutputBindings(this.functionName); String outputBinding = null; if (!CollectionUtils.isEmpty(outputBindings)) { Iterator<String> outputBindingsIter = outputBindings.iterator(); if (outputBindingsIter.hasNext()) { outputBinding = outputBindingsIter.next(); } } else { outputBinding = String.format("%s-%s-0", this.functionName, FunctionConstants.DEFAULT_OUTPUT_SUFFIX); } Assert.isTrue(outputBinding != null, "output binding is not inferred."); KafkaStreamsBindableProxyFactory.this.outputHolders.put(outputBinding, new BoundTargetHolder(getBindingTargetFactory(KStream.class) .createOutput(outputBinding), true)); String outputBinding1 = outputBinding; RootBeanDefinition rootBeanDefinition1 = new RootBeanDefinition(); rootBeanDefinition1.setInstanceSupplier(() -> outputHolders.get(outputBinding1).getBoundTarget()); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; registry.registerBeanDefinition(outputBinding1, rootBeanDefinition1); } }
Example 13
Source File: KafkaStreamsBindableProxyFactory.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 4 votes |
private boolean isAnotherFunctionOrConsumerFound(ResolvableType arg1) { return arg1 != null && !arg1.isArray() && arg1.getRawClass() != null && (arg1.getRawClass().isAssignableFrom(Function.class) || arg1.getRawClass().isAssignableFrom(Consumer.class)); }
Example 14
Source File: KeyValueSerdeResolver.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 4 votes |
private boolean isResolvalbeKafkaStreamsType(ResolvableType resolvableType) { return resolvableType.getRawClass() != null && (KStream.class.isAssignableFrom(resolvableType.getRawClass()) || KTable.class.isAssignableFrom(resolvableType.getRawClass()) || GlobalKTable.class.isAssignableFrom(resolvableType.getRawClass())); }
Example 15
Source File: KafkaStreamsFunctionProcessor.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 4 votes |
private Map<String, ResolvableType> buildTypeMap(ResolvableType resolvableType, KafkaStreamsBindableProxyFactory kafkaStreamsBindableProxyFactory) { Map<String, ResolvableType> resolvableTypeMap = new LinkedHashMap<>(); if (resolvableType != null && resolvableType.getRawClass() != null) { int inputCount = 1; ResolvableType currentOutputGeneric; if (resolvableType.getRawClass().isAssignableFrom(BiFunction.class) || resolvableType.getRawClass().isAssignableFrom(BiConsumer.class)) { inputCount = 2; currentOutputGeneric = resolvableType.getGeneric(2); } else { currentOutputGeneric = resolvableType.getGeneric(1); } while (currentOutputGeneric.getRawClass() != null && functionOrConsumerFound(currentOutputGeneric)) { inputCount++; currentOutputGeneric = currentOutputGeneric.getGeneric(1); } final Set<String> inputs = new LinkedHashSet<>(kafkaStreamsBindableProxyFactory.getInputs()); final Iterator<String> iterator = inputs.iterator(); popuateResolvableTypeMap(resolvableType, resolvableTypeMap, iterator); ResolvableType iterableResType = resolvableType; int i = resolvableType.getRawClass().isAssignableFrom(BiFunction.class) || resolvableType.getRawClass().isAssignableFrom(BiConsumer.class) ? 2 : 1; ResolvableType outboundResolvableType; if (i == inputCount) { outboundResolvableType = iterableResType.getGeneric(i); } else { while (i < inputCount && iterator.hasNext()) { iterableResType = iterableResType.getGeneric(1); if (iterableResType.getRawClass() != null && functionOrConsumerFound(iterableResType)) { popuateResolvableTypeMap(iterableResType, resolvableTypeMap, iterator); } i++; } outboundResolvableType = iterableResType.getGeneric(1); } resolvableTypeMap.put(OUTBOUND, outboundResolvableType); } return resolvableTypeMap; }
Example 16
Source File: GeodeLoggingApplicationListener.java From spring-boot-data-geode with Apache License 2.0 | 3 votes |
@Override public boolean supportsEventType(@NonNull ResolvableType eventType) { Class<?> rawType = eventType.getRawClass(); return rawType != null && Arrays.stream(EVENT_TYPES).anyMatch(it -> it.isAssignableFrom(rawType)); }