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.InitializingBean
Locate resources by using a class hierarchy to drive the search. The well-known placeholder DEFAULT_DIALECT_PLACEHOLDER is replaced with successive class names starting from the dialect class and progressing up the hierarchy until the base class is reached. A full resource search using Spring's DefaultResourceLoader is 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.xml
 
and
    dialectBaseClass = org.hibernate.dialect.Dialect
 
For 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 4
 
For 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 4
 
For 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
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.springframework.core.io.DefaultResourceLoader

    org.springframework.core.io.DefaultResourceLoader.ClassPathContextResource
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     

    Fields inherited from interface org.springframework.core.io.ResourceLoader

    CLASSPATH_URL_PREFIX
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new HierarchicalResourceLoader.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    org.springframework.core.io.Resource
    getResource(String location)
    Get a resource using the defined class hierarchy as a search path.
    void
    Set the class to be used during hierarchical dialect replacement.
    void
     

    Methods inherited from class org.springframework.core.io.DefaultResourceLoader

    addProtocolResolver, clearResourceCaches, getClassLoader, getProtocolResolvers, getResourceByPath, getResourceCache, setClassLoader

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • HierarchicalResourceLoader

      public HierarchicalResourceLoader()
      Create a new HierarchicalResourceLoader.
  • Method Details

    • 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 interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • getResource

      public org.springframework.core.io.Resource getResource(String location)
      Get a resource using the defined class hierarchy as a search path.
      Specified by:
      getResource in interface org.springframework.core.io.ResourceLoader
      Overrides:
      getResource in class org.springframework.core.io.DefaultResourceLoader
      Parameters:
      location - the location including a placeholder
      Returns:
      a resource found by successive searches using class name replacement, or null if not found.