Class BusinessObjectFactoryImpl

java.lang.Object
com.softslate.commerce.businessobjects.core.BaseBusinessObject
com.softslate.commerce.businessobjects.core.BusinessObjectFactoryImpl
All Implemented Interfaces:
BusinessObject, BusinessObjectFactory

public class BusinessObjectFactoryImpl extends BaseBusinessObject implements BusinessObjectFactory
Factory class used to create instances of business layer objects. Objects are created with the createObject, createObjectFromClassName, or createUtilsObject methods.

Generally, this class uses its appComponents property to look up the fully-qualified class name of the requested interface (taken from the appComponents.properties file. Then it uses the Java reflection API to create the instance.

An instance of BusinessObjectFactory is created in the Struts layer. Its properties are populated there with the application's DAOFactory, Settings, appComponents, appSettings, and with the User currently accessing the system.

Immediately after instantiating the requested business object, this factory passes its own properties to it so that the newly created object can use them to communicate with the rest of the application.

Author:
David Tobey
  • Field Details

    • log

      static org.apache.commons.logging.Log log
    • user

      private User user
      This factory's User. The current User accessing the system, for which business processing is to be performed by business objects created by this factory. This factory will pass the User to every business object it creates.
    • settings

      private Settings settings
      This factory's Settings instance. The current Settings, containing various settings to be used by business objects created by this factory. This factory will pass the Settings to every business object it creates.
    • appSettings

      private Properties appSettings
      This factory's application settings. The current application settings for the system. This factory will pass the application settings to every business object it creates. The application settings are settings for information unique to a given installation, such as the location of files on the server, as opposed to the SettingsBean, which stores settings drawn from the database.
    • appComponents

      private Properties appComponents
      This factory's component settings. The component settings identify which Java classes implement the various interfaces used by the system.
    • daoFactory

      private DAOFactory daoFactory
      This factory's DAOFactory. The current DAOFactory for the system, which will allow business objects created by this factory to create data access objects. This factory will pass the DAOFactory to every business object it creates.
    • injector

      private com.google.inject.Injector injector
      This factory's Injector. When this BusinessObjectFactory creates and object, it will populate that objects injector property so the object can use it to invoke other objects using dependency injection (Guice).
    • eventBus

      private com.google.common.eventbus.EventBus eventBus
      This factory's EventBus. When this BusinessObjectFactory creates and object, it will populate that object's eventBus property so the object can use it to post events and trigger subscribers to run their code.
  • Constructor Details

    • BusinessObjectFactoryImpl

      public BusinessObjectFactoryImpl()
    • BusinessObjectFactoryImpl

      public BusinessObjectFactoryImpl(Settings settings)
  • Method Details

    • getUser

      public User getUser()
      Description copied from interface: BusinessObjectFactory
      Retrieves the User previously set for this factory.
      Specified by:
      getUser in interface BusinessObjectFactory
      Returns:
      A User object that represents the user currently accessing the system.
    • setUser

      public void setUser(User user)
      Description copied from interface: BusinessObjectFactory
      Sets this factory's User. This factory will pass the User to every business object it creates.
      Specified by:
      setUser in interface BusinessObjectFactory
      Parameters:
      user - The current User accessing the system, for which business processing is to be performed by business objects created by this factory.
    • getSettings

      public Settings getSettings()
      Description copied from interface: BusinessObjectFactory
      Retrieves the Settings previously set for this factory.
      Specified by:
      getSettings in interface BusinessObjectFactory
      Returns:
      A Settings object that represents various settings for the system.
    • setSettings

      public void setSettings(Settings settings)
      Description copied from interface: BusinessObjectFactory
      Sets this factory's Settings instance. This factory will pass the Settings to every business object it creates.
      Specified by:
      setSettings in interface BusinessObjectFactory
      Parameters:
      settings - The current Settings for the system, containing various settings to be used by business objects created by this factory.
    • getAppSettings

      public Properties getAppSettings()
      Description copied from interface: BusinessObjectFactory
      Retrieves the application settings previously set for this factory. The application settings are settings for information unique to a given installation, such as the location of files on the server, as opposed to the Settings, which stores settings drawn from the database.
      Specified by:
      getAppSettings in interface BusinessObjectFactory
      Returns:
      A Properties object that represents various settings for the application.
    • setAppSettings

      public void setAppSettings(Properties appSettings)
      Description copied from interface: BusinessObjectFactory
      Sets this factory's application settings. This factory will pass the application settings to every business object it creates. The application settings are settings for information unique to a given installation, such as the location of files on the server, as opposed to the Settings interface, which stores settings drawn from the database.
      Specified by:
      setAppSettings in interface BusinessObjectFactory
      Parameters:
      appSettings - The current application settings in effect for the system.
    • getAppComponents

      public Properties getAppComponents()
      Description copied from interface: BusinessObjectFactory
      Retrieves the application components previously set for this factory. The components identify which Java class implement the various Interfaces used by the system.
      Specified by:
      getAppComponents in interface BusinessObjectFactory
      Returns:
      A Properties object that represents the components for the application.
    • setAppComponents

      public void setAppComponents(Properties appComponents)
      Description copied from interface: BusinessObjectFactory
      Sets this factory's application components. This factory will pass the application components to every business object it creates. The components identify which Java class implement the various Interfaces used by the system.
      Specified by:
      setAppComponents in interface BusinessObjectFactory
      Parameters:
      appComponents - The current application components in effect for the system.
    • getDaoFactory

      public DAOFactory getDaoFactory()
      Description copied from interface: BusinessObjectFactory
      Retrieves the DAOFactory previously set for this factory.
      Specified by:
      getDaoFactory in interface BusinessObjectFactory
      Returns:
      A DAOFactory object that can be used to create data access objects.
    • setDaoFactory

      public void setDaoFactory(DAOFactory daoFactory)
      Description copied from interface: BusinessObjectFactory
      Sets this factory's DAOFactory. This factory will pass the DAOFactory to every business object it creates.
      Specified by:
      setDaoFactory in interface BusinessObjectFactory
      Parameters:
      daoFactory - The current DAOFactory for the system, which will allow business objects created by this factory to create data access objects.
    • getInjector

      public com.google.inject.Injector getInjector()
      Description copied from interface: BusinessObjectFactory
      Retrieves the Injector previously set for this factory.
      Specified by:
      getInjector in interface BusinessObjectFactory
      Returns:
      A Injector object that can be used to create other objects and inject them with dependencies.
    • setInjector

      public void setInjector(com.google.inject.Injector injector)
      Description copied from interface: BusinessObjectFactory
      Sets this factory's Injector. This factory will pass the Injector to every business object it creates.
      Specified by:
      setInjector in interface BusinessObjectFactory
      Parameters:
      injector - The current Injector for the system, which can be used to create other objects and inject them with dependencies.
    • getEventBus

      public com.google.common.eventbus.EventBus getEventBus()
      Description copied from interface: BusinessObjectFactory
      Retrieves the EventBus previously set for this factory.
      Specified by:
      getEventBus in interface BusinessObjectFactory
      Returns:
      A EventBus object that can be used to post events and trigger subscribers to run their code.
    • setEventBus

      public void setEventBus(com.google.common.eventbus.EventBus eventBus)
      Description copied from interface: BusinessObjectFactory
      Sets this factory's EventBus. This factory will pass the EventBus to every business object it creates.
      Specified by:
      setEventBus in interface BusinessObjectFactory
      Parameters:
      eventBus - The current EventBus for the system, which can be used to post events to subscribers
    • createObject

      public <T extends BusinessObject> T createObject(String type) throws Exception
      Description copied from interface: BusinessObjectFactory
      Creates a business object.

      A lookup is performed first to find the fully-qualified Java class name of the object to create. The type parameter corresponds to a key in the appComponents.properties file. This factory uses its appComponents property to perform the lookup.

      If the Java class name is found, an object is created, and then this factory populates it with its own properties. These properties allow the newly create object to communicate with the rest of the application.

      Specified by:
      createObject in interface BusinessObjectFactory
      Parameters:
      type - A String associated with the class name of the business object to be created.
      Returns:
      An instance of the requested business object, or null, if an error occurs.
      Throws:
      Exception
    • createObject

      public <T extends BusinessObject> T createObject(Class<T> type)
      Specified by:
      createObject in interface BusinessObjectFactory
    • createObjectFromClassName

      public <T extends BusinessObject> T createObjectFromClassName(String className) throws Exception
      Description copied from interface: BusinessObjectFactory
      Creates a business object.

      Using the className parameter, this factory creates an object, and then populates it with its own properties. These properties allow the newly create object to communicate with the rest of the application.

      Specified by:
      createObjectFromClassName in interface BusinessObjectFactory
      Parameters:
      className - A String associated with the class name of the business object to be created.
      Returns:
      An instance of the requested business object, or null, if an error occurs.
      Throws:
      Exception
    • createObjectFromClassDefinition

      public <T extends BusinessObject> T createObjectFromClassDefinition(Class classDefinition) throws Exception
      Specified by:
      createObjectFromClassDefinition in interface BusinessObjectFactory
      Throws:
      Exception
    • createUtilsObject

      public <T> T createUtilsObject(Class<T> type)
      Specified by:
      createUtilsObject in interface BusinessObjectFactory
    • createUtilsObject

      public Object createUtilsObject(String type)
      Description copied from interface: BusinessObjectFactory
      Given a type corresponding to a key in the appComponents.properties file, creates and returns a utility object corresponding to the key.

      If no class can be instantiated for the given class name, an instance of one of the following classes is automatically returned (depending on the value of the type parameter):

      Specified by:
      createUtilsObject in interface BusinessObjectFactory
      Parameters:
      type - A String such as "formUtilsImplementer" corresponding to a key in the appComponents.properties file.
      Returns:
      An instance of the requested business object.
    • findImplementer

      public String findImplementer(String type)
    • invokeMultipleProcessors

      public Map invokeMultipleProcessors(String type, String method, Map argument) throws Exception
      Description copied from interface: BusinessObjectFactory
      Given a type corresponding to a key in the appComponents.properties file, a method name, and a Map as the argument, loops through all BusinessProcessors configured in appComponents.properties, calling each in turn. Returns a Map compling all the results of each BusinessProcessor called. If any of the BusinessProcessors returns a Map with a key of resultCode that is not equal to "0", processing of all remaining processors is halted, and this method returns immediately.
      Specified by:
      invokeMultipleProcessors in interface BusinessObjectFactory
      Parameters:
      type - A String such as "activePaymentProcessors" corresponding to a key in the appComponents.properties file.
      method - The method of each BusinessProcessor to invoke in turn.
      argument - A Map representing the single argument the method accepts.
      Returns:
      A Map representing all the results of each processor combined. They are combined into a single Map using the Map.putAll() method.
      Throws:
      Exception
    • invokeMultipleCollectionProcessors

      public Collection invokeMultipleCollectionProcessors(String type, String method, Map argument) throws Exception
      Description copied from interface: BusinessObjectFactory
      Given a type corresponding to a key in the appComponents.properties file, a method name, and a Map as the argument, loops through all BusinessProcessors configured in appComponents.properties, calling each in turn. Returns a Collection compling all the results of each BusinessProcessor called.
      Specified by:
      invokeMultipleCollectionProcessors in interface BusinessObjectFactory
      Parameters:
      type - A String such as "activeShippingProcessors" corresponding to a key in the appComponents.properties file.
      method - The method of each BusinessProcessor to invoke in turn. (E.g. "loadShippingOptions")
      argument - A Map representing the single argument the method accepts.
      Returns:
      A Collection representing all the results of each processor combined.
      Throws:
      Exception
    • getTransferMap

      public Map getTransferMap()
      Description copied from interface: BusinessObjectFactory
      Creates a Map of this factory's properties. This factory will pass the Map to the initialize(Map parameters) method of each business object it creates, which in turn populates the object's properties.
      Specified by:
      getTransferMap in interface BusinessObjectFactory
      Returns:
      A Map of this factory's properties.