Package org.ldaptive.props
Class AbstractPropertyInvoker
- java.lang.Object
-
- org.ldaptive.props.AbstractPropertyInvoker
-
- All Implemented Interfaces:
PropertyInvoker
- Direct Known Subclasses:
AuthenticationRequestPropertyInvoker
,AuthenticatorPropertyInvoker
,BeanGeneratorPropertyInvoker
,BindConnectionInitializerPropertyInvoker
,BlockingConnectionPoolPropertyInvoker
,CompareAuthenticationHandlerPropertyInvoker
,ConnectionConfigPropertyInvoker
,DefaultConnectionFactoryPropertyInvoker
,SearchOperationFactoryPropertyInvoker
,SearchRequestPropertyInvoker
,SimpleBindAuthenticationHandlerPropertyInvoker
,SimplePropertyInvoker
,SslConfigPropertyInvoker
public abstract class AbstractPropertyInvoker extends Object implements PropertyInvoker
Provides methods common to property invokers.
-
-
Constructor Summary
Constructors Constructor Description AbstractPropertyInvoker()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Object
convertSimpleType(Class<?> type, String value)
Converts simple types that are common to all property invokers.protected abstract Object
convertValue(Class<?> type, String value)
Converts the supplied string value into an Object of the supplied type.protected Object
createArrayEnumFromPropertyValue(Class<?> c, String s)
Returns the enum array which represents the supplied class given the supplied string representation.protected Object
createArrayTypeFromPropertyValue(Class<?> c, String s)
Returns the object which represents an array of the supplied class given the supplied string representation.static Class<?>
createClass(String className)
Creates the class with the supplied name.protected Object
createTypeFromPropertyValue(Class<?> c, String s)
Returns the object which represents the supplied class given the supplied string representation.protected static Enum<?>
getEnum(Class<?> clazz, String value)
Returns the enum for the supplied type and value.Set<String>
getProperties()
Returns the property keys for this invoker.boolean
hasProperty(String name)
Returns whether the supplied property exists for this invoker.protected void
initialize(Class<?> c)
Initializes the properties cache with the supplied class.static <T> T
instantiateType(T type, String className)
Creates an instance of the supplied type.static Object
invokeMethod(Method method, Object object, Object arg)
Invokes the supplied method on the supplied object with the supplied argument.void
setProperty(Object object, String name, String value)
This invokes the setter method for the supplied property name with the supplied value.
-
-
-
Method Detail
-
initialize
protected void initialize(Class<?> c)
Initializes the properties cache with the supplied class. The cache contains a map of properties to an array of the setter and getter methods. If a method named 'initialize' is found, it is also cached.- Parameters:
c
- to read methods from
-
setProperty
public void setProperty(Object object, String name, String value)
This invokes the setter method for the supplied property name with the supplied value.- Specified by:
setProperty
in interfacePropertyInvoker
- Parameters:
object
- to invoke method onname
- of the propertyvalue
- of the property- Throws:
IllegalArgumentException
- if an invocation exception occurs
-
convertValue
protected abstract Object convertValue(Class<?> type, String value)
Converts the supplied string value into an Object of the supplied type. If value cannot be converted it is returned as is.- Parameters:
type
- of object to convert value intovalue
- to parse- Returns:
- object of the supplied type
-
hasProperty
public boolean hasProperty(String name)
Returns whether the supplied property exists for this invoker.- Specified by:
hasProperty
in interfacePropertyInvoker
- Parameters:
name
- to check- Returns:
- whether the supplied property exists
-
getProperties
public Set<String> getProperties()
Returns the property keys for this invoker.- Specified by:
getProperties
in interfacePropertyInvoker
- Returns:
- set of property names
-
instantiateType
public static <T> T instantiateType(T type, String className)
Creates an instance of the supplied type.- Type Parameters:
T
- type of class returned- Parameters:
type
- of class to createclassName
- to create- Returns:
- class of type T
- Throws:
IllegalArgumentException
- if the supplied class name cannot create a new instance of T
-
createClass
public static Class<?> createClass(String className)
Creates the class with the supplied name.- Parameters:
className
- to create- Returns:
- class
- Throws:
IllegalArgumentException
- if the supplied class name cannot be created
-
convertSimpleType
protected Object convertSimpleType(Class<?> type, String value)
Converts simple types that are common to all property invokers. If value cannot be converted it is returned as is.- Parameters:
type
- of object to convert value intovalue
- to parse- Returns:
- object of the supplied type
-
getEnum
protected static Enum<?> getEnum(Class<?> clazz, String value)
Returns the enum for the supplied type and value.- Parameters:
clazz
- of the enumvalue
- of the enum- Returns:
- enum that matches the supplied value
-
createTypeFromPropertyValue
protected Object createTypeFromPropertyValue(Class<?> c, String s)
Returns the object which represents the supplied class given the supplied string representation.- Parameters:
c
- type to instantiates
- property value to parse- Returns:
- the supplied type or null
-
createArrayTypeFromPropertyValue
protected Object createArrayTypeFromPropertyValue(Class<?> c, String s)
Returns the object which represents an array of the supplied class given the supplied string representation.- Parameters:
c
- type to instantiates
- property value to parse- Returns:
- an array or null
-
createArrayEnumFromPropertyValue
protected Object createArrayEnumFromPropertyValue(Class<?> c, String s)
Returns the enum array which represents the supplied class given the supplied string representation.- Parameters:
c
- type to instantiates
- property value to parse- Returns:
- Enum[] of the supplied type or null
-
invokeMethod
public static Object invokeMethod(Method method, Object object, Object arg)
Invokes the supplied method on the supplied object with the supplied argument.- Parameters:
method
- to invokeobject
- to invoke method onarg
- to invoke method with- Returns:
- object produced by the invocation
- Throws:
IllegalArgumentException
- if an error occurs invoking the method
-
-