Class CloningPropertyEditorRegistrar

java.lang.Object
net.solarnetwork.support.CloningPropertyEditorRegistrar
All Implemented Interfaces:
org.springframework.beans.PropertyEditorRegistrar

public class CloningPropertyEditorRegistrar extends Object implements org.springframework.beans.PropertyEditorRegistrar
PropertyEditorRegistrar implementation that creates new PropertyEditor instances by cloning the ones configured on this class.

This implementation makes it easy to cofnigure PropertyEditors that are wired up to Spring components but need to be used in a thread-safe manner. Each PropertyEditor must provide a no-argument clone() method to create fully-configured copy of itself.

The configurable properties of this class are:

propertyEditors
Map of property names to associated PropertyEditor instances.
classEditors
Map of Class objects to associated PropertyEditor instances.
lenient
If true (the default) then if a configured PropertyEditor does not provide a public clone() method, this will configure the PropertyEditor as-is, without creating a new copy. If false then a RuntimeException will be thrown if this situation is encountered.
Version:
1.0
Author:
matt
  • Constructor Details

    • CloningPropertyEditorRegistrar

      public CloningPropertyEditorRegistrar()
  • Method Details

    • registerCustomEditors

      public void registerCustomEditors(org.springframework.beans.PropertyEditorRegistry registry)
      Specified by:
      registerCustomEditors in interface org.springframework.beans.PropertyEditorRegistrar
    • setPropertyEditor

      public void setPropertyEditor(String key, PropertyEditor editor)
      Set a PropertyEditor for a specific key.
      Parameters:
      key - the key (property name)
      editor - the associated editor
    • setPropertyEditor

      public void setPropertyEditor(Class<?> clazz, PropertyEditor editor)
      Set a PropertyEditor for a specific Class.
      Parameters:
      clazz - the Class
      editor - the associated editor
    • getPropertyEditors

      public Map<String,PropertyEditor> getPropertyEditors()
      Returns:
      the propertyEditors
    • setPropertyEditors

      public void setPropertyEditors(Map<String,PropertyEditor> propertyEditors)
      Parameters:
      propertyEditors - the propertyEditors to set
    • isLenient

      public boolean isLenient()
      Returns:
      the lenient
    • setLenient

      public void setLenient(boolean lenient)
      Parameters:
      lenient - the lenient to set
    • getClassEditors

      public Map<Class<?>,PropertyEditor> getClassEditors()
      Returns:
      the classEditors
    • setClassEditors

      public void setClassEditors(Map<Class<?>,PropertyEditor> classEditors)
      Parameters:
      classEditors - the classEditors to set