Package com.microstrategy.web.beans
Class BeanFactory
- java.lang.Object
- 
- com.microstrategy.web.beans.BeanFactory
 
- 
- All Implemented Interfaces:
- java.util.Observer
 
 public class BeanFactory extends java.lang.Object implements java.util.ObserverTheBeanFactoryclass allows the user to create both MicroStrategy beans and custom beans. It is used by the MicroStrategy Web application to create beans specified in the page configuration files.
 
 Clients create beans using thenewBeanmethod, which takes a bean type name and retuns an instance of the corresponding bean class. To map a bean name to a bean class, the factory uses a set of bean mappings and an ordered list of packages. A bean mapping maps a bean name (ex: "ReportBean") to a fully qualified classname. The package list provides a set of packages that will be searched in the event that a given bean name isn't explicitly mapped to a class.
 
 Specifically, the logic for creating a bean based on the type name is as follows:- If the bean name is explicitly mapped to a class, instantiate and return an instance of the mapped-to class.
- Otherwise, search the package list in order.  For each package:
 - If there is a package-level factory associated with the package, attempt
 to create the bean by delegating to the factory (a LocalBeanFactoryinstance).
- Otherwise, search the package for a class with a name of the form
 "<bean name> + Impl". If such a class exists, instantiate and return a new instance.
 
- If there is a package-level factory associated with the package, attempt
 to create the bean by delegating to the factory (a 
- If the bean name was not explictly mapped and a corresponding class could
 not be found in any of the packages in the list, throw a
 BeanNotFoundException.
 
 The list of mappings and packages is populated from an XML configuration file, beanFactoryConfig.xml. Users can use the customization infrastructure to augment or modify the set of mappings and packages. A custom beanFactoryConfig.xml might look like this:
 
 <beanfactory-config> <bean-mappings> <bean-mapping bean-name="Bean1" bean-class="test.pkg1.Bean1"/> </bean-mappings> <bean-packages> <bean-package package-name="misc.dummypkg2"/> <bean-package package-name="misc.dummypkg4" local-factory="DummyPkg4Factory"/> </bean-packages> </beanfactory-config>The XML above adds one new mapping, from "Bean1" totest.pkg1.Bean1, to those that already exist. It also appends two packages to the list of packages to search. To create beans in the second package,misc.dummypkg4, theBeanFactorywill delegate to an instance of that package's factory,misc.dummypkg4.DummyPkg4Factory.
 
 A package-level bean factory class specified via thelocal-factoryattribute must meet the following requirements:- It must implement the LocalBeanFactoryinterface. (SeeAbstractLocalBeanFactoryfor a default implementation of this interface.)
- It must contain a method,
 public static <return-type> getInstance();
 that returns an instance of the factory class.
- The newBeanmethod implementation must be thread-safe.
 
 Note:BeanFactoryis a singleton, so any instance-level setters take effect globally.- Since:
- MicroStrategy Web 9.0.0
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classBeanFactory.BeanFactoryInfostatic classBeanFactory.BeanMappingInfostatic classBeanFactory.BeanMappingInfoListstatic classBeanFactory.BeanPackageInfostatic classBeanFactory.BeanPackageInfoList
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()Destroy the HashSet and other caches, will be called when destroying the sevletjava.lang.StringgetConfigurationPath()Get the path for theBeanFactoryconfiguration file.static BeanFactorygetInstance()Return a BeanFactory instance.WebComponentnewBean(java.lang.String beanName)Create a bean based on the bean type name.voidsetConfigurationPath(java.lang.String configPath)Specify the path for the application's beanFactoryConfig.xml file, relative to the root of the application.voidupdate(java.util.Observable o, java.lang.Object arg)Exposed so that this class can update its state when customizations change.
 
- 
- 
- 
Method Detail- 
getInstancepublic static BeanFactory getInstance() Return a BeanFactory instance.- Returns:
- BeanFactory A BeanFactory instance.
 
 - 
updatepublic void update(java.util.Observable o, java.lang.Object arg)Exposed so that this class can update its state when customizations change. Clients should not call this method directly. This method is not threadsafe with respect to otherBeanFactorymethods.- Specified by:
- updatein interface- java.util.Observer
 
 - 
destroypublic void destroy() Destroy the HashSet and other caches, will be called when destroying the sevlet
 - 
setConfigurationPathpublic void setConfigurationPath(java.lang.String configPath) Specify the path for the application's beanFactoryConfig.xml file, relative to the root of the application. This method should be called when the application is initialized, before any instances of this class are used. It is not threadsafe with respect to otherBeanFactoryinstance methods. The value of this property is by default an empty string, which means that no application-level configuration file will be used. (In this case, the factory will contain no bean mappings and a single package:com.microstrategy.web.beans.)- Parameters:
- configPath- The path to the configuration file, relative to the application root directory (ex: "/WEB-INF/xml/config/beanFactoryConfig.xml").
- Throws:
- java.lang.IllegalArgumentException- If- configPathis null.
 
 - 
getConfigurationPathpublic java.lang.String getConfigurationPath() Get the path for theBeanFactoryconfiguration file.- Returns:
- The path to the configuration file, relative to the application root directory (ex: "/WEB-INF/xml/config/beanFactoryConfig.xml").
 
 - 
newBeanpublic WebComponent newBean(java.lang.String beanName) throws java.lang.IllegalArgumentException, BeanNotFoundException, MSTRUncheckedException Create a bean based on the bean type name.- Parameters:
- beanName- The type name of the desired bean (ex: "ReportBean").
- Returns:
- A new WebComponentinstance that corresponds tobeanName.
- Throws:
- java.lang.IllegalArgumentException- If- beanNameis null or empty.
- BeanNotFoundException- If- beanNamecould not be resolved to a class.
- MSTRUncheckedException- If an error occurred in the process of instantiating the bean instance.
 
 
- 
 
-