org.springframework.beans.factory.config
Class CustomEditorConfigurer

java.lang.Object
  extended by org.springframework.beans.factory.config.CustomEditorConfigurer
All Implemented Interfaces:
BeanClassLoaderAware, BeanFactoryPostProcessor, Ordered

public class CustomEditorConfigurer
extends Object
implements BeanFactoryPostProcessor, BeanClassLoaderAware, Ordered

BeanFactoryPostProcessor implementation that allows for convenient registration of custom property editors.

As of Spring 2.0, the recommended usage is to use custom PropertyEditorRegistrar implementations that in turn register any desired editors on a given registry. Each PropertyEditorRegistrar can register any number of custom editors.

 <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
   <property name="propertyEditorRegistrars">
     <list>
       <bean class="mypackage.MyCustomDateEditorRegistrar"/>
       <bean class="mypackage.MyObjectEditorRegistrar"/>
     </list>
   </property>
 </bean>

Alternative configuration example with custom editor classes:

 <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
   <property name="customEditors">
     <map>
       <entry key="java.util.Date" value="mypackage.MyCustomDateEditor"/>
       <entry key="mypackage.MyObject" value="mypackage.MyObjectEditor"/>
     </map>
   </property>
 </bean>

Also supports "java.lang.String[]"-style array class names and primitive class names (e.g. "boolean"). Delegates to ClassUtils for actual class name resolution.

NOTE: Custom property editors registered with this configurer do not apply to data binding. Custom editors for data binding need to be registered on the DataBinder: Use a common base class or delegate to common PropertyEditorRegistrar implementations to reuse editor registration there.

Since:
27.02.2004
Author:
Juergen Hoeller
See Also:
PropertyEditor, PropertyEditorRegistrar, ConfigurableBeanFactory.addPropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar), ConfigurableBeanFactory.registerCustomEditor(java.lang.Class, java.lang.Class), DataBinder.registerCustomEditor(java.lang.Class, java.beans.PropertyEditor), BaseCommandController.setPropertyEditorRegistrars(org.springframework.beans.PropertyEditorRegistrar[]), BaseCommandController.initBinder(javax.servlet.http.HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)

Field Summary
protected  Log logger
           
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
CustomEditorConfigurer()
           
 
Method Summary
 int getOrder()
          Return the order value of this object, with a higher value meaning greater in terms of sorting.
 void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
          Modify the application context's internal bean factory after its standard initialization.
 void setBeanClassLoader(ClassLoader beanClassLoader)
          Callback that supplies the bean class loader to a bean instance.
 void setCustomEditors(Map<String,?> customEditors)
          Specify the custom editors to register via a Map, using the class name of the required type as the key and the class name of the associated PropertyEditor as value.
 void setIgnoreUnresolvableEditors(boolean ignoreUnresolvableEditors)
          Set whether unresolvable editors should simply be skipped.
 void setOrder(int order)
           
 void setPropertyEditorRegistrars(PropertyEditorRegistrar[] propertyEditorRegistrars)
          Specify the PropertyEditorRegistrars to apply to beans defined within the current application context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Constructor Detail

CustomEditorConfigurer

public CustomEditorConfigurer()
Method Detail

setOrder

public void setOrder(int order)

getOrder

public int getOrder()
Description copied from interface: Ordered
Return the order value of this object, with a higher value meaning greater in terms of sorting.

Normally starting with 0, with Integer.MAX_VALUE indicating the greatest value. Same order values will result in arbitrary positions for the affected objects.

Higher values can be interpreted as lower priority. As a consequence, the object with the lowest value has highest priority (somewhat analogous to Servlet "load-on-startup" values).

Specified by:
getOrder in interface Ordered
Returns:
the order value

setPropertyEditorRegistrars

public void setPropertyEditorRegistrars(PropertyEditorRegistrar[] propertyEditorRegistrars)
Specify the PropertyEditorRegistrars to apply to beans defined within the current application context.

This allows for sharing PropertyEditorRegistrars with DataBinders, etc. Furthermore, it avoids the need for synchronization on custom editors: A PropertyEditorRegistrar will always create fresh editor instances for each bean creation attempt.

See Also:
ConfigurableBeanFactory.addPropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar)

setCustomEditors

public void setCustomEditors(Map<String,?> customEditors)
Specify the custom editors to register via a Map, using the class name of the required type as the key and the class name of the associated PropertyEditor as value.

Also supports PropertyEditor instances as values; however, this is deprecated since Spring 2.0.7!

See Also:
ConfigurableBeanFactory.registerCustomEditor(java.lang.Class, java.lang.Class)

setIgnoreUnresolvableEditors

public void setIgnoreUnresolvableEditors(boolean ignoreUnresolvableEditors)
Set whether unresolvable editors should simply be skipped. Default is to raise an exception in such a case.

This typically applies to either the editor class or the required type class not being found in the classpath. If you expect this to happen in some deployments and prefer to simply ignore the affected editors, then switch this flag to "true".


setBeanClassLoader

public void setBeanClassLoader(ClassLoader beanClassLoader)
Description copied from interface: BeanClassLoaderAware
Callback that supplies the bean class loader to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean's InitializingBean.afterPropertiesSet() method or a custom init-method.

Specified by:
setBeanClassLoader in interface BeanClassLoaderAware
Parameters:
beanClassLoader - the owning class loader; may be null in which case a default ClassLoader must be used, for example the ClassLoader obtained via ClassUtils.getDefaultClassLoader()

postProcessBeanFactory

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
                            throws BeansException
Description copied from interface: BeanFactoryPostProcessor
Modify the application context's internal bean factory after its standard initialization. All bean definitions will have been loaded, but no beans will have been instantiated yet. This allows for overriding or adding properties even to eager-initializing beans.

Specified by:
postProcessBeanFactory in interface BeanFactoryPostProcessor
Parameters:
beanFactory - the bean factory used by the application context
Throws:
BeansException - in case of errors