IntrospectionUtils (Apache Tomcat 11.0.24 API Documentation)
Description: declaration: package: org.apache.tomcat.util, class: IntrospectionUtils

# Class IntrospectionUtils

java.lang.Object
org.apache.tomcat.util.IntrospectionUtils

public final class IntrospectionUtils extends Object
Utils for introspection and reflection

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static interface`
  `IntrospectionUtils.PropertySource`
  Interface for a source of named properties used during introspection.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Object`
  `callMethod1(Object target, String methodN, Object param1, String typeParam1, ClassLoader cl)`
  Call a method with a single parameter on the given target object.
  `static Object`
  `callMethodN(Object target, String methodN, Object[] params, Class<?>[] typeParams)`
  Call a method with multiple parameters on the given target object.
  `static String`
  `capitalize(String name)`
  Reverse of Introspector.decapitalize.
  `static void`
  `clear()`
  Clear the internal method cache.
  `static Object`
  `convert(String object, Class<?> paramType)`
  Convert a string value to the specified type.
  `static String`
  `escape(String s)`
  Escapes special characters in a string for use in generated code.
  `static Method`
  `findMethod(Class<?> c, String name, Class<?>[] params)`
  Find a specific method by name and parameter types.
  `static Method[]`
  `findMethods(Class<?> c)`
  Find all public methods of the given class, using a cache for performance.
  `static Object`
  `getProperty(Object o, String name)`
  Get the value of a property from the given object.
  `static boolean`
  `isInstance(Class<?> clazz, String type)`
  Checks to see if the specified class is an instance of or assignable from the specified type.
  `static String`
  `replaceProperties(String value, Hashtable<Object,Object> staticProp, IntrospectionUtils.PropertySource[] dynamicProp, ClassLoader classLoader)`
  Replaces ${NAME} in the value with the value of the property 'NAME'.
  `static boolean`
  `setProperty(Object o, String name, String value)`
  Find a method with the right name If found, call the method ( if param is int or boolean we'll convert value to the right type before) - that means you can have setDebug(1).
  `static boolean`
  `setProperty(Object o, String name, String value, boolean invokeSetProperty)`
  Set a property on the given object.
  `static boolean`
  `setProperty(Object o, String name, String value, boolean invokeSetProperty, StringBuilder actualMethod)`
  Set a property on the given object, tracking the actual method called.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### setProperty

    public static boolean setProperty(Object o, String name, String value)
    Find a method with the right name If found, call the method ( if param is int or boolean we'll convert value to the right type before) - that means you can have setDebug(1).
    Parameters:
      `o` - The object to set a property on
      `name` - The property name
      `value` - The property value
    Returns:
      `true` if operation was successful

  - ### setProperty

    public static boolean setProperty(Object o, String name, String value, boolean invokeSetProperty)
    Set a property on the given object.
    Parameters:
      `o` - the object to set the property on
      `name` - the property name
      `value` - the property value
      `invokeSetProperty` - whether to invoke setProperty as a fallback
    Returns:
      `true` if the operation was successful

  - ### setProperty

    public static boolean setProperty(Object o, String name, String value, boolean invokeSetProperty, StringBuilder actualMethod)
    Set a property on the given object, tracking the actual method called.
    Parameters:
      `o` - the object to set the property on
      `name` - the property name
      `value` - the property value
      `invokeSetProperty` - whether to invoke setProperty as a fallback
      `actualMethod` - StringBuilder to append the actual method call to, or `null`
    Returns:
      `true` if the operation was successful

  - ### escape

    public static String escape(String s)
    Escapes special characters in a string for use in generated code.
    Parameters:
      `s` - the input string
    Returns:
      the escaped string with double quotes, backslashes, newlines and carriage returns escaped

  - ### getProperty

    public static Object getProperty(Object o, String name)
    Get the value of a property from the given object.
    Parameters:
      `o` - the object to get the property from
      `name` - the property name
    Returns:
      the property value, or `null` if not found

  - ### replaceProperties

    public static String replaceProperties(String value, Hashtable<Object,Object> staticProp, IntrospectionUtils.PropertySource[] dynamicProp, ClassLoader classLoader)
    Replaces ${NAME} in the value with the value of the property 'NAME'. Replaces ${NAME:DEFAULT} with the value of the property 'NAME:DEFAULT', if the property 'NAME:DEFAULT' is not set, the expression is replaced with the value of the property 'NAME', if the property 'NAME' is not set, the expression is replaced with 'DEFAULT'. If the property is not set and there is no default the value will be returned unmodified.
    Parameters:
      `value` - The value
      `staticProp` - Replacement properties
      `dynamicProp` - Replacement properties
      `classLoader` - Class loader associated with the code requesting the property
    Returns:
      the replacement value

  - ### capitalize

    public static String capitalize(String name)
    Reverse of Introspector.decapitalize.
    Parameters:
      `name` - The name
    Returns:
      the capitalized string

  - ### clear

    public static void clear()
    Clear the internal method cache.

  - ### findMethods

    public static Method[] findMethods(Class<?> c)
    Find all public methods of the given class, using a cache for performance.
    Parameters:
      `c` - the class
    Returns:
      the array of methods

  - ### findMethod

    public static Method findMethod(Class<?> c, String name, Class<?>[] params)
    Find a specific method by name and parameter types.
    Parameters:
      `c` - the class
      `name` - the method name
      `params` - the parameter types, or `null` for no parameters
    Returns:
      the matching method, or `null` if not found

  - ### callMethod1

    public static Object callMethod1(Object target, String methodN, Object param1, String typeParam1, ClassLoader cl) throws Exception
    Call a method with a single parameter on the given target object.
    Parameters:
      `target` - the target object
      `methodN` - the method name
      `param1` - the parameter value
      `typeParam1` - the parameter type name, or `null` to infer from the parameter
      `cl` - the class loader to use for loading the parameter type
    Returns:
      the result of the method call
    Throws:
      `Exception` - if the method cannot be found or invoked

  - ### callMethodN

    public static Object callMethodN(Object target, String methodN, Object[] params, Class<?>[] typeParams) throws Exception
    Call a method with multiple parameters on the given target object.
    Parameters:
      `target` - the target object
      `methodN` - the method name
      `params` - the parameter values
      `typeParams` - the parameter types
    Returns:
      the result of the method call, or `null` if the method cannot be found
    Throws:
      `Exception` - if the method cannot be invoked

  - ### convert

    public static Object convert(String object, Class<?> paramType)
    Convert a string value to the specified type.
    Parameters:
      `object` - the string value to convert
      `paramType` - the target type
    Returns:
      the converted object
    Throws:
      `IllegalArgumentException` - if conversion fails

  - ### isInstance

    public static boolean isInstance(Class<?> clazz, String type)
    Checks to see if the specified class is an instance of or assignable from the specified type. The class `clazz`, all its superclasses, interfaces and those superinterfaces are tested for a match against the type name `type`. This is similar to `instanceof` or `Class.isAssignableFrom(Class)` except that the target type will not be resolved into a Class object, which provides some security and memory benefits.
    Parameters:
      `clazz` - The class to test for a match.
      `type` - The name of the type that `clazz` must be.
    Returns:
      `true` if the `clazz` tested is an instance of the specified `type`, `false` otherwise.