Class DefaultBeanUtilsPlugin

java.lang.Object
org.sqlproc.engine.plugin.DefaultBeanUtilsPlugin
All Implemented Interfaces:
BeanUtilsPlugin

public class DefaultBeanUtilsPlugin extends Object implements BeanUtilsPlugin
Standard bean utilities implementation.
Author:
Vladimir Hudec
  • Field Details

  • Constructor Details

    • DefaultBeanUtilsPlugin

      public DefaultBeanUtilsPlugin()
  • Method Details

    • getInstanceConstructor

      protected Constructor<?> getInstanceConstructor(SqlRuntimeContext runtimeCtx, Class<?> clazz)
    • getInstance

      public Object getInstance(SqlRuntimeContext runtimeCtx, Class<?> clazz)
      Returns the new class instance
      Specified by:
      getInstance in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      clazz - the class to be constructed
      Returns:
      the new class instance. Null in the case of any error.
    • getDescriptors

      protected PropertyDescriptor[] getDescriptors(Class<?> clazz)
    • getAttributeDescriptor

      protected PropertyDescriptor getAttributeDescriptor(Class<?> clazz, String attrName)
    • getAttributeType

      public Class<?> getAttributeType(SqlRuntimeContext runtimeCtx, Class<?> clazz, String attrName)
      Description copied from interface: BeanUtilsPlugin
      Returns the Java type info for the attribute, if there is one.
      Specified by:
      getAttributeType in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      clazz - the class for which the attribute type is requested
      attrName - the name of the attribute which type is requested
      Returns:
      the object that represents the Java type info. Null in the case there's no such attribute.
    • getAttributeParameterizedTypes

      public Class<?>[] getAttributeParameterizedTypes(SqlRuntimeContext runtimeCtx, Class<?> clazz, String attrName)
      Description copied from interface: BeanUtilsPlugin
      Returns the Java parameterized type info for the attribute, if there is one.
      Specified by:
      getAttributeParameterizedTypes in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      clazz - the class for which the attribute type is requested
      attrName - the name of the attribute which type is requested
      Returns:
      the object that represents the Java parameterized type info. Null in the case there's no such attribute.
    • getGetter

      protected Method getGetter(SqlRuntimeContext runtimeCtx, Class<?> clazz, String attrName, boolean onlyCheck)
    • getGetterType

      public BeanUtilsPlugin.GetterType getGetterType(SqlRuntimeContext runtimeCtx, Class<?> clazz, String attrName)
      Returns the attribute getter method types, if there is one.
      Specified by:
      getGetterType in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      clazz - the class for which the getter is requested
      attrName - the name of the attribute which getter is requested
      Returns:
      The method that should be used to read the property value. Null in the case there's no such attribute's getter.
    • getGetterType

      public BeanUtilsPlugin.GetterType getGetterType(SqlRuntimeContext runtimeCtx, Object bean, String attrName)
      Returns the attribute getter method types, if there is one.
      Specified by:
      getGetterType in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      bean - the bean for which the getter is requested
      attrName - the name of the attribute which getter is requested
      Returns:
      The getter method types that should be used to read the property value. Null in the case there's no such attribute's getter.
    • checkAttribute

      public boolean checkAttribute(SqlRuntimeContext runtimeCtx, Object bean, String attrName)
      Checks the attribute getter method existence.
      Specified by:
      checkAttribute in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      bean - the bean for which the getter is checked
      attrName - the name of the attribute which getter is checked
      Returns:
      True if there's the attribute getter method
    • getAttribute

      public Object getAttribute(SqlRuntimeContext runtimeCtx, Object bean, String attrName) throws SqlRuntimeException
      Returns the value of the specified simple attribute of the specified bean.
      Specified by:
      getAttribute in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      bean - the bean for which the attribute value is requested
      attrName - the name of the attribute which value is requested
      Returns:
      the attribute value
      Throws:
      SqlRuntimeException - in the case of any error
    • getSetter

      protected Method getSetter(SqlRuntimeContext runtimeCtx, Class<?> clazz, String attrName, boolean onlyCheck, Class<?>... attrTypes)
    • getSetter

      protected Method getSetter(SqlRuntimeContext runtimeCtx, Object bean, String attrName, boolean onlyCheck, Class<?>... attrTypes)
    • simpleSetAttribute

      public boolean simpleSetAttribute(SqlRuntimeContext runtimeCtx, Object bean, String attrName, Object attrValue, Class<?>... attrTypes)
      Sets the value of the specified simple attribute of the specified bean, if there is one.
      Specified by:
      simpleSetAttribute in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      bean - the bean for which the attribute value is to be modified
      attrName - the name of the attribute to be modified
      attrValue - the value to which the attribute should be set
      attrTypes - the possible attribute types
      Returns:
      True if the attribute was successfully modified
    • setAttribute

      public void setAttribute(SqlRuntimeContext runtimeCtx, Object bean, String attrName, Object attrValue) throws SqlRuntimeException
      Sets the value of the specified simple attribute of the specified bean.
      Specified by:
      setAttribute in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      bean - the bean for which the attribute value is to be modified
      attrName - the name of the attribute to be modified
      attrValue - the value to which the attribute should be set
      Throws:
      SqlRuntimeException - in the case of any error
    • getMethod

      protected Method getMethod(Class<?> clazz, Method method, boolean onlyCheck)
    • getInterfaceMethod

      protected Method getInterfaceMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes)
    • getSuperclassMethod

      protected Method getSuperclassMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes)
    • getMethod

      protected Method getMethod(Class<?> clazz, String methodName, boolean onlyCheck, Class<?>... parameterTypes)
    • areTheSameParameters

      protected final boolean areTheSameParameters(Class<?> methodParameterType, Class<?> parameterType)
    • getPrimitiveWrapper

      protected Class<?> getPrimitiveWrapper(Class<?> primitiveType)
    • invokeMethod

      protected Object invokeMethod(SqlRuntimeContext runtimeCtx, Object bean, Method method, Object... args)
    • checkMethod

      public boolean checkMethod(SqlRuntimeContext runtimeCtx, Class<?> clazz, String methodName, Class<?>... argTypes)
      Checks the class method existence.
      Specified by:
      checkMethod in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      clazz - the class for which the method existence is checked
      methodName - the name of the method to be checked
      argTypes - the method parameters types
      Returns:
      True if there's such a method
    • checkMethod

      public boolean checkMethod(SqlRuntimeContext runtimeCtx, Object bean, String methodName, Object... args)
      Checks the bean method existence.
      Specified by:
      checkMethod in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      bean - the bean for which the method existence is checked
      methodName - the name of the method to be checked
      args - the method parameters
      Returns:
      True if there's such a method
    • invokeMethod

      public Object invokeMethod(SqlRuntimeContext runtimeCtx, Class<?> clazz, String methodName, Object... args) throws SqlRuntimeException
      Invokes the class method with the specified name and parameters. The method can be a static one.
      Specified by:
      invokeMethod in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      clazz - the class which method is going to be invoked
      methodName - the requested method name
      args - the method parameters
      Returns:
      the result of the method invocation
      Throws:
      SqlRuntimeException - in the case of any error
    • invokeMethod

      public Object invokeMethod(SqlRuntimeContext runtimeCtx, Object bean, String methodName, Object... args) throws SqlRuntimeException
      Invokes the bean method with the specified name and parameters.
      Specified by:
      invokeMethod in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      bean - the bean which method is going to be invoked
      methodName - the requested method name
      args - the method parameters
      Returns:
      the result of the method invocation
      Throws:
      SqlRuntimeException - in the case of any error
    • invokeMethod

      protected Object invokeMethod(SqlRuntimeContext runtimeCtx, Class<?> clazz, Object bean, String methodName, Object... args) throws SqlRuntimeException
      Throws:
      SqlRuntimeException
    • getEnumToValue

      public Object getEnumToValue(SqlRuntimeContext runtimeCtx, Object bean)
      Returns the bean enumeration value.
      Specified by:
      getEnumToValue in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      bean - the bean of the enumeration type
      Returns:
      the enumeration value. Null in the case of any error.
    • getEnumToClass

      public Class<?> getEnumToClass(SqlRuntimeContext runtimeCtx, Class<?> clazz)
      Returns the bean enumeration type.
      Specified by:
      getEnumToClass in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      clazz - the class of the enumeration type
      Returns:
      the enumeration type. Null in the case of any error.
    • getValueToEnum

      public Object getValueToEnum(SqlRuntimeContext runtimeCtx, Class<?> clazz, Object val)
      Returns the enumeration instance for the enumeration value
      Specified by:
      getValueToEnum in interface BeanUtilsPlugin
      Parameters:
      runtimeCtx - the public runtime context
      clazz - the class of the enumeration type
      val - the enumeration value
      Returns:
      the enumeration instance. Null in the case of any error.
    • attrTypes2String

      protected String attrTypes2String(Class<?>... attrTypes)
    • toArray

      protected Object[] toArray(Object arg)
    • toParameterTypes

      protected Class<?>[] toParameterTypes(Object arg)
    • toParameterTypes

      protected Class<?>[] toParameterTypes(Object[] args)
    • debugInfo

      protected String debugInfo(String msg, Object bean, Method method, Object... args)