當前位置: 首頁>>代碼示例>>Java>>正文


Java ConversionService類代碼示例

本文整理匯總了Java中org.springframework.core.convert.ConversionService的典型用法代碼示例。如果您正苦於以下問題:Java ConversionService類的具體用法?Java ConversionService怎麽用?Java ConversionService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConversionService類屬於org.springframework.core.convert包,在下文中一共展示了ConversionService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: HandlerMethodService

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
public HandlerMethodService(ConversionService conversionService,
		List<HandlerMethodArgumentResolver> customArgumentResolvers,
		ObjectMapper objectMapper, ApplicationContext applicationContext) {
	this.conversionService = conversionService;
	this.parameterNameDiscoverer = new DefaultParameterNameDiscoverer();

	this.argumentResolvers = new HandlerMethodArgumentResolverComposite();

	ConfigurableBeanFactory beanFactory = ClassUtils.isAssignableValue(
			ConfigurableApplicationContext.class, applicationContext)
					? ((ConfigurableApplicationContext) applicationContext)
							.getBeanFactory()
					: null;

	this.argumentResolvers.addResolver(
			new HeaderMethodArgumentResolver(this.conversionService, beanFactory));
	this.argumentResolvers.addResolver(new HeadersMethodArgumentResolver());
	this.argumentResolvers.addResolver(new WampMessageMethodArgumentResolver());
	this.argumentResolvers.addResolver(new PrincipalMethodArgumentResolver());
	this.argumentResolvers.addResolver(new WampSessionIdMethodArgumentResolver());
	this.argumentResolvers.addResolvers(customArgumentResolvers);

	this.objectMapper = objectMapper;
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:25,代碼來源:HandlerMethodService.java

示例2: getArguments

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
protected Object[] getArguments(Step step, StepImplementation implementation) {
	Method method = implementation.getMethod();
	Parameter[] parameters = method.getParameters();
	Object[] arguments = new Object[parameters.length];

	if (parameters.length > 0) {
		String text = step.getText();
		Pattern pattern = implementation.getPattern();
		Matcher matcher = pattern.matcher(text);
		checkState(matcher.find(),
			"unable to locate substitution parameters for pattern %s with input %s", pattern.pattern(), text);

		int groupCount = matcher.groupCount();
		ConversionService conversionService = SpringPreProcessor.getBean(ConversionService.class);
		for (int i = 0; i < groupCount; i++) {
			String parameterAsString = matcher.group(i + 1);
			Parameter parameter = parameters[i];
			Class<?> parameterType = parameter.getType();

			Object converted = conversionService.convert(parameterAsString, parameterType);
			arguments[i] = converted;
		}
	}
	return arguments;
}
 
開發者ID:qas-guru,項目名稱:martini-jmeter-extension,代碼行數:26,代碼來源:MartiniSamplerClient.java

示例3: contributeMethodArgument

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	Class<?> paramType = parameter.getParameterType();
	if (Map.class.isAssignableFrom(paramType) || MultipartFile.class.equals(paramType) ||
			"javax.servlet.http.Part".equals(paramType.getName())) {
		return;
	}

	RequestParam annot = parameter.getParameterAnnotation(RequestParam.class);
	String name = StringUtils.isEmpty(annot.value()) ? parameter.getParameterName() : annot.value();

	if (value == null) {
		builder.queryParam(name);
	}
	else if (value instanceof Collection) {
		for (Object element : (Collection<?>) value) {
			element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
			builder.queryParam(name, element);
		}
	}
	else {
		builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:RequestParamMethodArgumentResolver.java

示例4: finishBeanFactoryInitialization

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
/**
 * Finish the initialization of this context's bean factory,
 * initializing all remaining singleton beans.
 */
protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
	// Initialize conversion service for this context.
	if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) &&
			beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) {
		beanFactory.setConversionService(
				beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class));
	}

	// Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early.
	String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
	for (String weaverAwareName : weaverAwareNames) {
		getBean(weaverAwareName);
	}

	// Stop using the temporary ClassLoader for type matching.
	beanFactory.setTempClassLoader(null);

	// Allow for caching all bean definition metadata, not expecting further changes.
	beanFactory.freezeConfiguration();

	// Instantiate all remaining (non-lazy-init) singletons.
	beanFactory.preInstantiateSingletons();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:AbstractApplicationContext.java

示例5: normaliseValueForPut

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
public static Object normaliseValueForPut(Object value, ConversionService conversionService) {
	if (value instanceof Document) {
		return conversionService.convert(value, TypeDescriptor.forObject(value), TypeDescriptor.valueOf(IData.class));
	}
	else if (value instanceof Document[]) {
		return conversionService.convert(value, TypeDescriptor.forObject(value), TypeDescriptor.valueOf(IData[].class));
	}
	else if (value instanceof Iterable<?>) {
		if (CollectionUtil.areAllElementsOfType((Collection<?>) value, Document.class)) {
			return conversionService.convert(value, TypeDescriptor.forObject(value), TypeDescriptor.valueOf(IData[].class));
		}
		else {
			return value;
		}
		 
	}
	else {
		return value;
	}
}
 
開發者ID:innodev-au,項目名稱:wmboost-data,代碼行數:21,代碼來源:IDataHelper.java

示例6: contributeMethodArgument

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
    Class<?> paramType = parameter.getNestedParameterType();
    if (Map.class.isAssignableFrom(paramType)) {
        return;
    }
    WxApiParam wxApiParam = parameter.getParameterAnnotation(WxApiParam.class);
    String name = (wxApiParam == null || StringUtils.isEmpty(wxApiParam.name()) ? parameter.getParameterName() : wxApiParam.name());
    WxAppAssert.notNull(name, "請添加編譯器的-parameter或者為參數添加注解名稱");
    if (value == null) {
        if (wxApiParam != null) {
            if (!wxApiParam.required() || !wxApiParam.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
                return;
            }
        }
        builder.queryParam(name);
    } else if (value instanceof Collection) {
        for (Object element : (Collection<?>) value) {
            element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
            builder.queryParam(name, element);
        }
    } else {
        builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
    }
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:26,代碼來源:WxApiParamContributor.java

示例7: setEntryValue

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
@Override
protected void setEntryValue(Map nativeEntry, String key, Object value) {
    if (value == null || !shouldConvert(value)) {
        return;
    }

    Class type = value.getClass();
    if(value != null && type.isArray() && byte.class.isAssignableFrom(type.getComponentType())) {
        nativeEntry.put(key, SafeEncoder.encode((byte[])value));
    }
    else {

        final ConversionService conversionService = getMappingContext().getConversionService();
        nativeEntry.put(key, conversionService.convert(value, String.class));
    }
}
 
開發者ID:grails,項目名稱:gorm-redis,代碼行數:17,代碼來源:RedisEntityPersister.java

示例8: addDefaultConverters

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
/**
 * Add converters appropriate for most environments.
 * @param converterRegistry 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 addDefaultConverters(ConverterRegistry converterRegistry) {
	addScalarConverters(converterRegistry);
	addCollectionConverters(converterRegistry);

	converterRegistry.addConverter(new ByteBufferConverter((ConversionService) converterRegistry));
	if (jsr310Available) {
		Jsr310ConverterRegistrar.registerJsr310Converters(converterRegistry);
	}

	converterRegistry.addConverter(new ObjectToObjectConverter());
	converterRegistry.addConverter(new IdToEntityConverter((ConversionService) converterRegistry));
	converterRegistry.addConverter(new FallbackObjectToStringConverter());
	if (javaUtilOptionalClassAvailable) {
		converterRegistry.addConverter(new ObjectToOptionalConverter((ConversionService) converterRegistry));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:DefaultConversionService.java

示例9: canConvertElements

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
public static boolean canConvertElements(TypeDescriptor sourceElementType, TypeDescriptor targetElementType, ConversionService conversionService) {
	if (targetElementType == null) {
		// yes
		return true;
	}
	if (sourceElementType == null) {
		// maybe
		return true;
	}
	if (conversionService.canConvert(sourceElementType, targetElementType)) {
		// yes
		return true;
	}
	else if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) {
		// maybe;
		return true;
	}
	else {
		// no;
		return false;
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:23,代碼來源:ConversionUtils.java

示例10: convertProperty

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
private static Object convertProperty(BeanWrapper parentBean, String property,
    ConversionService conversionService, Map<String, Object> parentValue) {

  TypeDescriptor source = parentBean.getPropertyTypeDescriptor(property);
  Object propertyValue = parentBean.getPropertyValue(property);

  int dotIndex = property.indexOf('.');
  if (dotIndex > 0) {
    String baseProperty = property.substring(0, dotIndex);
    String childProperty = property.substring(dotIndex + 1);
    Map<String, Object> childValue = getChildValue(parentValue, baseProperty, childProperty);
    BeanWrapper childBean = new BeanWrapperImpl(parentBean.getPropertyValue(baseProperty));
    Object convertedProperty =
        convertProperty(childBean, childProperty, conversionService, childValue);
    childValue.put(childProperty, convertedProperty);
    return childValue;
  } else {
    String convertedPropertyValue =
        (String) conversionService.convert(propertyValue, source, TYPE_STRING);
    return convertedPropertyValue;
  }
}
 
開發者ID:DISID,項目名稱:springlets,代碼行數:23,代碼來源:ConvertedDatatablesData.java

示例11: createAttributeFromRequestValue

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
protected Object createAttributeFromRequestValue(String sourceValue,
										 String attributeName,
										 MethodParameter parameter,
										 WebDataBinderFactory binderFactory,
										 NativeWebRequest request) throws Exception {
DataBinder binder = binderFactory.createBinder(request, null, attributeName);
ConversionService conversionService = binder.getConversionService();
if (conversionService != null) {
	TypeDescriptor source = TypeDescriptor.valueOf(String.class);
	TypeDescriptor target = new TypeDescriptor(parameter);
	if (conversionService.canConvert(source, target)) {
		return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
	}
}
	return null;
}
 
開發者ID:thinking-github,項目名稱:nbone,代碼行數:17,代碼來源:NamespaceModelAttributeMethodProcessor.java

示例12: requestMappingHandlerAdapter

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
@Test
public void requestMappingHandlerAdapter() throws Exception {

	delegatingConfig.setConfigurers(Arrays.asList(webMvcConfigurer));
	RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter();

	ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
	ConversionService initializerConversionService = initializer.getConversionService();
	assertTrue(initializer.getValidator() instanceof LocalValidatorFactoryBean);

	verify(webMvcConfigurer).configureMessageConverters(converters.capture());
	verify(webMvcConfigurer).configureContentNegotiation(contentNegotiationConfigurer.capture());
	verify(webMvcConfigurer).addFormatters(conversionService.capture());
	verify(webMvcConfigurer).addArgumentResolvers(resolvers.capture());
	verify(webMvcConfigurer).addReturnValueHandlers(handlers.capture());
	verify(webMvcConfigurer).configureAsyncSupport(asyncConfigurer.capture());

	assertSame(conversionService.getValue(), initializerConversionService);
	assertEquals(0, resolvers.getValue().size());
	assertEquals(0, handlers.getValue().size());
	assertEquals(converters.getValue(), adapter.getMessageConverters());
	assertNotNull(asyncConfigurer);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:DelegatingWebMvcConfigurationTests.java

示例13: contributeMethodArgument

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value,
		UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {

	Class<?> paramType = parameter.getParameterType();
	if (Map.class.isAssignableFrom(paramType) || MultipartFile.class == paramType ||
			"javax.servlet.http.Part".equals(paramType.getName())) {
		return;
	}

	RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class);
	String name = (requestParam == null || StringUtils.isEmpty(requestParam.name()) ? parameter.getParameterName() : requestParam.name());

	if (value == null) {
		builder.queryParam(name);
	}
	else if (value instanceof Collection) {
		for (Object element : (Collection<?>) value) {
			element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
			builder.queryParam(name, element);
		}
	}
	else {
		builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:RequestParamMethodArgumentResolver.java

示例14: createAttributeFromRequestValue

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
/**
 * Create a model attribute from a String request value (e.g. URI template
 * variable, request parameter) using type conversion.
 * <p>The default implementation converts only if there a registered 
 * {@link Converter} that can perform the conversion.
 * @param sourceValue the source value to create the model attribute from
 * @param attributeName the name of the attribute, never {@code null}
 * @param parameter the method parameter
 * @param binderFactory for creating WebDataBinder instance
 * @param request the current request
 * @return the created model attribute, or {@code null}
 * @throws Exception
 */
protected Object createAttributeFromRequestValue(String sourceValue,
                                             String attributeName, 
                                             MethodParameter parameter, 
                                             WebDataBinderFactory binderFactory, 
                                             NativeWebRequest request) throws Exception {
    DataBinder binder = binderFactory.createBinder(request, null, attributeName);
    ConversionService conversionService = binder.getConversionService();
    if (conversionService != null) {
        TypeDescriptor source = TypeDescriptor.valueOf(String.class);
        TypeDescriptor target = new TypeDescriptor(parameter);
        if (conversionService.canConvert(source, target)) {
            return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
        }
    }
    return null;
}
 
開發者ID:thinking-github,項目名稱:nbone,代碼行數:30,代碼來源:FormModelMethodArgumentResolver.java

示例15: createAttributeFromRequestValue

import org.springframework.core.convert.ConversionService; //導入依賴的package包/類
/**
 * Create a model attribute from a String request value (e.g. URI template
 * variable, request parameter) using type conversion.
 * <p>The default implementation converts only if there a registered
 * {@link org.springframework.core.convert.converter.Converter} that can perform the conversion.
 *
 * @param sourceValue   the source value to create the model attribute from
 * @param attributeName the name of the attribute, never {@code null}
 * @param parameter     the method parameter
 * @param binderFactory for creating WebDataBinder instance
 * @param request       the current request
 * @return the created model attribute, or {@code null}
 * @throws Exception
 */
protected Object createAttributeFromRequestValue(String sourceValue,
                                                 String attributeName,
                                                 MethodParameter parameter,
                                                 WebDataBinderFactory binderFactory,
                                                 NativeWebRequest request) throws Exception {
    DataBinder binder = binderFactory.createBinder(request, null, attributeName);
    ConversionService conversionService = binder.getConversionService();
    if (conversionService != null) {
        TypeDescriptor source = TypeDescriptor.valueOf(String.class);
        TypeDescriptor target = new TypeDescriptor(parameter);
        if (conversionService.canConvert(source, target)) {
            return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
        }
    }
    return null;
}
 
開發者ID:thinking-github,項目名稱:nbone,代碼行數:31,代碼來源:FormModelMethodArgumentResolver.java


注:本文中的org.springframework.core.convert.ConversionService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。