org.ldaptive.props
Class AbstractPropertyInvoker

java.lang.Object
  extended by org.ldaptive.props.AbstractPropertyInvoker
All Implemented Interfaces:
PropertyInvoker
Direct Known Subclasses:
AuthenticationRequestPropertyInvoker, AuthenticatorPropertyInvoker, BindAuthenticationHandlerPropertyInvoker, BindConnectionInitializerPropertyInvoker, BlockingConnectionPoolPropertyInvoker, ConnectionConfigPropertyInvoker, DefaultConnectionFactoryPropertyInvoker, ProviderConfigPropertyInvoker, SearchRequestPropertyInvoker, SimplePropertyInvoker, SslConfigPropertyInvoker

public abstract class AbstractPropertyInvoker
extends Object
implements PropertyInvoker

Provides methods common to property invokers.

Version:
$Revision: 2885 $ $Date: 2014-02-05 16:28:49 -0500 (Wed, 05 Feb 2014) $
Author:
Middleware Services

Constructor Summary
AbstractPropertyInvoker()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPropertyInvoker

public AbstractPropertyInvoker()
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 interface PropertyInvoker
Parameters:
object - to invoke method on
name - of the property
value - 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 into
value - 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 interface PropertyInvoker
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 interface PropertyInvoker
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 create
className - 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 into
value - 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 enum
value - 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 instantiate
s - 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 instantiate
s - 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 instantiate
s - 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 invoke
object - to invoke method on
arg - to invoke method with
Returns:
object produced by the invocation
Throws:
IllegalArgumentException - if an error occurs invoking the method


Copyright © 2003-2015 Virginia Tech. All Rights Reserved.