org.apache.commons.beanutils

## Class FluentPropertyBeanIntrospector

- java.lang.Object
- - org.apache.commons.beanutils.FluentPropertyBeanIntrospector

- All Implemented Interfaces:
    BeanIntrospector

      public class FluentPropertyBeanIntrospector
      extends Object
      implements BeanIntrospector

  An implementation of the `BeanIntrospector` interface which can detect write methods for properties used in fluent API scenario.

  A fluent API allows setting multiple properties using a single statement by supporting so-called method chaining: Methods for setting a property value do not return void, but an object which can be called for setting another property. An example of such a fluent API could look as follows:

       public class FooBuilder {
           public FooBuilder setFooProperty1(String value) {
              ...
              return this;
          }

           public FooBuilder setFooProperty2(int value) {
              ...
              return this;
          }
       }

  Per default, `PropertyUtils` does not detect methods like this because, having a non-void return type, they violate the Java Beans specification.

  This class is more tolerant with regards to the return type of a set method. It basically iterates over all methods of a class and filters them for a configurable prefix (the default prefix is `set`). It then generates corresponding `PropertyDescriptor` objects for the methods found which use these methods as write methods.

  An instance of this class is intended to collaborate with a `DefaultBeanIntrospector` object. So best results are achieved by adding this instance as custom `BeanIntrospector` after the `DefaultBeanIntrospector` object. Then default introspection finds read-only properties because it does not detect the write methods with a non-void return type. `FluentPropertyBeanIntrospector` completes the descriptors for these properties by setting the correct write method.

  Since:
    1.9
  Version:
    $Id: FluentPropertyBeanIntrospector.java 1746621 2016-06-02 20:01:25Z oheger $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_WRITE_METHOD_PREFIX` The default prefix for write methods.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FluentPropertyBeanIntrospector()` Creates a new instance of `FluentPropertyBeanIntrospector` and sets the default prefix for write methods.
    `FluentPropertyBeanIntrospector(String writePrefix)` Creates a new instance of `FluentPropertyBeanIntrospector` and initializes it with the prefix for write methods used by the classes to be inspected.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getWriteMethodPrefix()` Returns the prefix for write methods this instance scans for.
    `void` | `introspect(IntrospectionContext icontext)` Performs introspection.

    - ### Methods inherited from class java.lang.Object

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

- - ### Field Detail

    - #### DEFAULT_WRITE_METHOD_PREFIX

          public static final String DEFAULT_WRITE_METHOD_PREFIX

      The default prefix for write methods.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### FluentPropertyBeanIntrospector

          public FluentPropertyBeanIntrospector(String writePrefix)

      Creates a new instance of `FluentPropertyBeanIntrospector` and initializes it with the prefix for write methods used by the classes to be inspected.
      Parameters:
        `writePrefix` - the prefix for write methods (must not be null)
      Throws:
        `IllegalArgumentException` - if the prefix is null

    - #### FluentPropertyBeanIntrospector

          public FluentPropertyBeanIntrospector()

      Creates a new instance of `FluentPropertyBeanIntrospector` and sets the default prefix for write methods.

  - ### Method Detail

    - #### getWriteMethodPrefix

          public String getWriteMethodPrefix()

      Returns the prefix for write methods this instance scans for.
      Returns:
        the prefix for write methods

    - #### introspect

          public void introspect(IntrospectionContext icontext)
                          throws IntrospectionException

      Performs introspection. This method scans the current class's methods for property write methods which have not been discovered by default introspection.
      Specified by:
        `introspect` in interface `BeanIntrospector`
      Parameters:
        `icontext` - the introspection context
      Throws:
        `IntrospectionException` - if an error occurs

Copyright © 2000–2016 The Apache Software Foundation. All rights reserved.