Class InitializableBean<B,P extends BeanInitialization>

Object
AnchorBean<B>
InitializableBean<B,P>
Type Parameters:
B - bean-family type
P - initialization-parameters type
Direct Known Subclasses:
DictionaryBean, Feature, FeatureRelatedBean, FilePathBean, ImageBean, MarksBean, NullParametersBean, PointsBean

public abstract class InitializableBean<B,P extends BeanInitialization> extends AnchorBean<B>
A bean that must be initialized with some parameters before being used.
Author:
Owen Feehan
  • Constructor Details

    • InitializableBean

      protected InitializableBean(BeanInitializer<P> beanInitializer, InitializationParameterAssigner propertyInitializer)
      Creates a new InitializableBean instance.
      Parameters:
      beanInitializer - Initializes a bean with another parameter.
      propertyInitializer - Assigns a parameter, if possible, to a bean - as used by bean initializer.
  • Method Details

    • initialize

      public void initialize(P parameters, Logger logger) throws InitializeException
      Initializes the bean with the necessary parameters.

      This method should always be called once before using the other methods of the bean.

      Parameters:
      parameters - parameters to initialize with.
      logger - a logger for events.
      Throws:
      InitializeException - if initialization cannot complete successfully.
    • onInitialization

      public void onInitialization(P initialization) throws InitializeException
      Called after initialization. An empty implementation is provided, to be overridden as needed in the sub-classes.
      Parameters:
      initialization - parameters used for initialization.
      Throws:
      InitializeException - if initialization does not successfully complete.
    • initRecursiveWithInitializer

      public void initRecursiveWithInitializer(BeanInitializer<?> initializer, Logger logger) throws InitializeException
      Initializes the bean and recursively all contained beans (who have compatible initialization requirements)
      Parameters:
      initializer - the property-initializer to use.
      logger - logger.
      Throws:
      InitializeException - if the initialization fails, including if correct initialization-parameters cannot be derived.
    • initializeRecursive

      public void initializeRecursive(P parameters, Logger logger) throws InitializeException
      Initializes this object, and all children objects, so long as they have P once a Bean doesn't have P, the children are not evaluated.
      Parameters:
      parameters - the parameters to initialize with.
      logger - logger.
      Throws:
      InitializeException - if the initialization fails.
    • isInitialized

      public boolean isInitialized()
      Has the been already been initialized via a call to initialize(BeanInitialization, Logger) or similar.
      Returns:
      true iff the bean has been initialized.
    • getLogger

      protected Logger getLogger()
      The logger.
      Returns:
      the logger.
    • getInitialization

      protected P getInitialization() throws InitializeException
      The parameters used for initialization.
      Returns:
      the parameters passed for initialization.
      Throws:
      InitializeException - if the bean has not been initialized.
    • getPropertyInitializer

      public InitializationParameterAssigner getPropertyInitializer()
      Assigns a parameter, if possible, to a bean - as used by bean initializer.