org.openpermis.editor.policy.beans
Class BeanUtilities

java.lang.Object
  extended by org.openpermis.editor.policy.beans.BeanUtilities

final class BeanUtilities
extends Object

Utility functions around Java Beans.

Since:
0.1.0

Field Summary
private static String ADD
          Method name of 'addPropertyChangeListener' support method.
private static int[] ARG_COUNT
          An array of allowed number of arguments in a property change method.
private static int ARG_NEW_VALUE
          The new value argument position in a property change method.
private static int ARG_OLD_VALUE
          The old value argument position in a property change method.
private static int ARG_PROPERTY
          The property argument position in a property change method.
private static int ARG_SOURCE
          The source argument position in a property change method.
private static String GET_PREFIX
          Prefix of Java Beans getter methods.
private static String IS_PREFIX
          Alternative prefix of Java Beans boolean getter methods.
private static String REMOVE
          Method name of 'removePropertyChangeListener' support method.
private static String SET_PREFIX
          Prefix of Java Beans setter methods.
 
Constructor Summary
private BeanUtilities()
          Objects of this class cannot be instantiated.
 
Method Summary
static
<T> T
addPropertyChangeListener(T bean, PropertyChangeListener listener)
          Registers the specified property change listener at the given bean.
static Map<String,Method> getPropertyChangeMethods(Class<?> beanClass, Class<?> targetClass)
          Builds a map of methods with a PropertyChange annotation.
static Method getter(Class<?> beanClass, String property)
          Finds the method for the getter of the specified property.
(package private) static String getterName(String property, boolean booleanValue)
          Returns the method name of the getter for the specified property.
static boolean isJavaBean(Class<?> cls)
          Tests if the specified class provides Java Beans support.
static boolean isJavaBean(Object object)
          Tests if the specified object is a Java Bean.
static Method method(Class<?> cls, String methodName, Class<?> parameterClass)
          Returns the method with the specified name and parameter class in the given class.
private static String methodName(String prefix, String property)
          Composes a method name given the specified prefix and property name.
static
<T> T
removePropertyChangeListener(T bean, PropertyChangeListener listener)
          Deregisters the specified property change listener from the given bean.
static Method setter(Class<?> beanClass, String property)
          Finds the method for the setter of the specified property.
(package private) static String setterName(String property)
          Returns the method name of the setter for the specified property.
(package private) static String signature(Object beanOrClass, String methodName, Class<?> parameterClass)
          Returns the signature of the specified method.
(package private) static void validate(Method method, PropertyChange pc)
          Validates the property change object and throws illegal state exceptions if it is not valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADD

private static final String ADD
Method name of 'addPropertyChangeListener' support method.

Constant Field Value:
"addPropertyChangeListener"
Since:
0.1.0

REMOVE

private static final String REMOVE
Method name of 'removePropertyChangeListener' support method.

Constant Field Value:
"removePropertyChangeListener"
Since:
0.1.0

SET_PREFIX

private static final String SET_PREFIX
Prefix of Java Beans setter methods.

Constant Field Value:
"set"
Since:
0.1.0

GET_PREFIX

private static final String GET_PREFIX
Prefix of Java Beans getter methods.

Constant Field Value:
"get"
Since:
0.1.0

IS_PREFIX

private static final String IS_PREFIX
Alternative prefix of Java Beans boolean getter methods.

Constant Field Value:
"is"
Since:
0.1.0

ARG_COUNT

private static final int[] ARG_COUNT
An array of allowed number of arguments in a property change method.

Since:
0.1.0

ARG_SOURCE

private static final int ARG_SOURCE
The source argument position in a property change method.

Constant Field Value:
0
Since:
0.1.0

ARG_PROPERTY

private static final int ARG_PROPERTY
The property argument position in a property change method.

Constant Field Value:
1
Since:
0.1.0

ARG_OLD_VALUE

private static final int ARG_OLD_VALUE
The old value argument position in a property change method.

Constant Field Value:
2
Since:
0.1.0

ARG_NEW_VALUE

private static final int ARG_NEW_VALUE
The new value argument position in a property change method.

Constant Field Value:
3
Since:
0.1.0
Constructor Detail

BeanUtilities

private BeanUtilities()
Objects of this class cannot be instantiated.

Since:
0.1.0
Method Detail

methodName

private static final String methodName(String prefix,
                                       String property)
Composes a method name given the specified prefix and property name.

Parameters:
prefix - the prefix to use.
property - the name of the property, must not be null or empty.
Returns:
the method name requested.
Since:
0.1.0

getterName

static final String getterName(String property,
                               boolean booleanValue)
Returns the method name of the getter for the specified property.

Parameters:
property - the name of the property, must not be null or empty.
booleanValue - indicates if the property is a boolean value.
Returns:
the method name of the getter for the specified property.
Since:
0.1.0

setterName

static final String setterName(String property)
Returns the method name of the setter for the specified property.

Parameters:
property - the name of the property, must not be null or empty.
Returns:
the method name of the setter for the specified property.
Since:
0.1.0

signature

static String signature(Object beanOrClass,
                        String methodName,
                        Class<?> parameterClass)
Returns the signature of the specified method.

Returns the name of the method including its parameter type if non-null.

Parameters:
beanOrClass - the bean or the bean class for which to create the signature.
methodName - the name of the method.
parameterClass - the parameter type or null if the method has no parameters.
Returns:
the signature requested.
Since:
0.1.0

method

public static Method method(Class<?> cls,
                            String methodName,
                            Class<?> parameterClass)
Returns the method with the specified name and parameter class in the given class.

Parameters:
cls - the class for which to retrieve the method, must not be null.
methodName - the name of the method, must not be null or empty.
parameterClass - the type of the parameter, may be null for methods without any parameters.
Returns:
the method requested, null if the method does not exist.
Since:
0.1.0

getter

public static Method getter(Class<?> beanClass,
                            String property)
Finds the method for the getter of the specified property.

Notes:
The return type is not checked.
Parameters:
beanClass - the Java bean class to search for the getter, must not be null.
property - the name of the property, must not be null or empty.
Returns:
the getter requested or null if there is no such getter.
Since:
0.1.0

setter

public static Method setter(Class<?> beanClass,
                            String property)
Finds the method for the setter of the specified property.

Notes:
The parameter type is not checked.
Parameters:
beanClass - the Java bean class to search for the setter, must not be null.
property - the name of the property, must not be null or empty.
Returns:
the getter requested or null if there is no such setter.
Since:
0.1.0

isJavaBean

public static boolean isJavaBean(Class<?> cls)
Tests if the specified class provides Java Beans support.

Parameters:
cls - the class to test, may be null.
Returns:
true if the class provides Java Beans support.
Since:
0.1.0

isJavaBean

public static boolean isJavaBean(Object object)
Tests if the specified object is a Java Bean.

Parameters:
object - the object to test, may be null.
Returns:
true if the object is a Java Bean.
Since:
0.1.0

validate

static void validate(Method method,
                     PropertyChange pc)
Validates the property change object and throws illegal state exceptions if it is not valid.

Parameters:
method - the method to validate the object for, must not be null (not checked).
pc - the property change object to validate, must not be null (not checked).
Throws:
IllegalStateException - if the property change object is invalid.
Since:
0.1.0

getPropertyChangeMethods

public static Map<String,Method> getPropertyChangeMethods(Class<?> beanClass,
                                                          Class<?> targetClass)
Builds a map of methods with a PropertyChange annotation.

Parameters:
beanClass - the bean class for which to build the map, must not be null.
targetClass - the class for which to build the map, must not be null.
Returns:
the map containing property names as keys and methods as values.
Since:
0.1.0

addPropertyChangeListener

public static <T> T addPropertyChangeListener(T bean,
                                              PropertyChangeListener listener)
Registers the specified property change listener at the given bean.

Parameters:
bean - the bean to add the property change listener to, must not be null.
listener - the listener to add, must not be null.
Returns:
the bean passed in for fluent use.
Throws:
IllegalArgumentException - if the object passed in is not a Java Bean.
IllegalStateException - if there is an error registering.
Since:
0.1.0

removePropertyChangeListener

public static <T> T removePropertyChangeListener(T bean,
                                                 PropertyChangeListener listener)
Deregisters the specified property change listener from the given bean.

Parameters:
bean - the bean to remove the listener from, must not be null.
listener - the listener to remove, must not be null.
Returns:
the bean passed in for fluent use.
Throws:
IllegalArgumentException - if the object passed in is not a Java Bean.
IllegalStateException - if there is an error deregistering.
Since:
0.1.0


PERMIS Role Based Access Control 0.4.0 (Build 15)
2009/05/20 08:15:22
Copyright (c) 2002-2007 Ergon Informatik AG