Class BeanUtils


  • public final class BeanUtils
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static boolean disableIsNull
      Whether we handle nulls
      private static java.util.logging.Logger logger  
      private static java.lang.String NULL
      The null string
      private static java.util.Map<java.lang.String,​java.lang.Class<?>> PRIMITIVE_NAME_TYPE_MAP
      Primitive type name -> class map.
      private static java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> PRIMITIVES_TO_WRAPPERS  
    • Constructor Summary

      Constructors 
      Constructor Description
      BeanUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void checkDisableNull()  
      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.lang.Class<?> findClass​(java.lang.String name)  
      static java.lang.Class<?> findClass​(java.lang.String name, java.lang.ClassLoader loader)  
      static java.lang.Class<?> getPrimitiveTypeForName​(java.lang.String name)  
      static java.lang.Class<?> getWrapperTypeFor​(java.lang.Class<?> primitive)  
      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 java.lang.String stripClass​(java.lang.Class<?> clazz)  
      static java.lang.String stripClass​(java.lang.String clazz)  
      static java.lang.String stripPackage​(java.lang.Class<?> clazz)  
      static java.lang.String stripPackage​(java.lang.String fqn)  
      • Methods inherited from class java.lang.Object

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

      • logger

        private static final java.util.logging.Logger logger
      • disableIsNull

        private static boolean disableIsNull
        Whether we handle nulls
      • PRIMITIVE_NAME_TYPE_MAP

        private static final java.util.Map<java.lang.String,​java.lang.Class<?>> PRIMITIVE_NAME_TYPE_MAP
        Primitive type name -> class map.
      • PRIMITIVES_TO_WRAPPERS

        private static final java.util.Map<java.lang.Class<?>,​java.lang.Class<?>> PRIMITIVES_TO_WRAPPERS
    • Constructor Detail

      • BeanUtils

        public BeanUtils()
    • Method Detail

      • stripPackage

        public static java.lang.String stripPackage​(java.lang.String fqn)
      • stripPackage

        public static java.lang.String stripPackage​(java.lang.Class<?> clazz)
      • stripClass

        public static java.lang.String stripClass​(java.lang.Class<?> clazz)
      • stripClass

        public static java.lang.String stripClass​(java.lang.String clazz)
      • getPrimitiveTypeForName

        public static java.lang.Class<?> getPrimitiveTypeForName​(java.lang.String name)
      • getWrapperTypeFor

        public static java.lang.Class<?> getWrapperTypeFor​(java.lang.Class<?> primitive)
      • findClass

        public static java.lang.Class<?> findClass​(java.lang.String name)
                                            throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • findClass

        public static java.lang.Class<?> findClass​(java.lang.String name,
                                                   java.lang.ClassLoader loader)
                                            throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • 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.
      • isNull

        public static 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 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
      • 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.
      • checkDisableNull

        private static void checkDisableNull()