Class ProxyIBeanFactory.Builder

  • Enclosing class:
    ProxyIBeanFactory

    public static class ProxyIBeanFactory.Builder
    extends Object
    Used for creating new instances of ProxyIBeanFactory. Builders are not created by constructor, they are exclusively created by calling ProxyIBeanFactory.builder().
     
     ProxyIBeanFactory factory = ProxyIBeanFactory.builder()
             .withBeanStyle(BeanStyle.MODERN_WITH_OPTIONAL)
             .withToStringStyle(myToStringStyle)
             .withDefaultInterfaceSupport()
             .withInterfaceSupport(extensionSupport1)
             .withInterfaceSupport(extensionSupport2)
             .build();
     
     

    Please note that a newly built ProxyIBeanFactory does not contain any extension interface support by default. Even the standard extension interfaces (like NullSafe or Freezable) are not supported out of the box, you need to use withDefaultInterfaceSupport() when building the factory.

    • Method Detail

      • withMetaInfoParser

        public ProxyIBeanFactory.Builder withMetaInfoParser​(IBeanMetaInfoParser metaInfoParser)
        Sets the IBeanMetaInfoParser to be used by the factory. This method needs to be used only in very rare cases. If not set the factory will use a CachedIBeanMetaInfoParser which is best choice for most cases.

        As a factory uses only one meta parser this method should be called only once for each Builder. If called multiple times only the last call will take effect.

        Parameters:
        metaInfoParser - the IBeanMetaInfoParser to be used in the factory
        Returns:
        the Builder instance itself to enable chained calls
      • withToStringStyle

        public ProxyIBeanFactory.Builder withToStringStyle​(ToStringStyle toStringStyle)
        Determines the ToStringStyle to be used in the built factory.

        As a factory uses only style this method should be called only once for each Builder. If called multiple times only the last call will take effect.

        Parameters:
        toStringStyle - either one of the predefined styles found in ToStringStyle or a custom ToStringStyle implementation
        Returns:
        the Builder instance itself to enable chained calls
      • withBeanStyle

        public ProxyIBeanFactory.Builder withBeanStyle​(BeanStyle beanStyle)
        Determines the BeanStyle to be used in the created factory.

        As a factory uses only style this method should be called only once for each Builder. If called multiple times only the last call will take effect.

        If you are using a custom BeanStyle that is not built in, you might need to provide a BeanStyleHandler as well. In that case use withBeanStyle(BeanStyle, BeanStyleHandler).

        Parameters:
        beanStyle - one of the predefined styles in BeanStyle or a custom BeanStyle implementation
        Returns:
        the Builder instance itself to enable chained calls
      • withBeanStyle

        public ProxyIBeanFactory.Builder withBeanStyle​(BeanStyle beanStyle,
                                                       BeanStyleHandler beanStyleHandler)
        Determines the BeanStyle and its corresponding BeanStyleHandler to be used in the created factory. This method should only be used when providing a custom BeanStyle that is one of the predefined styles of the IBean framework. If you are using a predefined one like BeanStyle.CLASSIC or BeanStyle.MODERN used withBeanStyle(BeanStyle) instead.

        As a factory uses only style this method should be called only once for each Builder. If called multiple times only the last call will take effect.

        Parameters:
        beanStyle - one of the predefined styles in BeanStyle or a custom BeanStyle implementation
        beanStyleHandler - the BeanStyleHandler that corresponds to the given beanStyle
        Returns:
        the Builder instance itself to enable chained calls
      • withInterfaceSupport

        public ProxyIBeanFactory.Builder withInterfaceSupport​(ExtensionSupport support)
        Registers a handler for an extension interface that is supposed to be used in the factory. This method needs to be called for each extension interface that is supposed to be supported by the factory. If you want to use the default handlers for the built in extension interfaces use withDefaultInterfaceSupport() as a shortcut.

        With this method you can determine handler for custom extension interfaces or you can also provide your own handler for one of the built in extension interfaces.

        Following sample code registers custom extension interface ExtInterface with handler ExtHandler:

         ExtensionSupport extSupport = new ExtensionSupport(
                 ExtInterface.class, 
                 ExtHandler.class, 
                 true); //handler stateful
         ProxyIBeanFactory factory = ProxyIBeanFactory.builder()
                 .withDefaultInterfaceSupport()
                 .withInterfaceSupport(extSupport)
                 .build();
         

        Note: this method should be called only once for each extension support. Multiple calls will overwrite prior settings.

        Parameters:
        support - an ExtensionSupport that bundles an extension interface with its handler. All built in handlers already provide an ExtensionSupport instance that can be used to register a built in extension interface with its built in default handler, for example NullSafeHandler.SUPPORT. If handler or interface are custom a specific ExtensionSupport needs to be provided.
        Returns:
        the Builder instance itself to enable chained calls
        See Also:
        IBean overview, ExtensionSupport, ExtensionHandler (for how to implement custom handlers)
      • withDefaultInterfaceSupport

        public ProxyIBeanFactory.Builder withDefaultInterfaceSupport()
        Convenience method that registers all default extension interfaces with their default handlers. Should be used instead of calling withInterfaceSupport(ExtensionSupport) several times.

        Please note that a newly built ProxyIBeanFactory does not contain any extension interface support by default. Even the standard extension interfaces (like NullSafe or Freezable) are not supported out of the box, you need to use this method when building the factory.

        This method should be called only once per factory creation.

        Returns:
        the Builder instance itself to enable chained calls
      • build

        public ProxyIBeanFactory build()
        Finally creates the specified ProxyIBeanFactory. Although it is meant that per builder instance this method is executed only once and as a final call, it is not prohibited that the factory is modified afterwards with further withXXX calls and several factories are created. Still this kind of use is discouraged and might be prohibited in future versions.
        Returns:
        the newly created factory