Package org.alfresco.util.bean
Class HierarchicalBeanLoader
- java.lang.Object
-
- org.alfresco.util.bean.HierarchicalBeanLoader
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.FactoryBean
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.ApplicationContextAware
public class HierarchicalBeanLoader extends Object implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.FactoryBean, org.springframework.context.ApplicationContextAware
Factory bean to find beans using a class hierarchy to drive the lookup. The well-known placeholderDEFAULT_DIALECT_PLACEHOLDER
is replaced with successive class names starting from thedialect class
and progressing up the hierarchy until thebase class
is reached. The bean is looked up in the context at each point until the bean is found or the base of the class hierarchy is reached. For example assume bean names:
BEAN 1: contentDAO.org.hibernate.dialect.Dialect BEAN 2: contentDAO.org.hibernate.dialect.MySQLInnoDBDialect BEAN 3: propertyValueDAO.org.hibernate.dialect.Dialect BEAN 4: propertyValueDAO.org.hibernate.dialect.MySQLDialect
and
dialectBaseClass = org.hibernate.dialect.Dialect
For dialect org.hibernate.dialect.MySQLInnoDBDialect the following will be returned:
contentDAO.bean.dialect == BEAN 2 propertyValueDAO.bean.dialect == BEAN 4
For dialectorg.hibernate.dialect.MySQLDBDialect the following will be returned:
contentDAO.bean.dialect == BEAN 1 propertyValueDAO.bean.dialect == BEAN 4
For dialectorg.hibernate.dialect.Dialect the following will be returned:
contentDAO.bean.dialect == BEAN 1 propertyValueDAO.bean.dialect == BEAN 3
- Since:
- 3.2SP1
- Author:
- Derek Hulley
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_DIALECT_PLACEHOLDER
static String
DEFAULT_DIALECT_REGEX
-
Constructor Summary
Constructors Constructor Description HierarchicalBeanLoader()
Create a new HierarchicalResourceLoader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
Object
getObject()
Replaces theClass<?>
getObjectType()
boolean
isSingleton()
void
setApplicationContext(org.springframework.context.ApplicationContext ctx)
The application context that this bean factory serves.void
setDialectBaseClass(String className)
Set the class to be used during hierarchical dialect replacement.void
setDialectClass(String className)
void
setTargetBeanName(String targetBeanName)
void
setTargetClass(Class<?> targetClass)
Set the target class that will be returned bygetObjectType()
-
-
-
Field Detail
-
DEFAULT_DIALECT_PLACEHOLDER
public static final String DEFAULT_DIALECT_PLACEHOLDER
- See Also:
- Constant Field Values
-
DEFAULT_DIALECT_REGEX
public static final String DEFAULT_DIALECT_REGEX
- See Also:
- Constant Field Values
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext ctx)
The application context that this bean factory serves.- Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
-
setTargetBeanName
public void setTargetBeanName(String targetBeanName)
- Parameters:
targetBeanName
- the name of the target bean to return, including theDEFAULT_DIALECT_PLACEHOLDER
where the specific dialect must be replaced.
-
setTargetClass
public void setTargetClass(Class<?> targetClass)
Set the target class that will be returned bygetObjectType()
- Parameters:
targetClass
- the type that this factory returns
-
setDialectBaseClass
public void setDialectBaseClass(String className)
Set the class to be used during hierarchical dialect replacement. Searches for the configuration location will not go further up the hierarchy than this class.- Parameters:
className
- the name of the class or interface
-
setDialectClass
public void setDialectClass(String className)
-
afterPropertiesSet
public void afterPropertiesSet() throws Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
getObjectType
public Class<?> getObjectType()
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean
- Returns:
- Returns
target class
-
isSingleton
public boolean isSingleton()
- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.FactoryBean
- Returns:
- Returns true always
-
-