Class PropertyEditors


  • public class PropertyEditors
    extends java.lang.Object
    A collection of PropertyEditor utilities. Provides the same interface as PropertyEditorManager plus more...

    Installs the default PropertyEditors.

    Version:
    $Revision$
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static boolean disableIsNull
      Whether we handle nulls
      private static boolean initialized
      Whether or not initialization of the editor search path has been done
      private static org.jboss.logging.Logger log
      The Logger object
      private static java.lang.String NULL
      The null string
    • Constructor Summary

      Constructors 
      Constructor Description
      PropertyEditors()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object convertValue​(java.lang.String text, java.lang.String typeName)
      Convert a string value into the true value for typeName using the PropertyEditor associated with typeName.
      static java.beans.PropertyEditor findEditor​(java.lang.Class<?> type)
      Locate a value editor for a given target type.
      static java.beans.PropertyEditor findEditor​(java.lang.String typeName)
      Locate a value editor for a given target type.
      static java.beans.PropertyEditor getEditor​(java.lang.Class<?> type)
      Get a value editor for a given target type.
      static java.beans.PropertyEditor getEditor​(java.lang.String typeName)
      Get a value editor for a given target type.
      java.lang.String[] getEditorSearchPath()
      Gets the package names that will be searched for property editors.
      static void init()
      Augment the PropertyEditorManager search path to incorporate the JBoss specific editors by appending the org.jboss.util.propertyeditor package to the PropertyEditorManager editor search path.
      static boolean isNull​(java.lang.String value)
      Whether a string is interpreted as the null value, including the empty string.
      static boolean isNull​(java.lang.String value, boolean trim, boolean empty)
      Whether a string is interpreted as the null value
      static boolean isNullHandlingEnabled()
      Will the standard editors return null from their PropertyEditor.setAsText(String) method for non-primitive targets?
      static void mapJavaBeanProperties​(java.lang.Object bean, java.util.Properties beanProps)
      This method takes the properties found in the given beanProps to the bean using the property editor registered for the property.
      static void mapJavaBeanProperties​(java.lang.Object bean, java.util.Properties beanProps, boolean isStrict)
      This method takes the properties found in the given beanProps to the bean using the property editor registered for the property.
      static void registerEditor​(java.lang.Class<?> type, java.lang.Class<?> editorType)
      Register an editor class to be used to editor values of a given target class.
      static void registerEditor​(java.lang.String typeName, java.lang.String editorTypeName)
      Register an editor class to be used to editor values of a given target class.
      void setEditorSearchPath​(java.lang.String[] path)
      Sets the package names that will be searched for property editors.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • log

        private static org.jboss.logging.Logger log
        The Logger object
      • disableIsNull

        private static boolean disableIsNull
        Whether we handle nulls
      • initialized

        private static boolean initialized
        Whether or not initialization of the editor search path has been done
    • Constructor Detail

      • PropertyEditors

        public PropertyEditors()
    • Method Detail

      • init

        public static void init()
        Augment the PropertyEditorManager search path to incorporate the JBoss specific editors by appending the org.jboss.util.propertyeditor package to the PropertyEditorManager editor search path.
      • isNull

        public static final boolean isNull​(java.lang.String value)
        Whether a string is interpreted as the null value, including the empty string.
        Parameters:
        value - the value
        Returns:
        true when the string has the value null
      • isNull

        public static final boolean isNull​(java.lang.String value,
                                           boolean trim,
                                           boolean empty)
        Whether a string is interpreted as the null value
        Parameters:
        value - the value
        trim - whether to trim the string
        empty - whether to include the empty string as null
        Returns:
        true when the string has the value null
      • isNullHandlingEnabled

        public static boolean isNullHandlingEnabled()
        Will the standard editors return null from their PropertyEditor.setAsText(String) method for non-primitive targets?
        Returns:
        True if nulls can be returned; false otherwise.
      • findEditor

        public static java.beans.PropertyEditor findEditor​(java.lang.Class<?> type)
        Locate a value editor for a given target type.
        Parameters:
        type - The class of the object to be edited.
        Returns:
        An editor for the given type or null if none was found.
      • findEditor

        public static java.beans.PropertyEditor findEditor​(java.lang.String typeName)
                                                    throws java.lang.ClassNotFoundException
        Locate a value editor for a given target type.
        Parameters:
        typeName - The class name of the object to be edited.
        Returns:
        An editor for the given type or null if none was found.
        Throws:
        java.lang.ClassNotFoundException - when the class could not be found
      • getEditor

        public static java.beans.PropertyEditor getEditor​(java.lang.Class<?> type)
        Get a value editor for a given target type.
        Parameters:
        type - The class of the object to be edited.
        Returns:
        An editor for the given type.
        Throws:
        java.lang.RuntimeException - No editor was found.
      • getEditor

        public static java.beans.PropertyEditor getEditor​(java.lang.String typeName)
                                                   throws java.lang.ClassNotFoundException
        Get a value editor for a given target type.
        Parameters:
        typeName - The class name of the object to be edited.
        Returns:
        An editor for the given type.
        Throws:
        java.lang.RuntimeException - No editor was found.
        java.lang.ClassNotFoundException - when the class is not found
      • registerEditor

        public static void registerEditor​(java.lang.Class<?> type,
                                          java.lang.Class<?> editorType)
        Register an editor class to be used to editor values of a given target class.
        Parameters:
        type - The class of the objetcs to be edited.
        editorType - The class of the editor.
      • registerEditor

        public static void registerEditor​(java.lang.String typeName,
                                          java.lang.String editorTypeName)
                                   throws java.lang.ClassNotFoundException
        Register an editor class to be used to editor values of a given target class.
        Parameters:
        typeName - The classname of the objetcs to be edited.
        editorTypeName - The class of the editor.
        Throws:
        java.lang.ClassNotFoundException - when the class could not be found
      • convertValue

        public static java.lang.Object convertValue​(java.lang.String text,
                                                    java.lang.String typeName)
                                             throws java.lang.ClassNotFoundException,
                                                    java.beans.IntrospectionException
        Convert a string value into the true value for typeName using the PropertyEditor associated with typeName.
        Parameters:
        text - the string represention of the value. This is passed to the PropertyEditor.setAsText method.
        typeName - the fully qualified class name of the true value type
        Returns:
        the PropertyEditor.getValue() result
        Throws:
        java.lang.ClassNotFoundException - thrown if the typeName class cannot be found
        java.beans.IntrospectionException - thrown if a PropertyEditor for typeName cannot be found
      • mapJavaBeanProperties

        public static void mapJavaBeanProperties​(java.lang.Object bean,
                                                 java.util.Properties beanProps)
                                          throws java.beans.IntrospectionException
        This method takes the properties found in the given beanProps to the bean using the property editor registered for the property. Any property in beanProps that does not have an associated java bean property will result in an IntrospectionException. The string property values are converted to the true java bean property type using the java bean PropertyEditor framework. If a property in beanProps does not have a PropertyEditor registered it will be ignored.
        Parameters:
        bean - - the java bean instance to apply the properties to
        beanProps - - map of java bean property name to property value.
        Throws:
        java.beans.IntrospectionException - thrown on introspection of bean and if a property in beanProps does not map to a property of bean.
      • mapJavaBeanProperties

        public static void mapJavaBeanProperties​(java.lang.Object bean,
                                                 java.util.Properties beanProps,
                                                 boolean isStrict)
                                          throws java.beans.IntrospectionException
        This method takes the properties found in the given beanProps to the bean using the property editor registered for the property. Any property in beanProps that does not have an associated java bean property will result in an IntrospectionException. The string property values are converted to the true java bean property type using the java bean PropertyEditor framework. If a property in beanProps does not have a PropertyEditor registered it will be ignored.
        Parameters:
        bean - - the java bean instance to apply the properties to
        beanProps - - map of java bean property name to property value.
        isStrict - - indicates if should throw exception if bean property can not be matched. True for yes, false for no.
        Throws:
        java.beans.IntrospectionException - thrown on introspection of bean and if a property in beanProps does not map to a property of bean.
      • getEditorSearchPath

        public java.lang.String[] getEditorSearchPath()
        Gets the package names that will be searched for property editors.
        Returns:
        The package names that will be searched for property editors.
      • setEditorSearchPath

        public void setEditorSearchPath​(java.lang.String[] path)
        Sets the package names that will be searched for property editors.
        Parameters:
        path - The serach path.