Interface BusinessObjectFactory
- All Known Implementing Classes:
BusinessObjectFactoryImpl
BusinessObjectFactoryImpl.
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
-
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.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.
-
Method Details
-
getAppSettings
Properties getAppSettings()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 theSettings, which stores settings drawn from the database.- Returns:
- A
Propertiesobject that represents various settings for the application.
-
setAppSettings
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 theSettingsinterface, which stores settings drawn from the database.- Parameters:
appSettings- The current application settings in effect for the system.
-
getAppComponents
Properties getAppComponents()Retrieves the application components previously set for this factory. The components identify which Java class implement the various Interfaces used by the system.- Returns:
- A
Propertiesobject that represents the components for the application.
-
setAppComponents
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.- Parameters:
appComponents- The current application components in effect for the system.
-
getUser
User getUser()Retrieves theUserpreviously set for this factory.- Returns:
- A
Userobject that represents the user currently accessing the system.
-
setUser
Sets this factory'sUser. This factory will pass theUserto every business object it creates.- Parameters:
user- The currentUseraccessing the system, for which business processing is to be performed by business objects created by this factory.
-
getSettings
Settings getSettings()Retrieves theSettingspreviously set for this factory.- Returns:
- A
Settingsobject that represents various settings for the system.
-
setSettings
Sets this factory'sSettingsinstance. This factory will pass theSettingsto every business object it creates.- Parameters:
settings- The currentSettingsfor the system, containing various settings to be used by business objects created by this factory.
-
getDaoFactory
DAOFactory getDaoFactory()Retrieves theDAOFactorypreviously set for this factory.- Returns:
- A
DAOFactoryobject that can be used to create data access objects.
-
setDaoFactory
Sets this factory'sDAOFactory. This factory will pass theDAOFactoryto every business object it creates.- Parameters:
daoFactory- The currentDAOFactoryfor the system, which will allow business objects created by this factory to create data access objects.
-
getInjector
com.google.inject.Injector getInjector()Retrieves theInjectorpreviously set for this factory.- Returns:
- A
Injectorobject that can be used to create other objects and inject them with dependencies.
-
setInjector
void setInjector(com.google.inject.Injector injector) Sets this factory'sInjector. This factory will pass theInjectorto every business object it creates.- Parameters:
injector- The currentInjectorfor the system, which can be used to create other objects and inject them with dependencies.
-
getEventBus
com.google.common.eventbus.EventBus getEventBus()Retrieves theEventBuspreviously set for this factory.- Returns:
- A
EventBusobject that can be used to post events and trigger subscribers to run their code.
-
setEventBus
void setEventBus(com.google.common.eventbus.EventBus eventBus) Sets this factory'sEventBus. This factory will pass theEventBusto every business object it creates.- Parameters:
eventBus- The currentEventBusfor the system, which can be used to post events to subscribers
-
createObject
Creates 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.
- 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
-
createObjectFromClassName
Creates 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.- 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
<T extends BusinessObject> T createObjectFromClassDefinition(Class classDefinition) throws Exception - Throws:
Exception
-
createObject
-
invokeMultipleProcessors
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. 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.- 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
Collection invokeMultipleCollectionProcessors(String type, String method, Map argument) throws Exception 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. Returns aCollectioncompling all the results of eachBusinessProcessorcalled.- 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
-
createUtilsObject
Given 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):
- Parameters:
type- AStringsuch as "formUtilsImplementer" corresponding to a key in theappComponents.propertiesfile.- Returns:
- An instance of the requested business object.
-
createUtilsObject
-
getTransferMap
Map getTransferMap()Creates 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.- Returns:
- A
Mapof this factory's properties.
-