Java Code Examples for org.springframework.core.ResolvableType#forInstance()
The following examples show how to use
org.springframework.core.ResolvableType#forInstance() .
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: AppConfig.java From flow-platform-x with Apache License 2.0 | 6 votes |
@Bean(name = "applicationEventMulticaster") public ApplicationEventMulticaster simpleApplicationEventMulticaster() { SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster() { @Override public void multicastEvent(ApplicationEvent event, ResolvableType eventType) { if (event instanceof SyncEvent) { ResolvableType type = (eventType != null ? eventType : ResolvableType.forInstance(event)); for (final ApplicationListener<?> listener : getApplicationListeners(event, type)) { invokeListener(listener, event); } return; } super.multicastEvent(event, eventType); } }; SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor("s-event-"); multicaster.setTaskExecutor(executor); return multicaster; }
Example 2
Source File: AbstractEncoderMethodReturnValueHandler.java From spring-analysis-note with MIT License | 5 votes |
@SuppressWarnings("unchecked") private Flux<DataBuffer> encodeContent( @Nullable Object content, MethodParameter returnType, DataBufferFactory bufferFactory, @Nullable MimeType mimeType, Map<String, Object> hints) { ResolvableType returnValueType = ResolvableType.forMethodParameter(returnType); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(returnValueType.resolve(), content); Publisher<?> publisher; ResolvableType elementType; if (adapter != null) { publisher = adapter.toPublisher(content); boolean isUnwrapped = KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(returnType.getContainingClass()) && KotlinDelegate.isSuspend(returnType.getMethod()) && !COROUTINES_FLOW_CLASS_NAME.equals(returnValueType.toClass().getName()); ResolvableType genericType = isUnwrapped ? returnValueType : returnValueType.getGeneric(); elementType = getElementType(adapter, genericType); } else { publisher = Mono.justOrEmpty(content); elementType = (returnValueType.toClass() == Object.class && content != null ? ResolvableType.forInstance(content) : returnValueType); } if (elementType.resolve() == void.class || elementType.resolve() == Void.class) { return Flux.from(publisher).cast(DataBuffer.class); } Encoder<?> encoder = getEncoder(elementType, mimeType); return Flux.from((Publisher) publisher).map(value -> encodeValue(value, elementType, encoder, bufferFactory, mimeType, hints)); }
Example 3
Source File: HttpMessageWriterView.java From spring-analysis-note with MIT License | 5 votes |
private boolean isMatch(Map.Entry<String, ?> entry) { if (entry.getValue() == null) { return false; } if (!getModelKeys().isEmpty() && !getModelKeys().contains(entry.getKey())) { return false; } ResolvableType type = ResolvableType.forInstance(entry.getValue()); return getMessageWriter().canWrite(type, null); }
Example 4
Source File: HttpMessageWriterView.java From java-technology-stack with MIT License | 5 votes |
private boolean isMatch(Map.Entry<String, ?> entry) { if (entry.getValue() == null) { return false; } if (!getModelKeys().isEmpty() && !getModelKeys().contains(entry.getKey())) { return false; } ResolvableType type = ResolvableType.forInstance(entry.getValue()); return getMessageWriter().canWrite(type, null); }
Example 5
Source File: MetadataEncoder.java From spring-cloud-rsocket with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private <T> DataBuffer encodeEntry(Object metadata, MimeType mimeType) { if (metadata instanceof ByteBuf) { return asDataBuffer((ByteBuf) metadata); } ResolvableType type = ResolvableType.forInstance(metadata); Encoder<T> encoder = this.strategies.encoder(type, mimeType); Assert.notNull(encoder, () -> "No encoder for metadata " + metadata + ", mimeType '" + mimeType + "'"); return encoder.encodeValue((T) metadata, bufferFactory(), type, mimeType, Collections.emptyMap()); }
Example 6
Source File: PersistentApplicationEventMulticaster.java From spring-domain-events with Apache License 2.0 | 5 votes |
@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.get().store(eventToPersist, transactionalListeners); } for (ApplicationListener listener : listeners) { EventPublication publication = CompletableEventPublication.of(event, PublicationTargetIdentifier.forListener(listener)); executeListenerWithCompletion(publication, listener); } }
Example 7
Source File: DataPrepEventsCaster.java From data-prep with Apache License 2.0 | 5 votes |
@Override public void multicastEvent(final ApplicationEvent event, ResolvableType eventType) { ResolvableType type = (eventType != null ? eventType : ResolvableType.forInstance(event)); for (final ApplicationListener<?> listener : getApplicationListeners(event, type)) { if (AsyncApplicationListener.class.isAssignableFrom(listener.getClass())) { LOGGER.trace("processing {} asynchronously to {}", event, listener); getTaskExecutor().execute(() -> invokeListener(listener, event)); } else { LOGGER.trace("processing {} synchronously to {}", event, listener); invokeListener(listener, event); } } }
Example 8
Source File: SimpleApplicationEventMulticaster.java From spring-analysis-note with MIT License | 4 votes |
private ResolvableType resolveDefaultEventType(ApplicationEvent event) { return ResolvableType.forInstance(event); }
Example 9
Source File: AbstractMessageWriterResultHandler.java From spring-analysis-note with MIT License | 4 votes |
/** * Write a given body to the response with {@link HttpMessageWriter}. * @param body the object to write * @param bodyParameter the {@link MethodParameter} of the body to write * @param actualParam the actual return type of the method that returned the value; * could be different from {@code bodyParameter} when processing {@code HttpEntity} * for example * @param exchange the current exchange * @return indicates completion or error * @since 5.0.2 */ @SuppressWarnings({"unchecked", "rawtypes", "ConstantConditions"}) protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParameter, @Nullable MethodParameter actualParam, ServerWebExchange exchange) { ResolvableType bodyType = ResolvableType.forMethodParameter(bodyParameter); ResolvableType actualType = (actualParam != null ? ResolvableType.forMethodParameter(actualParam) : bodyType); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(bodyType.resolve(), body); Publisher<?> publisher; ResolvableType elementType; ResolvableType actualElementType; if (adapter != null) { publisher = adapter.toPublisher(body); boolean isUnwrapped = KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(bodyParameter.getContainingClass()) && KotlinDelegate.isSuspend(bodyParameter.getMethod()) && !COROUTINES_FLOW_CLASS_NAME.equals(bodyType.toClass().getName()); ResolvableType genericType = isUnwrapped ? bodyType : bodyType.getGeneric(); elementType = getElementType(adapter, genericType); actualElementType = elementType; } else { publisher = Mono.justOrEmpty(body); actualElementType = body != null ? ResolvableType.forInstance(body) : bodyType; elementType = (bodyType.toClass() == Object.class && body != null ? actualElementType : bodyType); } if (elementType.resolve() == void.class || elementType.resolve() == Void.class) { return Mono.from((Publisher<Void>) publisher); } MediaType bestMediaType = selectMediaType(exchange, () -> getMediaTypesFor(elementType)); if (bestMediaType != null) { String logPrefix = exchange.getLogPrefix(); if (logger.isDebugEnabled()) { logger.debug(logPrefix + (publisher instanceof Mono ? "0..1" : "0..N") + " [" + elementType + "]"); } for (HttpMessageWriter<?> writer : getMessageWriters()) { if (writer.canWrite(actualElementType, bestMediaType)) { return writer.write((Publisher) publisher, actualType, elementType, bestMediaType, exchange.getRequest(), exchange.getResponse(), Hints.from(Hints.LOG_PREFIX_HINT, logPrefix)); } } } List<MediaType> mediaTypes = getMediaTypesFor(elementType); if (bestMediaType == null && mediaTypes.isEmpty()) { return Mono.error(new IllegalStateException("No HttpMessageWriter for " + elementType)); } return Mono.error(new NotAcceptableStatusException(mediaTypes)); }
Example 10
Source File: SimpleApplicationEventMulticaster.java From java-technology-stack with MIT License | 4 votes |
private ResolvableType resolveDefaultEventType(ApplicationEvent event) { return ResolvableType.forInstance(event); }
Example 11
Source File: AbstractMessageWriterResultHandler.java From java-technology-stack with MIT License | 4 votes |
/** * Write a given body to the response with {@link HttpMessageWriter}. * @param body the object to write * @param bodyParameter the {@link MethodParameter} of the body to write * @param actualParam the actual return type of the method that returned the value; * could be different from {@code bodyParameter} when processing {@code HttpEntity} * for example * @param exchange the current exchange * @return indicates completion or error * @since 5.0.2 */ @SuppressWarnings({"unchecked", "rawtypes"}) protected Mono<Void> writeBody(@Nullable Object body, MethodParameter bodyParameter, @Nullable MethodParameter actualParam, ServerWebExchange exchange) { ResolvableType bodyType = ResolvableType.forMethodParameter(bodyParameter); ResolvableType actualType = (actualParam != null ? ResolvableType.forMethodParameter(actualParam) : bodyType); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(bodyType.resolve(), body); Publisher<?> publisher; ResolvableType elementType; if (adapter != null) { publisher = adapter.toPublisher(body); ResolvableType genericType = bodyType.getGeneric(); elementType = getElementType(adapter, genericType); } else { publisher = Mono.justOrEmpty(body); elementType = (bodyType.toClass() == Object.class && body != null ? ResolvableType.forInstance(body) : bodyType); } if (elementType.resolve() == void.class || elementType.resolve() == Void.class) { return Mono.from((Publisher<Void>) publisher); } ServerHttpRequest request = exchange.getRequest(); ServerHttpResponse response = exchange.getResponse(); MediaType bestMediaType = selectMediaType(exchange, () -> getMediaTypesFor(elementType)); if (bestMediaType != null) { String logPrefix = exchange.getLogPrefix(); if (logger.isDebugEnabled()) { logger.debug(logPrefix + (publisher instanceof Mono ? "0..1" : "0..N") + " [" + elementType + "]"); } for (HttpMessageWriter<?> writer : getMessageWriters()) { if (writer.canWrite(elementType, bestMediaType)) { return writer.write((Publisher) publisher, actualType, elementType, bestMediaType, request, response, Hints.from(Hints.LOG_PREFIX_HINT, logPrefix)); } } } else { if (getMediaTypesFor(elementType).isEmpty()) { return Mono.error(new IllegalStateException("No writer for : " + elementType)); } } return Mono.error(new NotAcceptableStatusException(getMediaTypesFor(elementType))); }
Example 12
Source File: SimpleApplicationEventMulticaster.java From lams with GNU General Public License v2.0 | 4 votes |
private ResolvableType resolveDefaultEventType(ApplicationEvent event) { return ResolvableType.forInstance(event); }
Example 13
Source File: SimpleApplicationEventMulticaster.java From spring4-understanding with Apache License 2.0 | 4 votes |
private ResolvableType resolveDefaultEventType(ApplicationEvent event) { return ResolvableType.forInstance(event); }
Example 14
Source File: UiEventsMulticasterImpl.java From cuba with Apache License 2.0 | 4 votes |
protected ResolvableType resolveDefaultEventType(ApplicationEvent event) { return ResolvableType.forInstance(event); }