Package org.nuiton.util.beans
Class BeanUtil
java.lang.Object
org.nuiton.util.beans.BeanUtil
public class BeanUtil
extends java.lang.Object
Usefull methods around the
PropertyChangeListener.- Since:
- 1.4.1
- Author:
- Tony Chemit - chemit@codelutin.com
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringADD_PROPERTY_CHANGE_LISTENERstatic com.google.common.base.Predicate<java.beans.PropertyDescriptor>IS_READ_AND_WRITE_DESCRIPTORIs a property is readable and writable ?static com.google.common.base.Predicate<java.beans.PropertyDescriptor>IS_READ_DESCRIPTORIs a property is readable ?static com.google.common.base.Predicate<java.beans.PropertyDescriptor>IS_WRITE_DESCRIPTORIs a property is writable ?static java.lang.StringREMOVE_PROPERTY_CHANGE_LISTENER -
Constructor Summary
Constructors Modifier Constructor Description protectedBeanUtil() -
Method Summary
Modifier and Type Method Description static voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener, java.lang.Object bean)Add the givenlistenerto the givenbeanusing the normalized method namedaddPropertyChangeListener.static java.util.Set<java.beans.PropertyDescriptor>getDescriptors(java.lang.Class<?> beanType, com.google.common.base.Predicate<java.beans.PropertyDescriptor> predicate)Scan the given type and obtainPropertyDescriptorgiven the (optional) predicate (except theclassproperty of any java object).protected static voidgetDescriptors(java.lang.Class<?> beanType, com.google.common.base.Predicate<java.beans.PropertyDescriptor> predicate, java.util.Map<java.lang.String,java.beans.PropertyDescriptor> result, java.util.Set<java.lang.Class<?>> exploredTypes)static java.lang.reflect.MethodgetMutator(java.lang.Object bean, java.lang.String property)static java.util.Set<java.lang.String>getReadableProperties(java.lang.Class<?> beanType)Obtains all readable properties from a given type.protected static voidgetReadableProperties(java.lang.Class<?> beanType, java.util.Set<java.lang.String> result)protected static voidgetReadableProperties(java.lang.Class<?> beanType, java.util.Set<java.lang.String> result, java.util.Set<java.lang.Class<?>> exploredTypes)static java.lang.Class<?>getReadableType(java.lang.Class<?> beanType, java.lang.String propertyName)static java.util.Set<java.lang.String>getWriteableProperties(java.lang.Class<?> beanType)Obtains all writeable properties from a given type.protected static voidgetWriteableProperties(java.lang.Class<?> beanType, java.util.Set<java.lang.String> result)protected static voidgetWriteableProperties(java.lang.Class<?> beanType, java.util.Set<java.lang.String> result, java.util.Set<java.lang.Class<?>> exploredTypes)static booleanisJavaBeanCompiliant(java.lang.Class<?> type)Test if the given type is JavaBean compiliant, says that it has two public methods :addPropertyChangeListenerremovePropertyChangeListenerstatic booleanisNestedReadableProperty(java.lang.Class<?> beanType, java.lang.String propertyName)Obtains all readable properties from a given type.static voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener, java.lang.Object bean)Remove the givenlistenerfrom the givenbeanusing the normalized method namedremovePropertyChangeListener.
-
Field Details
-
ADD_PROPERTY_CHANGE_LISTENER
public static final java.lang.String ADD_PROPERTY_CHANGE_LISTENER- See Also:
- Constant Field Values
-
REMOVE_PROPERTY_CHANGE_LISTENER
public static final java.lang.String REMOVE_PROPERTY_CHANGE_LISTENER- See Also:
- Constant Field Values
-
IS_READ_DESCRIPTOR
public static final com.google.common.base.Predicate<java.beans.PropertyDescriptor> IS_READ_DESCRIPTORIs a property is readable ?- Since:
- 2.5.11
-
IS_WRITE_DESCRIPTOR
public static final com.google.common.base.Predicate<java.beans.PropertyDescriptor> IS_WRITE_DESCRIPTORIs a property is writable ?- Since:
- 2.5.11
-
IS_READ_AND_WRITE_DESCRIPTOR
public static final com.google.common.base.Predicate<java.beans.PropertyDescriptor> IS_READ_AND_WRITE_DESCRIPTORIs a property is readable and writable ?- Since:
- 2.5.11
-
-
Constructor Details
-
BeanUtil
protected BeanUtil()
-
-
Method Details
-
isJavaBeanCompiliant
public static boolean isJavaBeanCompiliant(java.lang.Class<?> type)Test if the given type is JavaBean compiliant, says that it has two public methods :addPropertyChangeListenerremovePropertyChangeListener
- Parameters:
type- type to test- Returns:
trueif type is Javabean compiliant,falseotherwise- Since:
- 2.0
-
addPropertyChangeListener
public static void addPropertyChangeListener(java.beans.PropertyChangeListener listener, java.lang.Object bean) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.IllegalAccessExceptionAdd the givenlistenerto the givenbeanusing the normalized method namedaddPropertyChangeListener.- Parameters:
listener- the listener to addbean- the bean on which the listener is added- Throws:
java.lang.reflect.InvocationTargetException- if could not invoke the methodaddPropertyChangeListenerjava.lang.NoSuchMethodException- if methodaddPropertyChangeListenerdoes not exist on given beanjava.lang.IllegalAccessException- if an illegal access occurs when invoking the methodaddPropertyChangeListener
-
removePropertyChangeListener
public static void removePropertyChangeListener(java.beans.PropertyChangeListener listener, java.lang.Object bean) throws java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.IllegalAccessExceptionRemove the givenlistenerfrom the givenbeanusing the normalized method namedremovePropertyChangeListener.- Parameters:
listener- the listener to removebean- the bean on which the listener is removed- Throws:
java.lang.reflect.InvocationTargetException- if could not invoke the methodremovePropertyChangeListenerjava.lang.NoSuchMethodException- if methodremovePropertyChangeListenerdoes not exist on given beanjava.lang.IllegalAccessException- if an illegal access occurs when invoking the methodremovePropertyChangeListener
-
getReadableProperties
public static java.util.Set<java.lang.String> getReadableProperties(java.lang.Class<?> beanType)Obtains all readable properties from a given type.- Parameters:
beanType- the type to seek- Returns:
- the set of all readable properties for the given type
- Since:
- 2.0
-
getWriteableProperties
public static java.util.Set<java.lang.String> getWriteableProperties(java.lang.Class<?> beanType)Obtains all writeable properties from a given type.- Parameters:
beanType- the type to seek- Returns:
- the set of all writeable properties for the given type
- Since:
- 2.0
-
isNestedReadableProperty
public static boolean isNestedReadableProperty(java.lang.Class<?> beanType, java.lang.String propertyName)Obtains all readable properties from a given type.- Parameters:
beanType- the type to seekpropertyName- FIXME- Returns:
- the set of all readable properties for the given type
- Since:
- 2.0
-
getReadableType
public static java.lang.Class<?> getReadableType(java.lang.Class<?> beanType, java.lang.String propertyName) -
getDescriptors
public static java.util.Set<java.beans.PropertyDescriptor> getDescriptors(java.lang.Class<?> beanType, com.google.common.base.Predicate<java.beans.PropertyDescriptor> predicate)Scan the given type and obtainPropertyDescriptorgiven the (optional) predicate (except theclassproperty of any java object). Note: If no predicate is given, then all descriptors are returned.- Parameters:
beanType- the bean type to scanpredicate- the optional predicate to keep descriptor- Returns:
- set of all matching descriptors
- Since:
- 2.6.11
-
getMutator
public static java.lang.reflect.Method getMutator(java.lang.Object bean, java.lang.String property) -
getDescriptors
protected static void getDescriptors(java.lang.Class<?> beanType, com.google.common.base.Predicate<java.beans.PropertyDescriptor> predicate, java.util.Map<java.lang.String,java.beans.PropertyDescriptor> result, java.util.Set<java.lang.Class<?>> exploredTypes) -
getReadableProperties
protected static void getReadableProperties(java.lang.Class<?> beanType, java.util.Set<java.lang.String> result, java.util.Set<java.lang.Class<?>> exploredTypes) -
getReadableProperties
protected static void getReadableProperties(java.lang.Class<?> beanType, java.util.Set<java.lang.String> result) -
getWriteableProperties
protected static void getWriteableProperties(java.lang.Class<?> beanType, java.util.Set<java.lang.String> result, java.util.Set<java.lang.Class<?>> exploredTypes) -
getWriteableProperties
protected static void getWriteableProperties(java.lang.Class<?> beanType, java.util.Set<java.lang.String> result)
-