Search in sources :

Example 1 with ConfigurableConversionService

use of cn.taketoday.core.conversion.support.ConfigurableConversionService in project today-infrastructure by TAKETODAY.

the class AbstractPropertyResolver method getConversionService.

@Override
public ConfigurableConversionService getConversionService() {
    // Need to provide an independent DefaultConversionService, not the
    // shared DefaultConversionService used by PropertySourcesPropertyResolver.
    ConfigurableConversionService cs = this.conversionService;
    if (cs == null) {
        synchronized (this) {
            cs = this.conversionService;
            if (cs == null) {
                cs = new DefaultConversionService();
                this.conversionService = cs;
            }
        }
    }
    return cs;
}
Also used : ConfigurableConversionService(cn.taketoday.core.conversion.support.ConfigurableConversionService) DefaultConversionService(cn.taketoday.core.conversion.support.DefaultConversionService)

Example 2 with ConfigurableConversionService

use of cn.taketoday.core.conversion.support.ConfigurableConversionService in project today-infrastructure by TAKETODAY.

the class ApplicationConversionService method addDelimitedStringConverters.

/**
 * Add converters to support delimited strings.
 *
 * @param registry the registry of converters to add to (must also be castable to
 * ConversionService, e.g. being a {@link ConfigurableConversionService})
 * @throws ClassCastException if the given ConverterRegistry could not be cast to a
 * ConversionService
 */
public static void addDelimitedStringConverters(ConverterRegistry registry) {
    ConversionService service = (ConversionService) registry;
    registry.addConverter(new ArrayToDelimitedStringConverter(service));
    registry.addConverter(new CollectionToDelimitedStringConverter(service));
    registry.addConverter(new DelimitedStringToArrayConverter(service));
    registry.addConverter(new DelimitedStringToCollectionConverter(service));
}
Also used : ConversionService(cn.taketoday.core.conversion.ConversionService) DefaultConversionService(cn.taketoday.core.conversion.support.DefaultConversionService) ConfigurableConversionService(cn.taketoday.core.conversion.support.ConfigurableConversionService)

Example 3 with ConfigurableConversionService

use of cn.taketoday.core.conversion.support.ConfigurableConversionService in project today-framework by TAKETODAY.

the class EnvironmentConverterTests method convertedEnvironmentHasSameConversionService.

@Test
void convertedEnvironmentHasSameConversionService() {
    AbstractEnvironment originalEnvironment = new MockEnvironment();
    ConfigurableConversionService conversionService = mock(ConfigurableConversionService.class);
    originalEnvironment.setConversionService(conversionService);
    StandardEnvironment convertedEnvironment = EnvironmentConverter.convertIfNecessary(getClass().getClassLoader(), originalEnvironment, StandardEnvironment.class);
    assertThat(convertedEnvironment.getConversionService()).isEqualTo(conversionService);
}
Also used : MockEnvironment(cn.taketoday.context.support.MockEnvironment) AbstractEnvironment(cn.taketoday.core.env.AbstractEnvironment) ConfigurableConversionService(cn.taketoday.core.conversion.support.ConfigurableConversionService) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigurableConversionService

use of cn.taketoday.core.conversion.support.ConfigurableConversionService in project today-framework by TAKETODAY.

the class ApplicationConversionService method addDelimitedStringConverters.

/**
 * Add converters to support delimited strings.
 *
 * @param registry the registry of converters to add to (must also be castable to
 * ConversionService, e.g. being a {@link ConfigurableConversionService})
 * @throws ClassCastException if the given ConverterRegistry could not be cast to a
 * ConversionService
 */
public static void addDelimitedStringConverters(ConverterRegistry registry) {
    ConversionService service = (ConversionService) registry;
    registry.addConverter(new ArrayToDelimitedStringConverter(service));
    registry.addConverter(new CollectionToDelimitedStringConverter(service));
    registry.addConverter(new DelimitedStringToArrayConverter(service));
    registry.addConverter(new DelimitedStringToCollectionConverter(service));
}
Also used : ConversionService(cn.taketoday.core.conversion.ConversionService) DefaultConversionService(cn.taketoday.core.conversion.support.DefaultConversionService) ConfigurableConversionService(cn.taketoday.core.conversion.support.ConfigurableConversionService)

Example 5 with ConfigurableConversionService

use of cn.taketoday.core.conversion.support.ConfigurableConversionService in project today-framework by TAKETODAY.

the class AbstractPropertyResolver method getConversionService.

@Override
public ConfigurableConversionService getConversionService() {
    // Need to provide an independent DefaultConversionService, not the
    // shared DefaultConversionService used by PropertySourcesPropertyResolver.
    ConfigurableConversionService cs = this.conversionService;
    if (cs == null) {
        synchronized (this) {
            cs = this.conversionService;
            if (cs == null) {
                cs = new DefaultConversionService();
                this.conversionService = cs;
            }
        }
    }
    return cs;
}
Also used : ConfigurableConversionService(cn.taketoday.core.conversion.support.ConfigurableConversionService) DefaultConversionService(cn.taketoday.core.conversion.support.DefaultConversionService)

Aggregations

ConfigurableConversionService (cn.taketoday.core.conversion.support.ConfigurableConversionService)6 DefaultConversionService (cn.taketoday.core.conversion.support.DefaultConversionService)4 MockEnvironment (cn.taketoday.context.support.MockEnvironment)2 ConversionService (cn.taketoday.core.conversion.ConversionService)2 AbstractEnvironment (cn.taketoday.core.env.AbstractEnvironment)2 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)2 Test (org.junit.jupiter.api.Test)2