Class BusinessObjectFactoryImpl
- All Implemented Interfaces:
BusinessObject,BusinessObjectFactory
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 Summary
FieldsModifier and TypeFieldDescriptionprivate PropertiesThis factory's component settings.private PropertiesThis factory's application settings.private DAOFactoryThis factory'sDAOFactory.private com.google.common.eventbus.EventBusThis factory'sEventBus.private com.google.inject.InjectorThis factory'sInjector.(package private) static org.apache.commons.logging.Logprivate SettingsThis factory'sSettingsinstance.private UserThis factory'sUser. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends BusinessObject>
TcreateObject(Class<T> type) <T extends BusinessObject>
TcreateObject(String type) Creates a business object.<T extends BusinessObject>
TcreateObjectFromClassDefinition(Class classDefinition) <T extends BusinessObject>
TcreateObjectFromClassName(String className) Creates a business object.<T> TcreateUtilsObject(Class<T> type) createUtilsObject(String type) Given a type corresponding to a key in theappComponents.propertiesfile, creates and returns a utility object corresponding to the key.findImplementer(String type) Retrieves the application components previously set for this factory.Retrieves the application settings previously set for this factory.Retrieves theDAOFactorypreviously set for this factory.com.google.common.eventbus.EventBusRetrieves theEventBuspreviously set for this factory.com.google.inject.InjectorRetrieves theInjectorpreviously set for this factory.Retrieves theSettingspreviously set for this factory.Creates aMapof this factory's properties.getUser()Retrieves theUserpreviously set for this factory.invokeMultipleCollectionProcessors(String type, String method, Map argument) Given a type corresponding to a key in theappComponents.propertiesfile, a method name, and a Map as the argument, loops through allBusinessProcessors configured inappComponents.properties, calling each in turn.invokeMultipleProcessors(String type, String method, Map argument) Given a type corresponding to a key in theappComponents.propertiesfile, a method name, and aMapas the argument, loops through allBusinessProcessors configured inappComponents.properties, calling each in turn.voidsetAppComponents(Properties appComponents) Sets this factory's application components.voidsetAppSettings(Properties appSettings) Sets this factory's application settings.voidsetDaoFactory(DAOFactory daoFactory) Sets this factory'sDAOFactory.voidsetEventBus(com.google.common.eventbus.EventBus eventBus) Sets this factory'sEventBus.voidsetInjector(com.google.inject.Injector injector) Sets this factory'sInjector.voidsetSettings(Settings settings) Sets this factory'sSettingsinstance.voidSets this factory'sUser.Methods inherited from class com.softslate.commerce.businessobjects.core.BaseBusinessObject
initialize
-
Field Details
-
log
static org.apache.commons.logging.Log log -
user
This factory'sUser. The currentUseraccessing the system, for which business processing is to be performed by business objects created by this factory. This factory will pass theUserto every business object it creates. -
settings
This factory'sSettingsinstance. The currentSettings, containing various settings to be used by business objects created by this factory. This factory will pass theSettingsto every business object it creates. -
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 theSettingsBean, which stores settings drawn from the database. -
appComponents
This factory's component settings. The component settings identify which Java classes implement the various interfaces used by the system. -
daoFactory
This factory'sDAOFactory. The currentDAOFactoryfor the system, which will allow business objects created by this factory to create data access objects. This factory will pass theDAOFactoryto every business object it creates. -
injector
private com.google.inject.Injector injectorThis factory'sInjector. 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 eventBusThis factory'sEventBus. 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
-
-
Method Details
-
getUser
Description copied from interface:BusinessObjectFactoryRetrieves theUserpreviously set for this factory.- Specified by:
getUserin interfaceBusinessObjectFactory- Returns:
- A
Userobject that represents the user currently accessing the system.
-
setUser
Description copied from interface:BusinessObjectFactorySets this factory'sUser. This factory will pass theUserto every business object it creates.- Specified by:
setUserin interfaceBusinessObjectFactory- Parameters:
user- The currentUseraccessing the system, for which business processing is to be performed by business objects created by this factory.
-
getSettings
Description copied from interface:BusinessObjectFactoryRetrieves theSettingspreviously set for this factory.- Specified by:
getSettingsin interfaceBusinessObjectFactory- Returns:
- A
Settingsobject that represents various settings for the system.
-
setSettings
Description copied from interface:BusinessObjectFactorySets this factory'sSettingsinstance. This factory will pass theSettingsto every business object it creates.- Specified by:
setSettingsin interfaceBusinessObjectFactory- Parameters:
settings- The currentSettingsfor the system, containing various settings to be used by business objects created by this factory.
-
getAppSettings
Description copied from interface:BusinessObjectFactoryRetrieves 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 theSettings, which stores settings drawn from the database.- Specified by:
getAppSettingsin interfaceBusinessObjectFactory- Returns:
- A
Propertiesobject that represents various settings for the application.
-
setAppSettings
Description copied from interface:BusinessObjectFactorySets 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 theSettingsinterface, which stores settings drawn from the database.- Specified by:
setAppSettingsin interfaceBusinessObjectFactory- Parameters:
appSettings- The current application settings in effect for the system.
-
getAppComponents
Description copied from interface:BusinessObjectFactoryRetrieves the application components previously set for this factory. The components identify which Java class implement the various Interfaces used by the system.- Specified by:
getAppComponentsin interfaceBusinessObjectFactory- Returns:
- A
Propertiesobject that represents the components for the application.
-
setAppComponents
Description copied from interface:BusinessObjectFactorySets 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:
setAppComponentsin interfaceBusinessObjectFactory- Parameters:
appComponents- The current application components in effect for the system.
-
getDaoFactory
Description copied from interface:BusinessObjectFactoryRetrieves theDAOFactorypreviously set for this factory.- Specified by:
getDaoFactoryin interfaceBusinessObjectFactory- Returns:
- A
DAOFactoryobject that can be used to create data access objects.
-
setDaoFactory
Description copied from interface:BusinessObjectFactorySets this factory'sDAOFactory. This factory will pass theDAOFactoryto every business object it creates.- Specified by:
setDaoFactoryin interfaceBusinessObjectFactory- Parameters:
daoFactory- The currentDAOFactoryfor 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:BusinessObjectFactoryRetrieves theInjectorpreviously set for this factory.- Specified by:
getInjectorin interfaceBusinessObjectFactory- Returns:
- A
Injectorobject 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:BusinessObjectFactorySets this factory'sInjector. This factory will pass theInjectorto every business object it creates.- Specified by:
setInjectorin interfaceBusinessObjectFactory- Parameters:
injector- The currentInjectorfor 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:BusinessObjectFactoryRetrieves theEventBuspreviously set for this factory.- Specified by:
getEventBusin interfaceBusinessObjectFactory- Returns:
- A
EventBusobject 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:BusinessObjectFactorySets this factory'sEventBus. This factory will pass theEventBusto every business object it creates.- Specified by:
setEventBusin interfaceBusinessObjectFactory- Parameters:
eventBus- The currentEventBusfor the system, which can be used to post events to subscribers
-
createObject
Description copied from interface:BusinessObjectFactoryCreates a business object.A lookup is performed first to find the fully-qualified Java class name of the object to create. The
typeparameter corresponds to a key in theappComponents.propertiesfile. This factory uses itsappComponentsproperty 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:
createObjectin interfaceBusinessObjectFactory- Parameters:
type- AStringassociated 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
- Specified by:
createObjectin interfaceBusinessObjectFactory
-
createObjectFromClassName
Description copied from interface:BusinessObjectFactoryCreates a business object.Using the
classNameparameter, 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:
createObjectFromClassNamein interfaceBusinessObjectFactory- Parameters:
className- AStringassociated 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:
createObjectFromClassDefinitionin interfaceBusinessObjectFactory- Throws:
Exception
-
createUtilsObject
- Specified by:
createUtilsObjectin interfaceBusinessObjectFactory
-
createUtilsObject
Description copied from interface:BusinessObjectFactoryGiven a type corresponding to a key in theappComponents.propertiesfile, 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:
createUtilsObjectin interfaceBusinessObjectFactory- Parameters:
type- AStringsuch as "formUtilsImplementer" corresponding to a key in theappComponents.propertiesfile.- Returns:
- An instance of the requested business object.
-
findImplementer
-
invokeMultipleProcessors
Description copied from interface:BusinessObjectFactoryGiven a type corresponding to a key in theappComponents.propertiesfile, a method name, and aMapas the argument, loops through allBusinessProcessors configured inappComponents.properties, calling each in turn. Returns aMapcompling all the results of eachBusinessProcessorcalled. If any of theBusinessProcessors returns aMapwith a key ofresultCodethat is not equal to "0", processing of all remaining processors is halted, and this method returns immediately.- Specified by:
invokeMultipleProcessorsin interfaceBusinessObjectFactory- Parameters:
type- A String such as "activePaymentProcessors" corresponding to a key in theappComponents.propertiesfile.method- The method of eachBusinessProcessorto invoke in turn.argument- AMaprepresenting the single argument the method accepts.- Returns:
- A
Maprepresenting all the results of each processor combined. They are combined into a singleMapusing theMap.putAll()method. - Throws:
Exception
-
invokeMultipleCollectionProcessors
public Collection invokeMultipleCollectionProcessors(String type, String method, Map argument) throws Exception Description copied from interface:BusinessObjectFactoryGiven a type corresponding to a key in theappComponents.propertiesfile, a method name, and a Map as the argument, loops through allBusinessProcessors configured inappComponents.properties, calling each in turn. Returns aCollectioncompling all the results of eachBusinessProcessorcalled.- Specified by:
invokeMultipleCollectionProcessorsin interfaceBusinessObjectFactory- Parameters:
type- AStringsuch as "activeShippingProcessors" corresponding to a key in theappComponents.propertiesfile.method- The method of eachBusinessProcessorto invoke in turn. (E.g. "loadShippingOptions")argument- AMaprepresenting the single argument the method accepts.- Returns:
- A
Collectionrepresenting all the results of each processor combined. - Throws:
Exception
-
getTransferMap
Description copied from interface:BusinessObjectFactoryCreates aMapof this factory's properties. This factory will pass theMapto theinitialize(Map parameters)method of each business object it creates, which in turn populates the object's properties.- Specified by:
getTransferMapin interfaceBusinessObjectFactory- Returns:
- A
Mapof this factory's properties.
-