JBoss Common Beans 1.1.0.Final-redhat-1

org.jboss.common.beans.property
Class BeanUtils

java.lang.Object
  extended by org.jboss.common.beans.property.BeanUtils

public final class BeanUtils
extends Object

Author:
baranowb

Constructor Summary
BeanUtils()
           
 
Method Summary
static Object convertValue(String text, String typeName)
          Convert a string value into the true value for typeName using the PropertyEditor associated with typeName.
static Class<?> findClass(String name)
           
static Class<?> findClass(String name, ClassLoader loader)
           
static Class<?> getPrimitiveTypeForName(String name)
           
static Class<?> getWrapperTypeFor(Class<?> primitive)
           
static boolean isNull(String value)
          Whether a string is interpreted as the null value, including the empty string.
static boolean isNull(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(Object bean, 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(Object bean, 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 String stripClass(Class<?> clazz)
           
static String stripClass(String clazz)
           
static String stripPackage(Class<?> clazz)
           
static String stripPackage(String fqn)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanUtils

public BeanUtils()
Method Detail

stripPackage

public static String stripPackage(String fqn)

stripPackage

public static String stripPackage(Class<?> clazz)

stripClass

public static String stripClass(Class<?> clazz)

stripClass

public static String stripClass(String clazz)

getPrimitiveTypeForName

public static Class<?> getPrimitiveTypeForName(String name)

getWrapperTypeFor

public static Class<?> getWrapperTypeFor(Class<?> primitive)

findClass

public static Class<?> findClass(String name)
                          throws ClassNotFoundException
Throws:
ClassNotFoundException

findClass

public static Class<?> findClass(String name,
                                 ClassLoader loader)
                          throws ClassNotFoundException
Throws:
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(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(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 Object convertValue(String text,
                                  String typeName)
                           throws ClassNotFoundException,
                                  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:
ClassNotFoundException - thrown if the typeName class cannot be found
IntrospectionException - thrown if a PropertyEditor for typeName cannot be found

mapJavaBeanProperties

public static void mapJavaBeanProperties(Object bean,
                                         Properties beanProps)
                                  throws 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:
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(Object bean,
                                         Properties beanProps,
                                         boolean isStrict)
                                  throws 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:
IntrospectionException - thrown on introspection of bean and if a property in beanProps does not map to a property of bean.

JBoss Common Beans 1.1.0.Final-redhat-1

Copyright © 2013 JBoss by Red Hat. All Rights Reserved.