org.springframework.orm.jpa.persistenceunit
Class PersistenceUnitReader

java.lang.Object
  extended by org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader

 class PersistenceUnitReader
extends java.lang.Object

Internal helper class for reading persistence.xml files.

Since:
2.0
Author:
Costin Leau, Juergen Hoeller

Field Summary
private  DataSourceLookup dataSourceLookup
           
private static java.lang.String EXCLUDE_UNLISTED_CLASSES
           
private static java.lang.String JAR_FILE_URL
           
private static java.lang.String JTA_DATA_SOURCE
           
private  Log logger
           
private static java.lang.String MANAGED_CLASS_NAME
           
private static java.lang.String MAPPING_FILE_NAME
           
private static java.lang.String META_INF
           
private static java.lang.String NON_JTA_DATA_SOURCE
           
private static java.lang.String PERSISTENCE_UNIT
           
private static java.lang.String PERSISTENCE_VERSION
           
private static java.lang.String PROPERTIES
           
private static java.lang.String PROVIDER
           
private  ResourcePatternResolver resourcePatternResolver
           
private static java.lang.String SHARED_CACHE_MODE
           
private static java.lang.String TRANSACTION_TYPE
           
private static java.lang.String UNIT_NAME
           
private static java.lang.String VALIDATION_MODE
           
 
Constructor Summary
PersistenceUnitReader(ResourcePatternResolver resourcePatternResolver, DataSourceLookup dataSourceLookup)
          Create a new PersistenceUnitReader.
 
Method Summary
protected  org.w3c.dom.Document buildDocument(org.xml.sax.ErrorHandler handler, java.io.InputStream stream)
          Validate the given stream and return a valid DOM document for parsing.
protected  java.net.URL determinePersistenceUnitRootUrl(Resource resource)
          Determine the persistence unit root URL based on the given resource (which points to the persistence.xml file we're reading).
protected  void parseClass(org.w3c.dom.Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)
          Parse the class XML elements.
protected  java.util.List<SpringPersistenceUnitInfo> parseDocument(Resource resource, org.w3c.dom.Document document, java.util.List<SpringPersistenceUnitInfo> infos)
          Parse the validated document and add entries to the given unit info list.
protected  void parseJarFiles(org.w3c.dom.Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)
          Parse the jar-file XML elements.
protected  void parseMappingFiles(org.w3c.dom.Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)
          Parse the mapping-file XML elements.
protected  SpringPersistenceUnitInfo parsePersistenceUnitInfo(org.w3c.dom.Element persistenceUnit, java.lang.String version)
          Parse the unit info DOM element.
protected  void parseProperty(org.w3c.dom.Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)
          Parse the property XML elements.
 SpringPersistenceUnitInfo[] readPersistenceUnitInfos(java.lang.String persistenceXmlLocation)
          Parse and build all persistence unit infos defined in the specified XML file(s).
 SpringPersistenceUnitInfo[] readPersistenceUnitInfos(java.lang.String[] persistenceXmlLocations)
          Parse and build all persistence unit infos defined in the given XML files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PERSISTENCE_VERSION

private static final java.lang.String PERSISTENCE_VERSION
See Also:
Constant Field Values

PERSISTENCE_UNIT

private static final java.lang.String PERSISTENCE_UNIT
See Also:
Constant Field Values

UNIT_NAME

private static final java.lang.String UNIT_NAME
See Also:
Constant Field Values

MAPPING_FILE_NAME

private static final java.lang.String MAPPING_FILE_NAME
See Also:
Constant Field Values

JAR_FILE_URL

private static final java.lang.String JAR_FILE_URL
See Also:
Constant Field Values

MANAGED_CLASS_NAME

private static final java.lang.String MANAGED_CLASS_NAME
See Also:
Constant Field Values

PROPERTIES

private static final java.lang.String PROPERTIES
See Also:
Constant Field Values

PROVIDER

private static final java.lang.String PROVIDER
See Also:
Constant Field Values

TRANSACTION_TYPE

private static final java.lang.String TRANSACTION_TYPE
See Also:
Constant Field Values

JTA_DATA_SOURCE

private static final java.lang.String JTA_DATA_SOURCE
See Also:
Constant Field Values

NON_JTA_DATA_SOURCE

private static final java.lang.String NON_JTA_DATA_SOURCE
See Also:
Constant Field Values

EXCLUDE_UNLISTED_CLASSES

private static final java.lang.String EXCLUDE_UNLISTED_CLASSES
See Also:
Constant Field Values

SHARED_CACHE_MODE

private static final java.lang.String SHARED_CACHE_MODE
See Also:
Constant Field Values

VALIDATION_MODE

private static final java.lang.String VALIDATION_MODE
See Also:
Constant Field Values

META_INF

private static final java.lang.String META_INF
See Also:
Constant Field Values

logger

private final Log logger

resourcePatternResolver

private final ResourcePatternResolver resourcePatternResolver

dataSourceLookup

private final DataSourceLookup dataSourceLookup
Constructor Detail

PersistenceUnitReader

public PersistenceUnitReader(ResourcePatternResolver resourcePatternResolver,
                             DataSourceLookup dataSourceLookup)
Create a new PersistenceUnitReader.

Parameters:
resourcePatternResolver - the ResourcePatternResolver to use for loading resources
dataSourceLookup - the DataSourceLookup to resolve DataSource names in persistence.xml files against
Method Detail

readPersistenceUnitInfos

public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(java.lang.String persistenceXmlLocation)
Parse and build all persistence unit infos defined in the specified XML file(s).

Parameters:
persistenceXmlLocation - the resource location (can be a pattern)
Returns:
the resulting PersistenceUnitInfo instances

readPersistenceUnitInfos

public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(java.lang.String[] persistenceXmlLocations)
Parse and build all persistence unit infos defined in the given XML files.

Parameters:
persistenceXmlLocations - the resource locations (can be patterns)
Returns:
the resulting PersistenceUnitInfo instances

buildDocument

protected org.w3c.dom.Document buildDocument(org.xml.sax.ErrorHandler handler,
                                             java.io.InputStream stream)
                                      throws javax.xml.parsers.ParserConfigurationException,
                                             org.xml.sax.SAXException,
                                             java.io.IOException
Validate the given stream and return a valid DOM document for parsing.

Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException

parseDocument

protected java.util.List<SpringPersistenceUnitInfo> parseDocument(Resource resource,
                                                                  org.w3c.dom.Document document,
                                                                  java.util.List<SpringPersistenceUnitInfo> infos)
                                                           throws java.io.IOException
Parse the validated document and add entries to the given unit info list.

Throws:
java.io.IOException

determinePersistenceUnitRootUrl

protected java.net.URL determinePersistenceUnitRootUrl(Resource resource)
                                                throws java.io.IOException
Determine the persistence unit root URL based on the given resource (which points to the persistence.xml file we're reading).

Parameters:
resource - the resource to check
Returns:
the corresponding persistence unit root URL
Throws:
java.io.IOException - if the checking failed

parsePersistenceUnitInfo

protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(org.w3c.dom.Element persistenceUnit,
                                                             java.lang.String version)
                                                      throws java.io.IOException
Parse the unit info DOM element.

Throws:
java.io.IOException

parseProperty

protected void parseProperty(org.w3c.dom.Element persistenceUnit,
                             SpringPersistenceUnitInfo unitInfo)
Parse the property XML elements.


parseClass

protected void parseClass(org.w3c.dom.Element persistenceUnit,
                          SpringPersistenceUnitInfo unitInfo)
Parse the class XML elements.


parseJarFiles

protected void parseJarFiles(org.w3c.dom.Element persistenceUnit,
                             SpringPersistenceUnitInfo unitInfo)
                      throws java.io.IOException
Parse the jar-file XML elements.

Throws:
java.io.IOException

parseMappingFiles

protected void parseMappingFiles(org.w3c.dom.Element persistenceUnit,
                                 SpringPersistenceUnitInfo unitInfo)
Parse the mapping-file XML elements.