Package com.microstrategy.web.beans
Class AbstractLocalBeanFactory
- java.lang.Object
-
- com.microstrategy.web.beans.AbstractLocalBeanFactory
-
- All Implemented Interfaces:
LocalBeanFactory
- Direct Known Subclasses:
AdminBeanFactory
,AppBeanFactory
,WebBeanFactory
public abstract class AbstractLocalBeanFactory extends java.lang.Object implements LocalBeanFactory
Default implementation of theLocalBeanFactory
interface that resolves bean type names to bean classes by appending "Impl" to the bean type name. A given subclass should implementgetBeanPackage()
to specify the package associated with the factory. If the factory supports creating non-public bean implementation classes,createBeanInstance(java.lang.Class)
can be overridden to create the actual bean instances. OverridegetBeanClassName(java.lang.String)
to change the way bean type names are resolved to class names. Note that the implementation caches resolved bean class objects, so a given bean type name is only resolved to a bean class name once.- Since:
- MicroStrategy Web 9.0.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractLocalBeanFactory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
canCreateBean(java.lang.String beanName)
Check whether this factory can create a bean with a given type name.protected WebComponent
createBeanInstance(java.lang.Class beanClass)
Create an instance ofbeanClass
.protected java.lang.String
getBeanClassName(java.lang.String beanName)
Resolve a bean type name to a fully qualified class name (ex: "ReportBean" --> "com.microstrategy.web.beans.ReportBeanImpl").protected abstract java.lang.String
getBeanPackage()
Returns the full name of the package associated with this factory (ex: "com.microstrategy.web.beans").WebComponent
newBean(java.lang.String beanName)
Create a bean based on the bean type name.
-
-
-
Method Detail
-
newBean
public WebComponent newBean(java.lang.String beanName) throws java.lang.IllegalArgumentException, BeanNotFoundException, MSTRUncheckedException
Create a bean based on the bean type name. This implementation will look for a bean class named "<pkg name>.<beanName>Impl
", where<pkg name>
is the string returned bygetBeanPackage()
. This method will callgetBeanClassName(java.lang.String)
to resolvebeanName
to a class name, andcreateBeanInstance(java.lang.Class)
to create the bean instance.- Specified by:
newBean
in interfaceLocalBeanFactory
- Parameters:
beanName
- The type name of the desired bean (ex: "ReportBean").- Returns:
- A new
WebComponent
instance that corresponds tobeanName
. - Throws:
java.lang.IllegalArgumentException
- IfbeanName
is null or empty.BeanNotFoundException
- IfbeanName
could not be resolved to a class.MSTRUncheckedException
- If an error occurred in the process of instantiating the bean instance.
-
getBeanClassName
protected java.lang.String getBeanClassName(java.lang.String beanName)
Resolve a bean type name to a fully qualified class name (ex: "ReportBean" --> "com.microstrategy.web.beans.ReportBeanImpl"). This implementation simply returnsgetBeanPackage() + "." + beanName + "Impl"
. Override this method to change the way bean type names are resolved to class names.- Parameters:
beanName
- Bean type name to resolve.- Returns:
- Fully qualified bean class name corresponding to
beanName
.
-
createBeanInstance
protected WebComponent createBeanInstance(java.lang.Class beanClass) throws java.lang.IllegalAccessException, java.lang.InstantiationException
Create an instance ofbeanClass
. This implementation simply callsbeanClass.newInstance()
. Override this method in a derived class to create instances of non-public bean classes. Throws the same exceptions asClass.newInstance()
.- Parameters:
beanClass
- The class of the desired bean.- Returns:
- An instance of the desired bean class.
- Throws:
java.lang.IllegalAccessException
java.lang.InstantiationException
-
getBeanPackage
protected abstract java.lang.String getBeanPackage()
Returns the full name of the package associated with this factory (ex: "com.microstrategy.web.beans").- Returns:
- The name of the package associated with this factory.
-
canCreateBean
public boolean canCreateBean(java.lang.String beanName)
Check whether this factory can create a bean with a given type name. If this method returns false for a given bean type name, then callingnewBean(java.lang.String)
with that bean type name will result in aBeanNotFoundException
.- Specified by:
canCreateBean
in interfaceLocalBeanFactory
- Parameters:
beanName
- The type name of the bean to check.- Returns:
- true if this factory can create a bean for
beanName
; false otherwise.
-
-