Package org.jboss.common.beans.property
Class BeanUtils
- java.lang.Object
-
- org.jboss.common.beans.property.BeanUtils
-
public final class BeanUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static boolean
disableIsNull
Whether we handle nullsprivate static java.util.logging.Logger
logger
private static java.lang.String
NULL
The null stringprivate 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 valuestatic boolean
isNullHandlingEnabled()
Will the standard editors return null from theirPropertyEditor.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)
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
NULL
private static final java.lang.String NULL
The null string- See Also:
- Constant Field Values
-
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
-
-
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 theirPropertyEditor.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 valuetrim
- whether to trim the stringempty
- 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 foundjava.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 tobeanProps
- - 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 tobeanProps
- - 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()
-
-