List of usage examples for org.springframework.util Assert isAssignable
public static void isAssignable(Class<?> superType, Class<?> subType)
From source file:org.springframework.cloud.stream.binding.MessageConverterConfigurer.java
/** * Setup data-type and message converters for the given message channel. * * @param channel message channel to set the data-type and message converters * @param channelName the channel name/*w w w. j av a2 s . c o m*/ * @param inbound inbound (i.e., "input") or outbound channel */ private void configureMessageChannel(MessageChannel channel, String channelName, boolean inbound) { Assert.isAssignable(AbstractMessageChannel.class, channel.getClass()); AbstractMessageChannel messageChannel = (AbstractMessageChannel) channel; BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(channelName); String contentType = bindingProperties.getContentType(); ProducerProperties producerProperties = bindingProperties.getProducer(); if (!inbound && producerProperties != null && producerProperties.isPartitioned()) { messageChannel.addInterceptor(new PartitioningInterceptor(bindingProperties, getPartitionKeyExtractorStrategy(producerProperties), getPartitionSelectorStrategy(producerProperties))); } ConsumerProperties consumerProperties = bindingProperties.getConsumer(); if (this.isNativeEncodingNotSet(producerProperties, consumerProperties, inbound)) { if (inbound) { messageChannel.addInterceptor(new InboundContentTypeConvertingInterceptor(contentType, this.compositeMessageConverterFactory)); } else { messageChannel.addInterceptor(new OutboundContentTypeConvertingInterceptor(contentType, this.compositeMessageConverterFactory.getMessageConverterForAllRegistered())); } } }
From source file:org.springframework.data.document.web.bind.annotation.support.HandlerMethodInvoker.java
private Class<?> getHttpEntityType(MethodParameter methodParam) { Assert.isAssignable(HttpEntity.class, methodParam.getParameterType()); ParameterizedType type = (ParameterizedType) methodParam.getGenericParameterType(); if (type.getActualTypeArguments().length == 1) { Type typeArgument = type.getActualTypeArguments()[0]; if (typeArgument instanceof Class) { return (Class<?>) typeArgument; } else if (typeArgument instanceof GenericArrayType) { Type componentType = ((GenericArrayType) typeArgument).getGenericComponentType(); if (componentType instanceof Class) { // Surely, there should be a nicer way to do this Object array = Array.newInstance((Class<?>) componentType, 0); return array.getClass(); }/*from w w w. j ava2 s . c o m*/ } } throw new IllegalArgumentException( "HttpEntity parameter (" + methodParam.getParameterName() + ") is not parameterized"); }
From source file:org.springframework.integration.test.util.TestUtils.java
@SuppressWarnings("unchecked") public static <T> T getPropertyValue(Object root, String propertyPath, Class<T> type) { Object value = getPropertyValue(root, propertyPath); if (value != null) { Assert.isAssignable(type, value.getClass()); }/* ww w . j a v a2 s. c o m*/ return (T) value; }
From source file:org.springframework.kafka.test.utils.KafkaTestUtils.java
/** * A typed version of {@link #getPropertyValue(Object, String)}. * @param root the object.//from w w w . jav a 2s .c om * @param propertyPath the path. * @param type the type to cast the object to. * @param <T> the type. * @return the field value. * @see #getPropertyValue(Object, String) */ @SuppressWarnings("unchecked") public static <T> T getPropertyValue(Object root, String propertyPath, Class<T> type) { Object value = getPropertyValue(root, propertyPath); if (value != null) { Assert.isAssignable(type, value.getClass()); } return (T) value; }
From source file:org.springframework.security.authentication.DefaultAuthenticationEventPublisher.java
/** * Sets additional exception to event mappings. These are automatically merged with * the default exception to event mappings that <code>ProviderManager</code> defines. * * @param additionalExceptionMappings where keys are the fully-qualified string name * of the exception class and the values are the fully-qualified string name of the * event class to fire./*from w w w. j a v a 2 s . com*/ */ @SuppressWarnings({ "unchecked" }) public void setAdditionalExceptionMappings(Properties additionalExceptionMappings) { Assert.notNull(additionalExceptionMappings, "The exceptionMappings object must not be null"); for (Object exceptionClass : additionalExceptionMappings.keySet()) { String eventClass = (String) additionalExceptionMappings.get(exceptionClass); try { Class<?> clazz = getClass().getClassLoader().loadClass(eventClass); Assert.isAssignable(AbstractAuthenticationFailureEvent.class, clazz); addMapping((String) exceptionClass, (Class<? extends AbstractAuthenticationFailureEvent>) clazz); } catch (ClassNotFoundException e) { throw new RuntimeException("Failed to load authentication event class " + eventClass); } } }