Package org.alfresco.util.resource
Class HierarchicalResourceLoader
- java.lang.Object
-
- org.springframework.core.io.DefaultResourceLoader
-
- org.alfresco.util.resource.HierarchicalResourceLoader
-
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean,org.springframework.core.io.ResourceLoader
public class HierarchicalResourceLoader extends org.springframework.core.io.DefaultResourceLoader implements org.springframework.beans.factory.InitializingBeanLocate resources by using a class hierarchy to drive the search. The well-known placeholderDEFAULT_DIALECT_PLACEHOLDERis replaced with successive class names starting from thedialect classand progressing up the hierarchy until thebase classis reached. A full resource search using Spring'sDefaultResourceLoaderis done at each point until the resource is found or the base of the class hierarchy is reached. For example assume classpath resources:
RESOURCE 1: config/ibatis/org.hibernate.dialect.Dialect/SqlMap-DOG.xml RESOURCE 2: config/ibatis/org.hibernate.dialect.MySQLInnoDBDialect/SqlMap-DOG.xml RESOURCE 3: config/ibatis/org.hibernate.dialect.Dialect/SqlMap-CAT.xml RESOURCE 4: config/ibatis/org.hibernate.dialect.MySQLDialect/SqlMap-CAT.xmland
dialectBaseClass = org.hibernate.dialect.DialectFor dialect org.hibernate.dialect.MySQLInnoDBDialect the following will be returned:
config/ibatis/#resource.dialect#/SqlMap-DOG.xml == RESOURCE 2 config/ibatis/#resource.dialect#/SqlMap-CAT.xml == RESOURCE 4For dialectorg.hibernate.dialect.MySQLDBDialect the following will be returned:
config/ibatis/#resource.dialect#/SqlMap-DOG.xml == RESOURCE 1 config/ibatis/#resource.dialect#/SqlMap-CAT.xml == RESOURCE 4For dialectorg.hibernate.dialect.Dialect the following will be returned:
config/ibatis/#resource.dialect#/SqlMap-DOG.xml == RESOURCE 1 config/ibatis/#resource.dialect#/SqlMap-CAT.xml == RESOURCE 3- Since:
- 3.2 (Mobile)
- Author:
- Derek Hulley
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_DIALECT_PLACEHOLDERstatic java.lang.StringDEFAULT_DIALECT_REGEX
-
Constructor Summary
Constructors Constructor Description HierarchicalResourceLoader()Create a new HierarchicalResourceLoader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()org.springframework.core.io.ResourcegetResource(java.lang.String location)Get a resource using the defined class hierarchy as a search path.voidsetDialectBaseClass(java.lang.String className)Set the class to be used during hierarchical dialect replacement.voidsetDialectClass(java.lang.String className)
-
-
-
Field Detail
-
DEFAULT_DIALECT_PLACEHOLDER
public static final java.lang.String DEFAULT_DIALECT_PLACEHOLDER
- See Also:
- Constant Field Values
-
DEFAULT_DIALECT_REGEX
public static final java.lang.String DEFAULT_DIALECT_REGEX
- See Also:
- Constant Field Values
-
-
Method Detail
-
setDialectBaseClass
public void setDialectBaseClass(java.lang.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(java.lang.String className)
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception
-
getResource
public org.springframework.core.io.Resource getResource(java.lang.String location)
Get a resource using the defined class hierarchy as a search path.- Specified by:
getResourcein interfaceorg.springframework.core.io.ResourceLoader- Overrides:
getResourcein classorg.springframework.core.io.DefaultResourceLoader- Parameters:
location- the location including aplaceholder- Returns:
- a resource found by successive searches using class name replacement, or null if not found.
-
-