The Spring Framework

org.springframework.orm.jpa.persistenceunit
Class PersistenceUnitReader

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

 class PersistenceUnitReader
extends Object

Internal helper class for reading persistence.xml files.

Since:
2.0
Author:
Costin Leau, Juergen Hoeller

Constructor Summary
PersistenceUnitReader(ResourcePatternResolver resourcePatternResolver, DataSourceLookup dataSourceLookup)
          Create a new PersistenceUnitReader.
 
Method Summary
protected  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  Resource findSchemaResource(String schemaName)
          Try to locate the schema first in the class path before using the URL specified inside the XML.
protected  void parseClass(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)
          Parse the class XML elements.
protected  List<SpringPersistenceUnitInfo> parseDocument(Resource resource, Document document, List<SpringPersistenceUnitInfo> infos)
          Parse the validated document and populates(add to) the given unit info list.
protected  void parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)
          Parse the jar-file XML elements.
protected  void parseMappingFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)
          Parse the mapping-file XML elements.
protected  SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit)
          Parse the unit info DOM element.
protected  void parseProperty(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo)
          Parse the property XML elements.
 SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String persistenceXmlLocation)
          Parse and build all persistence unit infos defined in the specified XML file(s).
 SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String[] persistenceXmlLocations)
          Parse and build all persistence unit infos defined in the given XML files.
protected  Document validateResource(ErrorHandler handler, InputStream stream)
          Validate the given stream and return a valid DOM document for parsing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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(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(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

validateResource

protected Document validateResource(ErrorHandler handler,
                                    InputStream stream)
                             throws ParserConfigurationException,
                                    SAXException,
                                    IOException
Validate the given stream and return a valid DOM document for parsing.

Throws:
ParserConfigurationException
SAXException
IOException

findSchemaResource

protected Resource findSchemaResource(String schemaName)
Try to locate the schema first in the class path before using the URL specified inside the XML.

Returns:
an existing resource, or null if none found

parseDocument

protected List<SpringPersistenceUnitInfo> parseDocument(Resource resource,
                                                        Document document,
                                                        List<SpringPersistenceUnitInfo> infos)
                                                 throws IOException
Parse the validated document and populates(add to) the given unit info list.

Throws:
IOException

determinePersistenceUnitRootUrl

protected URL determinePersistenceUnitRootUrl(Resource resource)
                                       throws 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:
IOException - if the checking failed

parsePersistenceUnitInfo

protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit)
                                                      throws IOException
Parse the unit info DOM element.

Throws:
IOException

parseProperty

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


parseClass

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


parseJarFiles

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

Throws:
IOException

parseMappingFiles

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


The Spring Framework

Copyright © 2002-2006 The Spring Framework.