List of usage examples for org.springframework.beans BeanUtils findEditorByConvention
@Nullable public static PropertyEditor findEditorByConvention(@Nullable Class<?> targetType)
From source file:com.asual.summer.core.resource.PropertyResource.java
public void setLocation(String location) { ResourceEditor editor = (ResourceEditor) BeanUtils.findEditorByConvention(Resource.class); this.resources = new Resource[] { locationStringToResource(location, editor) }; }
From source file:com.asual.summer.core.resource.PropertyResource.java
public void setLocations(String[] locations) { ResourceEditor editor = (ResourceEditor) BeanUtils.findEditorByConvention(Resource.class); Resource[] resources = new Resource[locations.length]; for (int i = 0; i < locations.length; i++) { resources[i] = locationStringToResource(locations[i], editor); }//from w ww .j av a 2 s . c o m this.resources = resources; }
From source file:com.alibaba.citrus.service.form.impl.GroupImpl.java
/** * fields/*from ww w. j a v a2s . co m*/ * <p> * <code>isValidated()</code><code>true</code>group * </p> */ public void mapTo(Object object) { if (isValidated() || object == null) { return; } if (log.isDebugEnabled()) { log.debug("Mapping properties to fields: group=\"{}\", object={}", getName(), ObjectUtil.identityToString(object)); } BeanWrapper bean = new BeanWrapperImpl(object); getForm().getFormConfig().getPropertyEditorRegistrar().registerCustomEditors(bean); for (Field field : getFields()) { String propertyName = field.getFieldConfig().getPropertyName(); if (bean.isReadableProperty(propertyName)) { Object propertyValue = bean.getPropertyValue(propertyName); Class<?> propertyType = bean.getPropertyType(propertyName); PropertyEditor editor = bean.findCustomEditor(propertyType, propertyName); if (editor == null) { editor = BeanUtils.findEditorByConvention(propertyType); } if (editor == null) { if (propertyType.isArray() || CollectionFactory.isApproximableCollectionType(propertyType)) { field.setValues((String[]) bean.convertIfNecessary(propertyValue, String[].class)); } else { field.setValue(bean.convertIfNecessary(propertyValue, String.class)); } } else { editor.setValue(propertyValue); field.setValue(editor.getAsText()); } } else { log.debug("No readable property \"{}\" found in type {}", propertyName, object.getClass().getName()); } } }
From source file:net.sf.juffrou.reflect.JuffrouTypeConverterDelegate.java
/** * Find a default editor for the given type. * //from www . jav a 2 s .c o m * @param requiredType * the type to find an editor for * @return the corresponding editor, or <code>null</code> if none */ private PropertyEditor findDefaultEditor(Class requiredType) { PropertyEditor editor = null; if (requiredType != null) { // No custom editor -> check BeanWrapperImpl's default editors. editor = this.propertyEditorRegistry.getDefaultEditor(requiredType); if (editor == null && !String.class.equals(requiredType)) { // No BeanWrapper default editor -> check standard JavaBean editor. editor = BeanUtils.findEditorByConvention(requiredType); } } return editor; }
From source file:org.springframework.beans.TypeConverterDelegate.java
/** * Find a default editor for the given type. * @param requiredType the type to find an editor for * @return the corresponding editor, or {@code null} if none *///from w w w. ja v a2 s . c o m @Nullable private PropertyEditor findDefaultEditor(@Nullable Class<?> requiredType) { PropertyEditor editor = null; if (requiredType != null) { // No custom editor -> check BeanWrapperImpl's default editors. editor = this.propertyEditorRegistry.getDefaultEditor(requiredType); if (editor == null && String.class != requiredType) { // No BeanWrapper default editor -> check standard JavaBean editor. editor = BeanUtils.findEditorByConvention(requiredType); } } return editor; }
From source file:org.springframework.faces.mvc.bind.ReverseDataBinder.java
/** * Find a default editor for the given type. This code is based on <tt>TypeConverterDelegate.findDefaultEditor</tt> * from Spring 2.5.6./*from w ww. j a v a 2 s .c om*/ * @param requiredType the type to find an editor for * @param descriptor the JavaBeans descriptor for the property * @return the corresponding editor, or <code>null</code> if none * * @author Juergen Hoeller * @author Rob Harrop */ protected PropertyEditor findDefaultEditor(PropertyEditorRegistrySupport propertyEditorRegistrySupport, Object targetObject, Class requiredType, PropertyDescriptor descriptor) { PropertyEditor editor = null; if (descriptor != null) { if (JdkVersion.isAtLeastJava15()) { editor = descriptor.createPropertyEditor(targetObject); } else { Class editorClass = descriptor.getPropertyEditorClass(); if (editorClass != null) { editor = (PropertyEditor) BeanUtils.instantiateClass(editorClass); } } } if (editor == null && requiredType != null) { // No custom editor -> check default editors. editor = propertyEditorRegistrySupport.getDefaultEditor(requiredType); if (editor == null && !String.class.equals(requiredType)) { // No BeanWrapper default editor -> check standard JavaBean editor. editor = BeanUtils.findEditorByConvention(requiredType); if (editor == null && !unknownEditorTypes.containsKey(requiredType)) { // Global PropertyEditorManager fallback... editor = PropertyEditorManager.findEditor(requiredType); if (editor == null) { // Regular case as of Spring 2.5 unknownEditorTypes.put(requiredType, Boolean.TRUE); } } } } return editor; }
From source file:org.springframework.springfaces.mvc.bind.ReverseDataBinder.java
/** * Find a default editor for the given type. This code is based on <tt>TypeConverterDelegate.findDefaultEditor</tt>. * @param requiredType the type to find an editor for * @param typeDescriptor the type description of the property * @return the corresponding editor, or <code>null</code> if none * // w ww.j av a2 s. c om * @param propertyEditorRegistry * @param targetObject * * @author Juergen Hoeller * @author Rob Harrop */ protected PropertyEditor findDefaultEditor(PropertyEditorRegistrySupport propertyEditorRegistry, Object targetObject, Class<?> requiredType, TypeDescriptor typeDescriptor) { PropertyEditor editor = null; if (requiredType != null) { // No custom editor -> check BeanWrapperImpl's default editors. editor = propertyEditorRegistry.getDefaultEditor(requiredType); if (editor == null && !String.class.equals(requiredType)) { // No BeanWrapper default editor -> check standard JavaBean editor. editor = BeanUtils.findEditorByConvention(requiredType); } } return editor; }
From source file:org.tinygroup.beanwrapper.TypeConverterDelegate.java
/** * Find a default editor for the given type. * @param requiredType the type to find an editor for * @param descriptor the JavaBeans descriptor for the property * @return the corresponding editor, or <code>null</code> if none *//* w ww .jav a 2 s .co m*/ protected PropertyEditor findDefaultEditor(Class requiredType, PropertyDescriptor descriptor) { PropertyEditor editor = null; if (descriptor != null) { if (JdkVersion.isAtLeastJava15()) { editor = descriptor.createPropertyEditor(this.targetObject); } else { Class editorClass = descriptor.getPropertyEditorClass(); if (editorClass != null) { editor = (PropertyEditor) BeanUtils.instantiateClass(editorClass); } } } if (editor == null && requiredType != null) { // No custom editor -> check BeanWrapperImpl's default editors. editor = (PropertyEditor) this.propertyEditorRegistry.getDefaultEditor(requiredType); if (editor == null && !String.class.equals(requiredType)) { // No BeanWrapper default editor -> check standard JavaBean editor. editor = BeanUtils.findEditorByConvention(requiredType); if (editor == null && !unknownEditorTypes.containsKey(requiredType)) { // Deprecated global PropertyEditorManager fallback... editor = PropertyEditorManager.findEditor(requiredType); if (editor == null) { // Regular case as of Spring 2.5 unknownEditorTypes.put(requiredType, Boolean.TRUE); } else { logger.warn("PropertyEditor [" + editor.getClass().getName() + "] found through deprecated global PropertyEditorManager fallback - " + "consider using a more isolated form of registration, e.g. on the BeanWrapper/BeanFactory!"); } } } } return editor; }