Top Description Inners Fields Constructors Methods
liquibase.util

public Class ObjectUtil

extends Object
Class Inheritance
Imports
liquibase.exception.UnexpectedLiquibaseException, liquibase.statement.DatabaseFunction, .SequenceCurrentValueFunction, .SequenceNextValueFunction, java.beans.IntrospectionException, .Introspector, .PropertyDescriptor, .PropertyVetoException, java.io.File, java.lang.reflect.InvocationTargetException, .Method, java.math.BigDecimal, .BigInteger, java.text.ParseException, java.util.*, java.util.concurrent.ConcurrentHashMap

Various methods that make it easier to read and write object properties using the propertyName, instead of having to look up the correct reader/writer methods manually first. All methods in this class are static by nature.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final List<ObjectUtil.BeanIntrospector>
private static final Map<Class<?>, Method[]>
methodCache

Cache for the methods of classes that we have been queried about so far.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <T> T
convert(Object object, Class<T> targetClass)

Converts the given object to the targetClass

public static <T> T
defaultIfNull(T value, T defaultValue)

Return the defaultValue if the passed value is null.

public static PropertyDescriptor[]
getDescriptors(Class<?> targetClass)

private static Method[]

Returns:

array of Method belonging to the class of the object
getMethods
(Object
the object to examine
object
)

Determines the class of a given object and returns an array of that class's methods.

public static Object

Returns:

the stored value
getProperty
(Object
the object to examine
object
,
String
the property name for which the value should be read
propertyName
)

For a given object, try to find the appropriate reader method and return the value, if set for the object.

public static Class<T>

Returns:

the class name of the return type if the reading method is found, null if it is not found.
getPropertyType
(Object
the object to examine
object
,
String
the property name whose reading method should be searched
propertyName
)

Tried to determine the appropriate reader method for a given propertyName of a given object and, if found, returns the class of its return type.

private static Method

Returns:

the Method if found, null in all other cases.
getReadMethod
(Object
the object whose class will be examined
object
,
String
the property name for which the read method should be searched
propertyName
)

Tries to find the Java method to read a given propertyName for the given object.

private static Method

Returns:

the Method if found, null in all other cases.
getWriteMethod
(Object
the object whose class will be examined
object
,
String
the property name for which the write method is to be searched
propertyName
)

Tries to find the Java method to write a new value for a given propertyName to the given object.

public static boolean

Returns:

true if both reader and writer methods exist
hasProperty
(Object
the object for which the class should be examined
object
,
String
the property name to search
propertyName
)

Examines the given object's class and returns true if reader and writer methods both exist for the given property name.

public static boolean

Returns:

true if a reader method exists
hasReadProperty
(Object
the object for which the class should be examined
object
,
String
the property name to search
propertyName
)

Examines the given object's class and returns true if a reader method exists for the given property name.

public static boolean

Returns:

true if a writer method exists
hasWriteProperty
(Object
the object for which the class should be examined
object
,
String
the property name to search
propertyName
)

Examines the given object's class and returns true if a writer method exists for the given property name.

private static void
raiseOverflowException(Number number, Class<T> targetClass)

private static <T> T
public static void
setProperty(Object
the object whose property should be set
object
,
String
name of the property to set
propertyName
,
String
new value of the property, as String
propertyValue
)

Tries to guess the "real" data type of propertyValue by the given propertyName, then sets the selected property of the given object to that value.

public static void
setProperty(Object
the object whose property should be set
object
,
String
name of the property to set
propertyName
,
Object
new value of the property
propertyValue
)

Sets the selected property of the given object to propertyValue.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

introspectorsback to summary
private static final List<ObjectUtil.BeanIntrospector> introspectors
methodCacheback to summary
private static final Map<Class<?>, Method[]> methodCache

Cache for the methods of classes that we have been queried about so far.

Constructor Detail

ObjectUtilback to summary
public ObjectUtil()

Method Detail

convertback to summary
public static <T> T convert(Object object, Class<T> targetClass) throws IllegalArgumentException

Converts the given object to the targetClass

defaultIfNullback to summary
public static <T> T defaultIfNull(T value, T defaultValue)

Return the defaultValue if the passed value is null. Otherwise, return the original value.

getDescriptorsback to summary
public static PropertyDescriptor[] getDescriptors(Class<?> targetClass) throws IntrospectionException
getMethodsback to summary
private static Method[] getMethods(Object object)

Determines the class of a given object and returns an array of that class's methods. The information might come from a cache.

Parameters
object:Object

the object to examine

Returns:Method[]

array of Method belonging to the class of the object

getPropertyback to summary
public static Object getProperty(Object object, String propertyName) throws UnexpectedLiquibaseException

For a given object, try to find the appropriate reader method and return the value, if set for the object. If the property is currently not set for the object, an UnexpectedLiquibaseException run-time exception occurs.

Parameters
object:Object

the object to examine

propertyName:String

the property name for which the value should be read

Returns:Object

the stored value

getPropertyTypeback to summary
public static Class<T> getPropertyType(Object object, String propertyName)

Tried to determine the appropriate reader method for a given propertyName of a given object and, if found, returns the class of its return type.

Parameters
object:Object

the object to examine

propertyName:String

the property name whose reading method should be searched

Returns:Class<T>

the class name of the return type if the reading method is found, null if it is not found.

getReadMethodback to summary
private static Method getReadMethod(Object object, String propertyName)

Tries to find the Java method to read a given propertyName for the given object.

Parameters
object:Object

the object whose class will be examined

propertyName:String

the property name for which the read method should be searched

Returns:Method

the Method if found, null in all other cases.

getWriteMethodback to summary
private static Method getWriteMethod(Object object, String propertyName)

Tries to find the Java method to write a new value for a given propertyName to the given object.

Parameters
object:Object

the object whose class will be examined

propertyName:String

the property name for which the write method is to be searched

Returns:Method

the Method if found, null in all other cases.

hasPropertyback to summary
public static boolean hasProperty(Object object, String propertyName)

Examines the given object's class and returns true if reader and writer methods both exist for the given property name.

Parameters
object:Object

the object for which the class should be examined

propertyName:String

the property name to search

Returns:boolean

true if both reader and writer methods exist

hasReadPropertyback to summary
public static boolean hasReadProperty(Object object, String propertyName)

Examines the given object's class and returns true if a reader method exists for the given property name.

Parameters
object:Object

the object for which the class should be examined

propertyName:String

the property name to search

Returns:boolean

true if a reader method exists

hasWritePropertyback to summary
public static boolean hasWriteProperty(Object object, String propertyName)

Examines the given object's class and returns true if a writer method exists for the given property name.

Parameters
object:Object

the object for which the class should be examined

propertyName:String

the property name to search

Returns:boolean

true if a writer method exists

raiseOverflowExceptionback to summary
private static void raiseOverflowException(Number number, Class<T> targetClass)
raiseUnknownConversionExceptionback to summary
private static <T> T raiseUnknownConversionException(Object object, Class<T> targetClass)
setPropertyback to summary
public static void setProperty(Object object, String propertyName, String propertyValue)

Tries to guess the "real" data type of propertyValue by the given propertyName, then sets the selected property of the given object to that value.

Parameters
object:Object

the object whose property should be set

propertyName:String

name of the property to set

propertyValue:String

new value of the property, as String

setPropertyback to summary
public static void setProperty(Object object, String propertyName, Object propertyValue)

Sets the selected property of the given object to propertyValue. A run-time exception will occur if the type of value is incompatible with the reader/writer method signatures of the given propertyName.

Parameters
object:Object

the object whose property should be set

propertyName:String

name of the property to set

propertyValue:Object

new value of the property

liquibase.util back to summary

private Interface ObjectUtil.BeanIntrospector

Known Direct Implementers
liquibase.util.ObjectUtil.DefaultBeanIntrospector, liquibase.util.ObjectUtil.FluentPropertyBeanIntrospector

Method Summary

Modifier and TypeMethod and Description
public void

Method Detail

introspectback to summary
public void introspect(ObjectUtil.IntrospectionContext context) throws IntrospectionException
liquibase.util back to summary

private Class ObjectUtil.DefaultBeanIntrospector

extends Object
implements BeanIntrospector
Class Inheritance
All Implemented Interfaces
liquibase.util.ObjectUtil.BeanIntrospector

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DefaultBeanIntrospectorback to summary
private DefaultBeanIntrospector()

Method Detail

introspectback to summary
public void introspect(ObjectUtil.IntrospectionContext context) throws IntrospectionException

Implements liquibase.util.ObjectUtil.BeanIntrospector.introspect.

Annotations
@Override
liquibase.util back to summary

private Class ObjectUtil.FluentPropertyBeanIntrospector

extends Object
implements BeanIntrospector
Class Inheritance
All Implemented Interfaces
liquibase.util.ObjectUtil.BeanIntrospector

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

FluentPropertyBeanIntrospectorback to summary
private FluentPropertyBeanIntrospector()

Method Detail

introspectback to summary
public void introspect(ObjectUtil.IntrospectionContext context) throws IntrospectionException

Implements liquibase.util.ObjectUtil.BeanIntrospector.introspect.

Annotations
@Override
liquibase.util back to summary

private Class ObjectUtil.IntrospectionContext

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Map<String, PropertyDescriptor>
private final Class<?>

Constructor Summary

AccessConstructor and Description
public
IntrospectionContext(Class<?> targetClass)

Method Summary

Modifier and TypeMethod and Description
public void
public void
public PropertyDescriptor
public PropertyDescriptor[]
public Class<?>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

descriptorsback to summary
private final Map<String, PropertyDescriptor> descriptors
targetClassback to summary
private final Class<?> targetClass

Constructor Detail

IntrospectionContextback to summary
public IntrospectionContext(Class<?> targetClass)

Method Detail

addDescriptorback to summary
public void addDescriptor(PropertyDescriptor descriptor)
addDescriptorsback to summary
public void addDescriptors(PropertyDescriptor[] descriptors)
getDescriptorback to summary
public PropertyDescriptor getDescriptor(String name)
getDescriptorsback to summary
public PropertyDescriptor[] getDescriptors()
getTargetClassback to summary
public Class<?> getTargetClass()