/** * Create a new instance with a default {@link ConversionService}. */ public GenericMessageConverter() { this.conversionService = DefaultConversionService.getSharedInstance(); }
/** * Create a StandardTypeConverter for the default ConversionService. * @see DefaultConversionService#getSharedInstance() */ public StandardTypeConverter() { this.conversionService = DefaultConversionService.getSharedInstance(); }
/** * Create a StandardTypeConverter for the default ConversionService. * @see DefaultConversionService#getSharedInstance() */ public StandardTypeConverter() { this.conversionService = DefaultConversionService.getSharedInstance(); }
/** * Constructor with a {@link ConversionService} and a {@link BeanFactory}. * @param cs conversion service for converting values to match the * target method parameter type * @param beanFactory a bean factory to use for resolving {@code ${...}} placeholder * and {@code #{...}} SpEL expressions in default values, or {@code null} if default * values are not expected to contain expressions */ protected AbstractNamedValueMethodArgumentResolver(ConversionService cs, @Nullable ConfigurableBeanFactory beanFactory) { this.conversionService = (cs != null ? cs : DefaultConversionService.getSharedInstance()); this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, null) : null); }
/** * Convert the given value to the specified target type, if necessary. * @param value the original property value * @param targetType the specified target type for property retrieval * @return the converted value, or the original value if no conversion * is necessary * @since 4.3.5 */ @SuppressWarnings("unchecked") @Nullable protected <T> T convertValueIfNecessary(Object value, @Nullable Class<T> targetType) { if (targetType == null) { return (T) value; } ConversionService conversionServiceToUse = this.conversionService; if (conversionServiceToUse == null) { // Avoid initialization of shared DefaultConversionService if // no standard type conversion is needed in the first place... if (ClassUtils.isAssignableValue(targetType, value)) { return (T) value; } conversionServiceToUse = DefaultConversionService.getSharedInstance(); } return conversionServiceToUse.convert(value, targetType); }
/** * Convert the given value to the specified target type, if necessary. * @param value the original property value * @param targetType the specified target type for property retrieval * @return the converted value, or the original value if no conversion * is necessary * @since 4.3.5 */ @SuppressWarnings("unchecked") @Nullable protected <T> T convertValueIfNecessary(Object value, @Nullable Class<T> targetType) { if (targetType == null) { return (T) value; } ConversionService conversionServiceToUse = this.conversionService; if (conversionServiceToUse == null) { // Avoid initialization of shared DefaultConversionService if // no standard type conversion is needed in the first place... if (ClassUtils.isAssignableValue(targetType, value)) { return (T) value; } conversionServiceToUse = DefaultConversionService.getSharedInstance(); } return conversionServiceToUse.convert(value, targetType); }
/** * Create a new instance with a default {@link ConversionService}. */ public GenericMessageConverter() { this.conversionService = DefaultConversionService.getSharedInstance(); }
public BeanFactoryTypeConverter() { this.conversionService = DefaultConversionService.getSharedInstance(); }
/** * Constructor with a {@link ConversionService} and a {@link BeanFactory}. * @param cs conversion service for converting values to match the * target method parameter type * @param beanFactory a bean factory to use for resolving {@code ${...}} placeholder * and {@code #{...}} SpEL expressions in default values, or {@code null} if default * values are not expected to contain expressions */ protected AbstractNamedValueMethodArgumentResolver(ConversionService cs, @Nullable ConfigurableBeanFactory beanFactory) { this.conversionService = (cs != null ? cs : DefaultConversionService.getSharedInstance()); this.configurableBeanFactory = beanFactory; this.expressionContext = (beanFactory != null ? new BeanExpressionContext(beanFactory, null) : null); }
protected ConversionService getRequiredConversionService() { ConversionService conversionService = getConversionService(); if (conversionService == null) { conversionService = DefaultConversionService.getSharedInstance(); setConversionService(conversionService); } return conversionService; }
@SuppressWarnings("unchecked") public AbstractMethodAnnotationPostProcessor(ConfigurableListableBeanFactory beanFactory) { Assert.notNull(beanFactory, "'beanFactory' must not be null"); this.messageHandlerAttributes.add(SEND_TIMEOUT_ATTRIBUTE); this.beanFactory = beanFactory; this.conversionService = this.beanFactory.getConversionService() != null ? this.beanFactory.getConversionService() : DefaultConversionService.getSharedInstance(); this.channelResolver = new BeanFactoryChannelResolver(beanFactory); this.annotationType = (Class<T>) GenericTypeResolver.resolveTypeArgument(this.getClass(), MethodAnnotationPostProcessor.class); Disposables disposablesBean = null; try { disposablesBean = beanFactory.getBean(Disposables.class); } catch (Exception e) { // NOSONAR - only for test cases } this.disposables = disposablesBean; }
@Override protected Object transformPayload(Map<?, ?> payload) throws Exception { Object target = (this.targetClass != null) ? BeanUtils.instantiateClass(this.targetClass) : this.getBeanFactory().getBean(this.targetBeanName); DataBinder binder = new DataBinder(target); ConversionService conversionService = getConversionService(); if (conversionService == null) { conversionService = DefaultConversionService.getSharedInstance(); } binder.setConversionService(conversionService); binder.bind(new MutablePropertyValues(payload)); return target; }
@Override protected void onInit() { super.onInit(); ConversionService conversionService = getConversionService(); if (conversionService == null) { conversionService = DefaultConversionService.getSharedInstance(); } for (Map.Entry<Object, NamedComponent> entry : this.mapping.entrySet()) { Object key = entry.getKey(); String channelKey; if (key instanceof String) { channelKey = (String) key; } else if (key instanceof Class) { channelKey = ((Class<?>) key).getName(); } else if (conversionService.canConvert(key.getClass(), String.class)) { channelKey = conversionService.convert(key, String.class); } else { throw new MessagingException("Unsupported channel mapping type for router [" + key.getClass() + "]"); } this.router.setChannelMapping(channelKey, entry.getValue().getComponentName()); } }
/** * Create a new instance with a default {@link ConversionService}. */ public GenericMessageConverter() { this.conversionService = DefaultConversionService.getSharedInstance(); }
/** * Create a StandardTypeConverter for the default ConversionService. * @see DefaultConversionService#getSharedInstance() */ public StandardTypeConverter() { this.conversionService = DefaultConversionService.getSharedInstance(); }
/** * Create a new instance with a default {@link ConversionService}. */ public GenericMessageConverter() { this.conversionService = DefaultConversionService.getSharedInstance(); }
@Test public void testEvaluationContextDefaultTypeConverter() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, new RootBeanDefinition(IntegrationEvaluationContextFactoryBean.class)); context.refresh(); StandardEvaluationContext evalContext = ExpressionUtils.createStandardEvaluationContext(context); assertNotNull(evalContext.getBeanResolver()); TypeConverter typeConverter = evalContext.getTypeConverter(); assertNotNull(typeConverter); assertSame(DefaultConversionService.getSharedInstance(), TestUtils.getPropertyValue(typeConverter, "conversionService")); }
@Test public void testEvaluationContextNoBeanFactory() { StandardEvaluationContext evalContext = ExpressionUtils.createStandardEvaluationContext(); assertNull(evalContext.getBeanResolver()); TypeConverter typeConverter = evalContext.getTypeConverter(); assertNotNull(typeConverter); assertSame(DefaultConversionService.getSharedInstance(), TestUtils.getPropertyValue(typeConverter, "conversionService")); } }
@Test public void testEvaluationContextNoFactoryBean() { GenericApplicationContext context = new GenericApplicationContext(); context.registerBeanDefinition(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, new RootBeanDefinition(ConversionServiceFactoryBean.class)); context.refresh(); StandardEvaluationContext evalContext = ExpressionUtils.createStandardEvaluationContext(context); assertNotNull(evalContext.getBeanResolver()); TypeConverter typeConverter = evalContext.getTypeConverter(); assertNotNull(typeConverter); assertNotSame(DefaultConversionService.getSharedInstance(), TestUtils.getPropertyValue(typeConverter, "conversionService")); assertSame(context.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME), TestUtils.getPropertyValue(typeConverter, "conversionService")); }
protected ConversionService getRequiredConversionService() { ConversionService conversionService = getConversionService(); if (conversionService == null) { conversionService = DefaultConversionService.getSharedInstance(); setConversionService(conversionService); } return conversionService; }