Class AccessorRegistry.Builder

java.lang.Object
org.klojang.templates.AccessorRegistry.Builder
Enclosing class:
AccessorRegistry

public static final class AccessorRegistry.Builder extends Object
A builder class for AccessorRegistry instances.
Author:
Ayco Holleman
  • Method Details

    • setDefaultNameMapper

      public AccessorRegistry.Builder setDefaultNameMapper(NameMapper nameMapper)
      Sets the default NameMapper used to map template variables to bean properties and/or map keys. If no default NameMapper is specified, template variables will be mapped as-is to bean properties and/or map keys.
      Parameters:
      nameMapper - the name mapper
      Returns:
      this Builder instance
    • nullEqualsUndefined

      public AccessorRegistry.Builder nullEqualsUndefined(boolean b)
      Determines whether null values should be treated just like Accessor.UNDEFINED. By default this is not the case.
      Parameters:
      b - whether null values should be treated just like Accessor.UNDEFINED
      Returns:
      this Builder instance
      See Also:
    • setNameMapper

      public AccessorRegistry.Builder setNameMapper(Template template, NameMapper nameMapper)
      Sets the NameMapper to be used for the specified template.
      Parameters:
      template - the template for which to use the specified name mapper
      nameMapper - the name mapper
      Returns:
      this Builder instance
    • register

      public <T> AccessorRegistry.Builder register(Class<T> type, Accessor<T> accessor)
      Sets the Accessor to be used for objects of the specified type.
      Type Parameters:
      T - the type of the objects for which to use the Accessor
      Parameters:
      type - the Class object corresponding to the type
      accessor - the Accessor
      Returns:
      this Builder instance
    • register

      public <T> AccessorRegistry.Builder register(Template template, Class<T> type, Accessor<T> accessor)
      Sets the Accessor to be used for objects of the specified type, when inserted into the specified template.
      Type Parameters:
      T - the type of the objects for which to use the Accessor
      Parameters:
      template - the template for which to use the Accessor
      type - the Class object corresponding to the type
      accessor - the Accessor
      Returns:
      this Builder instance
    • register

      public <T> AccessorRegistry.Builder register(BeanReader<T> br)
      Use the specified BeanReader to access objects of the type the BeanReader can read. Use a BeanReaderBuilder to obtain the BeanReader if you prefer 100% reflection-free bean reading. See BeanReader.forClass(Class).
      Type Parameters:
      T - the type of the beans
      Parameters:
      br - the BeanReader
      Returns:
      this Builder instance
    • register

      public <T> AccessorRegistry.Builder register(BeanReader<T> beanReader, Template template)
      Use the specified BeanReader to access objects of the type the BeanReader can read. Use a BeanReaderBuilder to obtain the BeanReader if you prefer 100% reflection-free bean reading. See BeanReader.forClass(Class).
      Type Parameters:
      T - the type of the beans
      Parameters:
      beanReader - the BeanReader
      template - the template for which to use the accessor (may be a root template or a nested template)
      Returns:
      this Builder instance
    • register

      public <T> AccessorRegistry.Builder register(BeanReader<T> br, NameMapper nameMapper)
      Use the specified BeanReader to access objects of the type the BeanReader can read. Use a BeanReaderBuilder to obtain the BeanReader if you prefer 100% reflection-free bean reading. See BeanReader.forClass(Class).
      Type Parameters:
      T - the type of the beans
      Parameters:
      br - the BeanReader
      nameMapper - the NameMapper to be used to map template variables to bean properties
      Returns:
      this Builder instance
    • register

      public <T> AccessorRegistry.Builder register(BeanReader<T> beanReader, Template template, NameMapper nameMapper)
      Use the specified BeanReader to access objects of the type the BeanReader can read. Use a BeanReaderBuilder to obtain the BeanReader if you prefer 100% reflection-free bean reading. See BeanReader.forClass(Class).
      Type Parameters:
      T - the type of the beans
      Parameters:
      beanReader - the BeanReader
      template - the template for which to use the accessor (may be a root template or a nested template)
      nameMapper - the NameMapper to be used to map template variables to bean properties
      Returns:
      this Builder instance
    • freeze

      public AccessorRegistry freeze()
      Returns an AccessorRegistry with the configured accessors.
      Returns:
      an AccessorRegistry with the configured accessors