本文整理汇总了Java中org.springframework.beans.SimpleTypeConverter类的典型用法代码示例。如果您正苦于以下问题:Java SimpleTypeConverter类的具体用法?Java SimpleTypeConverter怎么用?Java SimpleTypeConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleTypeConverter类属于org.springframework.beans包,在下文中一共展示了SimpleTypeConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterPropertiesSet
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
/**
* Look up the JNDI object and store it.
*/
@Override
public void afterPropertiesSet() throws IllegalArgumentException, NamingException {
super.afterPropertiesSet();
if (this.proxyInterfaces != null || !this.lookupOnStartup || !this.cache || this.exposeAccessContext) {
// We need to create a proxy for this...
if (this.defaultObject != null) {
throw new IllegalArgumentException(
"'defaultObject' is not supported in combination with 'proxyInterface'");
}
// We need a proxy and a JndiObjectTargetSource.
this.jndiObject = JndiObjectProxyFactory.createJndiObjectProxy(this);
}
else {
if (this.defaultObject != null && getExpectedType() != null &&
!getExpectedType().isInstance(this.defaultObject)) {
TypeConverter converter = (this.beanFactory != null ?
this.beanFactory.getTypeConverter() : new SimpleTypeConverter());
try {
this.defaultObject = converter.convertIfNecessary(this.defaultObject, getExpectedType());
}
catch (TypeMismatchException ex) {
throw new IllegalArgumentException("Default object [" + this.defaultObject + "] of type [" +
this.defaultObject.getClass().getName() + "] is not of expected type [" +
getExpectedType().getName() + "] and cannot be converted either", ex);
}
}
// Locate specified JNDI object.
this.jndiObject = lookupWithFallback();
}
}
示例2: getMethodArgument
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
/**
* Gets properly typed method argument.
* @param parameterType
* @param value
* @return
*/
private <T> T getMethodArgument(Class<T> parameterType, Object value) {
if (parameterType.isInstance(value)) {
return parameterType.cast(value);
}
try {
return new SimpleTypeConverter().convertIfNecessary(value, parameterType);
} catch (ConversionNotSupportedException e) {
if (String.class.equals(parameterType)) {
return (T) String.valueOf(value);
}
throw new ApplicationRuntimeException("Unable to convert method argument type", e);
}
}
示例3: DirectFieldAccessor
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
/**
* Create a new DirectFieldAccessor for the given target object.
* @param target the target object to access
*/
public DirectFieldAccessor(final Object target) {
Assert.notNull(target, "Target object must not be null");
this.target = target;
ReflectionUtils.doWithFields(this.target.getClass(), new ReflectionUtils.FieldCallback() {
public void doWith(Field field) {
// jlm - FIX SPR-8398: avoid to overwrite shadowed fileds
if (!fieldMap.containsKey(field.getName())) {
fieldMap.put(field.getName(), field);
}
}
});
this.typeConverterDelegate = new SimpleTypeConverter();
registerDefaultEditors();
setExtractOldValueForEditor(true);
}
示例4: getConverter
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
private TypeConverter getConverter() {
if (typeConverter == null) {
SimpleTypeConverter simpleConverter = new SimpleTypeConverter();
beanFactory.copyRegisteredEditorsTo(simpleConverter);
simpleConverter.setConversionService(beanFactory.getConversionService());
typeConverter = simpleConverter;
}
return typeConverter;
}
示例5: getSimpleTypeConverter
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
/**
* Return this binder's underlying SimpleTypeConverter.
*/
protected SimpleTypeConverter getSimpleTypeConverter() {
if (this.typeConverter == null) {
this.typeConverter = new SimpleTypeConverter();
if (this.conversionService != null) {
this.typeConverter.setConversionService(this.conversionService);
}
}
return this.typeConverter;
}
示例6: checkQualifiers
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
/**
* Match the given qualifier annotations against the candidate bean definition.
*/
protected boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) {
if (ObjectUtils.isEmpty(annotationsToSearch)) {
return true;
}
SimpleTypeConverter typeConverter = new SimpleTypeConverter();
for (Annotation annotation : annotationsToSearch) {
Class<? extends Annotation> type = annotation.annotationType();
boolean checkMeta = true;
boolean fallbackToMeta = false;
if (isQualifier(type)) {
if (!checkQualifier(bdHolder, annotation, typeConverter)) {
fallbackToMeta = true;
}
else {
checkMeta = false;
}
}
if (checkMeta) {
boolean foundMeta = false;
for (Annotation metaAnn : type.getAnnotations()) {
Class<? extends Annotation> metaType = metaAnn.annotationType();
if (isQualifier(metaType)) {
foundMeta = true;
// Only accept fallback match if @Qualifier annotation has a value...
// Otherwise it is just a marker for a custom qualifier annotation.
if ((fallbackToMeta && StringUtils.isEmpty(AnnotationUtils.getValue(metaAnn))) ||
!checkQualifier(bdHolder, metaAnn, typeConverter)) {
return false;
}
}
}
if (fallbackToMeta && !foundMeta) {
return false;
}
}
}
return true;
}
示例7: getTypeConverter
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
@Override
public TypeConverter getTypeConverter() {
TypeConverter customConverter = getCustomTypeConverter();
if (customConverter != null) {
return customConverter;
}
else {
// Build default TypeConverter, registering custom editors.
SimpleTypeConverter typeConverter = new SimpleTypeConverter();
typeConverter.setConversionService(getConversionService());
registerCustomEditors(typeConverter);
return typeConverter;
}
}
示例8: getBeanTypeConverter
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
/**
* Obtain a bean type converter from the BeanFactory that this bean
* runs in. This is typically a fresh instance for each call,
* since TypeConverters are usually <i>not</i> thread-safe.
* <p>Falls back to a SimpleTypeConverter when not running in a BeanFactory.
* @see ConfigurableBeanFactory#getTypeConverter()
* @see org.springframework.beans.SimpleTypeConverter
*/
protected TypeConverter getBeanTypeConverter() {
BeanFactory beanFactory = getBeanFactory();
if (beanFactory instanceof ConfigurableBeanFactory) {
return ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
}
else {
return new SimpleTypeConverter();
}
}
示例9: typeConverter
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
@Bean
public TypeConverter typeConverter() {
SimpleTypeConverter tc = new SimpleTypeConverter();
tc.registerCustomEditor(LocalDateTime.class, new LocalDateTimePropertyEditor("yyyyMMdd_HHmmss"));
tc.registerCustomEditor(LocalDate.class, new LocalDatePropertyEditor("yyyyMMdd"));
return tc;
}
示例10: setBeanFactory
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
if (beanFactory instanceof ConfigurableBeanFactory) {
Object typeConverter = ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
if (typeConverter instanceof SimpleTypeConverter) {
delegate = (SimpleTypeConverter) typeConverter;
}
}
}
示例11: JpqQueryRSQLVisitor
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
private JpqQueryRSQLVisitor(final Root<T> root, final CriteriaBuilder cb, final Class<A> enumType,
final VirtualPropertyReplacer virtualPropertyReplacer) {
this.root = root;
this.cb = cb;
this.enumType = enumType;
this.virtualPropertyReplacer = virtualPropertyReplacer;
simpleTypeConverter = new SimpleTypeConverter();
}
示例12: setFieldValue
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
public static void setFieldValue(Field field, Object bean, Object value)
throws IllegalAccessException {
// Set it on the field
field.setAccessible(true);
// Perform type conversion if possible..
SimpleTypeConverter converter = new SimpleTypeConverter();
try {
value = converter.convertIfNecessary(value, field.getType());
}
catch (ConversionNotSupportedException e) {
// If conversion isn't supported, ignore and try and set anyway.
}
field.set(bean, value);
}
示例13: getTypeConverter
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
public TypeConverter getTypeConverter() {
TypeConverter customConverter = getCustomTypeConverter();
if (customConverter != null) {
return customConverter;
}
else {
// Build default TypeConverter, registering custom editors.
SimpleTypeConverter typeConverter = new SimpleTypeConverter();
typeConverter.setConversionService(getConversionService());
registerCustomEditors(typeConverter);
return typeConverter;
}
}
示例14: GoConfigFieldWriter
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
public GoConfigFieldWriter(Field declaredField, Object value, SimpleTypeConverter converter, ConfigCache configCache, final ConfigElementImplementationRegistry registry) {
this.configField = declaredField;
this.value = value;
this.configField.setAccessible(true);
this.typeConverter = converter;
this.configCache = configCache;
this.registry = registry;
}
示例15: SpringBlueprintConverterService
import org.springframework.beans.SimpleTypeConverter; //导入依赖的package包/类
public SpringBlueprintConverterService(ConversionService delegate, ConfigurableBeanFactory cbf) {
this.delegate = delegate;
this.cbf = cbf;
this.typeConverter = new SimpleTypeConverter();
}