Top Description Inners Fields Constructors Methods
org.hibernate.jpa.boot.internal

public Class PersistenceXmlParser

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.net.URL, .URLConnection, java.util.ArrayList, .Collections, .List, .Map, .Properties, java.util.concurrent.ConcurrentHashMap, jakarta.persistence.PersistenceException, jakarta.persistence.spi.PersistenceUnitTransactionType, javax.xml.parsers.DocumentBuilder, .DocumentBuilderFactory, .ParserConfigurationException, javax.xml.transform.dom.DOMSource, javax.xml.validation.Validator, org.hibernate.boot.archive.internal.ArchiveHelper, org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl, org.hibernate.boot.registry.classloading.spi.ClassLoaderService, org.hibernate.boot.xsd.ConfigXsdSupport, org.hibernate.cfg.AvailableSettings, org.hibernate.internal.EntityManagerMessageLogger, org.hibernate.internal.log.DeprecationLogger, org.hibernate.internal.util.StringHelper, org.hibernate.jpa.internal.util.ConfigurationHelper, org.w3c.dom.Document, .Element, .Node, .NodeList, org.xml.sax.ErrorHandler, .InputSource, .SAXException, .SAXParseException

Used by Hibernate to parse persistence.xml files in SE environments.
Author
Steve Ebersole

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final ClassLoaderService
private final PersistenceUnitTransactionType
private DocumentBuilderFactory
private static final EntityManagerMessageLogger
private final Map<String, ParsedPersistenceXmlDescriptor>

Constructor Summary

AccessConstructor and Description
protected
PersistenceXmlParser(ClassLoaderService classLoaderService, PersistenceUnitTransactionType defaultTransactionType)

Method Summary

Modifier and TypeMethod and Description
private void
bindPersistenceUnit(ParsedPersistenceXmlDescriptor persistenceUnit, Element persistenceUnitElement)

private DocumentBuilderFactory
private void
private DocumentBuilderFactory
private void
doResolve(Map<K, V> integration)

private static boolean
extractBooleanContent(Element element, boolean defaultBool)

private static String
private static String
extractContent(Element element, String defaultStr)

private static String
protected List<ParsedPersistenceXmlDescriptor>
private Document
loadUrl(URL xmlUrl)

public static ParsedPersistenceXmlDescriptor

Returns:

The single persistence-unit descriptor
locateIndividualPersistenceUnit
(URL
The persistence.xml URL
persistenceXmlUrl
)

Parse a specific persistence.xml with the assumption that it defines a single persistence-unit.

public static ParsedPersistenceXmlDescriptor

Returns:

The single persistence-unit descriptor
locateIndividualPersistenceUnit
(URL
The persistence.xml URL
persistenceXmlUrl
,
Map<K, V>
The Map of integration settings
integration
)

Parse a specific persistence.xml with the assumption that it defines a single persistence-unit.

public static ParsedPersistenceXmlDescriptor

Returns:

The single persistence-unit descriptor
locateIndividualPersistenceUnit
(URL
The persistence.xml URL
persistenceXmlUrl
,
PersistenceUnitTransactionType
The specific PersistenceUnitTransactionType to incorporate into the persistence-unit descriptor
transactionType
,
Map<K, V>
The Map of integration settings
integration
)

Parse a specific persistence.xml with the assumption that it defines a single persistence-unit.

public static ParsedPersistenceXmlDescriptor

Returns:

The matching persistence-unit descriptor
locateNamedPersistenceUnit
(URL
The persistence.xml URL
persistenceXmlUrl
,
String
The PU name to match
name
)

Parse a specific persistence.xml and return the descriptor for the persistence-unit with matching name

public static ParsedPersistenceXmlDescriptor

Returns:

The matching persistence-unit descriptor
locateNamedPersistenceUnit
(URL
The persistence.xml URL
persistenceXmlUrl
,
String
The PU name to match
name
,
Map<K, V>
The Map of integration settings
integration
)

Parse a specific persistence.xml and return the descriptor for the persistence-unit with matching name

public static ParsedPersistenceXmlDescriptor

Returns:

The matching persistence-unit descriptor
locateNamedPersistenceUnit
(URL
The persistence.xml URL
persistenceXmlUrl
,
String
The PU name to match
name
,
PersistenceUnitTransactionType
The specific PersistenceUnitTransactionType to incorporate into the persistence-unit descriptor
transactionType
,
Map<K, V>
The Map of integration settings
integration
)

Parse a specific persistence.xml and return the descriptor for the persistence-unit with matching name

public static List<ParsedPersistenceXmlDescriptor>

Returns:

List of descriptors for all discovered persistence-units.
locatePersistenceUnits
(Map<K, V>
The Map of integration settings
integration
)

Find all persistence-units from all accessible META-INF/persistence.xml resources

public static Map<String, ParsedPersistenceXmlDescriptor>
parse(URL persistenceXmlUrl, PersistenceUnitTransactionType transactionType)

Intended only for use by Hibernate tests!

public static Map<String, ParsedPersistenceXmlDescriptor>

Returns:

Map of persistence-unit descriptors keyed by the PU name
parse
(URL
The URL of the persistence.xml to parse
persistenceXmlUrl
,
PersistenceUnitTransactionType
The specific PersistenceUnitTransactionType to incorporate into the persistence-unit descriptor
transactionType
,
Map<K, V>
The Map of integration settings
integration
)

Generic method to parse a specified persistence.xml and return a Map of descriptors for all discovered persistence-units keyed by the PU name.

private void
parsePersistenceXml(List<URL> xmlUrls, Map<K, V> integration)

protected void
parsePersistenceXml(URL xmlUrl, Map<K, V> integration)

private static PersistenceUnitTransactionType
private void
validate(Document document)

Validate the document using the

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classLoaderServiceback to summary
private final ClassLoaderService classLoaderService
defaultTransactionTypeback to summary
private final PersistenceUnitTransactionType defaultTransactionType
documentBuilderFactoryback to summary
private DocumentBuilderFactory documentBuilderFactory
LOGback to summary
private static final EntityManagerMessageLogger LOG
persistenceUnitsback to summary
private final Map<String, ParsedPersistenceXmlDescriptor> persistenceUnits

Constructor Detail

PersistenceXmlParserback to summary
protected PersistenceXmlParser(ClassLoaderService classLoaderService, PersistenceUnitTransactionType defaultTransactionType)

Method Detail

bindPersistenceUnitback to summary
private void bindPersistenceUnit(ParsedPersistenceXmlDescriptor persistenceUnit, Element persistenceUnitElement)
buildDocumentBuilderFactoryback to summary
private DocumentBuilderFactory buildDocumentBuilderFactory()
decodeTransactionTypeback to summary
private void decodeTransactionType(ParsedPersistenceXmlDescriptor persistenceUnit)
documentBuilderFactoryback to summary
private DocumentBuilderFactory documentBuilderFactory()
doResolveback to summary
private void doResolve(Map<K, V> integration)
extractBooleanContentback to summary
private static boolean extractBooleanContent(Element element, boolean defaultBool)
extractContentback to summary
private static String extractContent(Element element)
extractContentback to summary
private static String extractContent(Element element, String defaultStr)
extractInfoback to summary
private static String extractInfo(SAXException error)
getResolvedPersistenceUnitsback to summary
protected List<ParsedPersistenceXmlDescriptor> getResolvedPersistenceUnits()
loadUrlback to summary
private Document loadUrl(URL xmlUrl)
locateIndividualPersistenceUnitback to summary
public static ParsedPersistenceXmlDescriptor locateIndividualPersistenceUnit(URL persistenceXmlUrl)

Parse a specific persistence.xml with the assumption that it defines a single persistence-unit.

Parameters
persistenceXmlUrl:URL

The persistence.xml URL

Returns:ParsedPersistenceXmlDescriptor

The single persistence-unit descriptor

locateIndividualPersistenceUnitback to summary
public static ParsedPersistenceXmlDescriptor locateIndividualPersistenceUnit(URL persistenceXmlUrl, Map<K, V> integration)

Parse a specific persistence.xml with the assumption that it defines a single persistence-unit.

Parameters
persistenceXmlUrl:URL

The persistence.xml URL

integration:Map<K, V>

The Map of integration settings

Returns:ParsedPersistenceXmlDescriptor

The single persistence-unit descriptor

locateIndividualPersistenceUnitback to summary
public static ParsedPersistenceXmlDescriptor locateIndividualPersistenceUnit(URL persistenceXmlUrl, PersistenceUnitTransactionType transactionType, Map<K, V> integration)

Parse a specific persistence.xml with the assumption that it defines a single persistence-unit.

Parameters
persistenceXmlUrl:URL

The persistence.xml URL

transactionType:PersistenceUnitTransactionType

The specific PersistenceUnitTransactionType to incorporate into the persistence-unit descriptor

integration:Map<K, V>

The Map of integration settings

Returns:ParsedPersistenceXmlDescriptor

The single persistence-unit descriptor

locateNamedPersistenceUnitback to summary
public static ParsedPersistenceXmlDescriptor locateNamedPersistenceUnit(URL persistenceXmlUrl, String name)

Parse a specific persistence.xml and return the descriptor for the persistence-unit with matching name

Parameters
persistenceXmlUrl:URL

The persistence.xml URL

name:String

The PU name to match

Returns:ParsedPersistenceXmlDescriptor

The matching persistence-unit descriptor

locateNamedPersistenceUnitback to summary
public static ParsedPersistenceXmlDescriptor locateNamedPersistenceUnit(URL persistenceXmlUrl, String name, Map<K, V> integration)

Parse a specific persistence.xml and return the descriptor for the persistence-unit with matching name

Parameters
persistenceXmlUrl:URL

The persistence.xml URL

name:String

The PU name to match

integration:Map<K, V>

The Map of integration settings

Returns:ParsedPersistenceXmlDescriptor

The matching persistence-unit descriptor

locateNamedPersistenceUnitback to summary
public static ParsedPersistenceXmlDescriptor locateNamedPersistenceUnit(URL persistenceXmlUrl, String name, PersistenceUnitTransactionType transactionType, Map<K, V> integration)

Parse a specific persistence.xml and return the descriptor for the persistence-unit with matching name

Parameters
persistenceXmlUrl:URL

The persistence.xml URL

name:String

The PU name to match

transactionType:PersistenceUnitTransactionType

The specific PersistenceUnitTransactionType to incorporate into the persistence-unit descriptor

integration:Map<K, V>

The Map of integration settings

Returns:ParsedPersistenceXmlDescriptor

The matching persistence-unit descriptor

locatePersistenceUnitsback to summary
public static List<ParsedPersistenceXmlDescriptor> locatePersistenceUnits(Map<K, V> integration)

Find all persistence-units from all accessible META-INF/persistence.xml resources

Parameters
integration:Map<K, V>

The Map of integration settings

Returns:List<ParsedPersistenceXmlDescriptor>

List of descriptors for all discovered persistence-units.

parseback to summary
public static Map<String, ParsedPersistenceXmlDescriptor> parse(URL persistenceXmlUrl, PersistenceUnitTransactionType transactionType)

Intended only for use by Hibernate tests!

Parses a specific persistence.xml file...

parseback to summary
public static Map<String, ParsedPersistenceXmlDescriptor> parse(URL persistenceXmlUrl, PersistenceUnitTransactionType transactionType, Map<K, V> integration)

Generic method to parse a specified persistence.xml and return a Map of descriptors for all discovered persistence-units keyed by the PU name.

Parameters
persistenceXmlUrl:URL

The URL of the persistence.xml to parse

transactionType:PersistenceUnitTransactionType

The specific PersistenceUnitTransactionType to incorporate into the persistence-unit descriptor

integration:Map<K, V>

The Map of integration settings

Returns:Map<String, ParsedPersistenceXmlDescriptor>

Map of persistence-unit descriptors keyed by the PU name

parsePersistenceXmlback to summary
private void parsePersistenceXml(List<URL> xmlUrls, Map<K, V> integration)
parsePersistenceXmlback to summary
protected void parsePersistenceXml(URL xmlUrl, Map<K, V> integration)
parseTransactionTypeback to summary
private static PersistenceUnitTransactionType parseTransactionType(String value)
validateback to summary
private void validate(Document document)

Validate the document using the

org.hibernate.jpa.boot.internal back to summary

public Class PersistenceXmlParser.ErrorHandlerImpl

extends Object
implements ErrorHandler
Class Inheritance
  • java.lang.Object
  • org.hibernate.jpa.boot.internal.PersistenceXmlParser.ErrorHandlerImpl
All Implemented Interfaces
org.xml.sax.ErrorHandler

Field Summary

Modifier and TypeField and Description
private List<SAXException>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
error(SAXParseException
The error information encapsulated in a SAX parse exception.
error
)

Implements org.xml.sax.ErrorHandler.error.

Receive notification of a recoverable error.
public void
fatalError(SAXParseException
The error information encapsulated in a SAXParseException.
error
)

Implements org.xml.sax.ErrorHandler.fatalError.

Receive notification of a non-recoverable, fatal error.
public void
warning(SAXParseException
The warning information encapsulated in a SAX parse exception.
warn
)

Implements org.xml.sax.ErrorHandler.warning.

Receive notification of a warning.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

errorsback to summary
private List<SAXException> errors

Constructor Detail

ErrorHandlerImplback to summary
pack-priv ErrorHandlerImpl(List<SAXException> errors)

Method Detail

errorback to summary
public void error(SAXParseException error)

Implements org.xml.sax.ErrorHandler.error.

Doc from org.xml.sax.ErrorHandler.error.

Receive notification of a recoverable error.

This corresponds to the definition of "error" in section 1.2 of the W3C XML 1.0 Recommendation. For example, a validating parser would use this callback to report the violation of a validity constraint. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end. If the application cannot do so, then the parser should report a fatal error even if the XML recommendation does not require it to do so.

Filters may use this method to report other, non-XML errors as well.

Parameters
error:SAXParseException

The error information encapsulated in a SAX parse exception.

fatalErrorback to summary
public void fatalError(SAXParseException error)

Implements org.xml.sax.ErrorHandler.fatalError.

Doc from org.xml.sax.ErrorHandler.fatalError.

Receive notification of a non-recoverable, fatal error.

As defined in section 1.2 of the W3C XML 1.0 Recommendation, fatal errors are those that would make it impossible for a parser to continue normal processing. These include violation of a well-formedness constraint, invalid encoding, and forbidden structural errors as described in the W3C XML 1.0 Recommendation.

Parameters
error:SAXParseException

The error information encapsulated in a SAXParseException.

warningback to summary
public void warning(SAXParseException warn)

Implements org.xml.sax.ErrorHandler.warning.

Doc from org.xml.sax.ErrorHandler.warning.

Receive notification of a warning.

SAX parsers will use this method to report conditions that are not errors or fatal errors as defined by the XML recommendation. The default behaviour is to take no action.

The SAX parser must continue to provide normal parsing events after invoking this method: it should still be possible for the application to process the document through to the end.

Filters may use this method to report other, non-XML warnings as well.

Parameters
warn:SAXParseException

The warning information encapsulated in a SAX parse exception.