org.springframework.beans.factory.xml
Class PluggableSchemaResolver

java.lang.Object
  extended by org.springframework.beans.factory.xml.PluggableSchemaResolver
All Implemented Interfaces:
org.xml.sax.EntityResolver

public class PluggableSchemaResolver
extends java.lang.Object
implements org.xml.sax.EntityResolver

EntityResolver implementation that attempts to resolve schema URLs into local classpath resources using a set of mappings files.

By default, this class will look for mapping files in the classpath using the pattern: META-INF/spring.schemas allowing for multiple files to exist on the classpath at any one time. The format of META-INF/spring.schemas is a properties file where each line should be of the form systemId=schema-location where schema-location should also be a schema file in the classpath. Since systemId is commonly a URL, one must be careful to escape any ':' characters which are treated as delimiters in properties files.

The pattern for the mapping files can be overidden using the PluggableSchemaResolver(ClassLoader, String) constructor

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller

Field Summary
private  java.lang.ClassLoader classLoader
           
static java.lang.String DEFAULT_SCHEMA_MAPPINGS_LOCATION
          The location of the file that defines schema mappings.
private static Log logger
           
private  java.util.Map<java.lang.String,java.lang.String> schemaMappings
          Stores the mapping of schema URL -> local schema path
private  java.lang.String schemaMappingsLocation
           
 
Constructor Summary
PluggableSchemaResolver(java.lang.ClassLoader classLoader)
          Loads the schema URL -> schema file location mappings using the default mapping file pattern "META-INF/spring.schemas".
PluggableSchemaResolver(java.lang.ClassLoader classLoader, java.lang.String schemaMappingsLocation)
          Loads the schema URL -> schema file location mappings using the given mapping file pattern.
 
Method Summary
private  java.util.Map<java.lang.String,java.lang.String> getSchemaMappings()
          Load the specified schema mappings lazily.
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SCHEMA_MAPPINGS_LOCATION

public static final java.lang.String DEFAULT_SCHEMA_MAPPINGS_LOCATION
The location of the file that defines schema mappings. Can be present in multiple JAR files.

See Also:
Constant Field Values

logger

private static final Log logger

classLoader

private final java.lang.ClassLoader classLoader

schemaMappingsLocation

private final java.lang.String schemaMappingsLocation

schemaMappings

private volatile java.util.Map<java.lang.String,java.lang.String> schemaMappings
Stores the mapping of schema URL -> local schema path

Constructor Detail

PluggableSchemaResolver

public PluggableSchemaResolver(java.lang.ClassLoader classLoader)
Loads the schema URL -> schema file location mappings using the default mapping file pattern "META-INF/spring.schemas".

Parameters:
classLoader - the ClassLoader to use for loading (can be null) to use the default ClassLoader)
See Also:
PropertiesLoaderUtils.loadAllProperties(String, ClassLoader)

PluggableSchemaResolver

public PluggableSchemaResolver(java.lang.ClassLoader classLoader,
                               java.lang.String schemaMappingsLocation)
Loads the schema URL -> schema file location mappings using the given mapping file pattern.

Parameters:
classLoader - the ClassLoader to use for loading (can be null) to use the default ClassLoader)
schemaMappingsLocation - the location of the file that defines schema mappings (must not be empty)
See Also:
PropertiesLoaderUtils.loadAllProperties(String, ClassLoader)
Method Detail

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
                                      throws java.io.IOException
Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Throws:
java.io.IOException

getSchemaMappings

private java.util.Map<java.lang.String,java.lang.String> getSchemaMappings()
Load the specified schema mappings lazily.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object