public class PersistenceXMLLoader extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
PersistenceXMLLoader.AllowedProtocol
Allowed protocols
|
static class |
PersistenceXMLLoader.ErrorLogger
The Class ErrorLogger.
|
| Modifier and Type | Field and Description |
|---|---|
private static org.slf4j.Logger |
log
The log.
|
| Modifier | Constructor and Description |
|---|---|
private |
PersistenceXMLLoader()
Instantiates a new persistence xml loader.
|
| Modifier and Type | Method and Description |
|---|---|
static List<PersistenceUnitMetadata> |
findPersistenceUnits(URL url,
String[] persistenceUnits)
Find persistence units.
|
static List<PersistenceUnitMetadata> |
findPersistenceUnits(URL url,
String[] persistenceUnits,
javax.persistence.spi.PersistenceUnitTransactionType defaultTransactionType)
Find persistence units.
|
private static Document |
getDocument(URL pathToPersistenceXml)
Reads the persistence xml content into an object graph and validates it
against the related xsd schema.
|
static String |
getElementContent(Element element)
Gets the element content.
|
private static String |
getElementContent(Element element,
String defaultStr)
Get the content of the given element.
|
private static URL |
getPersistenceRootUrl(URL url)
Returns persistence unit root url
|
private static InputStream |
getStreamFromClasspath(String fileName)
Get stream from classpath.
|
static javax.persistence.spi.PersistenceUnitTransactionType |
getTransactionType(String elementContent)
Gets the transaction type.
|
private static boolean |
isEmpty(String str)
Checks if is empty.
|
private static Document |
parseDocument(InputStream is)
Reads the content of the persistence.xml file into an object model, with
the root node of type
Document. |
private static String |
parseFilePath(String file)
Parse and exclude path till META-INF
|
private static PersistenceUnitMetadata |
parsePersistenceUnit(URL url,
String[] persistenceUnits,
Element top,
String versionName)
Parses the persistence unit.
|
private static void |
validateDocumentAgainstSchema(Document xmlRootNode)
Validates an xml object graph against its schema.
|
private PersistenceXMLLoader()
private static Document getDocument(URL pathToPersistenceXml) throws InvalidConfigurationException
pathToPersistenceXml - path to the persistence.xml fileInvalidConfigurationException - if the file could not be parsed or is not valid against the
schemaprivate static Document parseDocument(InputStream is) throws InvalidConfigurationException
Document.is - InputStream of the persistence.xml contentInvalidConfigurationException - if the content could not be read due to an I/O error or could
not be parsedÏprivate static void validateDocumentAgainstSchema(Document xmlRootNode) throws InvalidConfigurationException
xmlRootNode - root xml node of the document to validateInvalidConfigurationException - if the validation could not be performed or the xml graph is
invalid against the schemaprivate static InputStream getStreamFromClasspath(String fileName)
fileName - the file nameException - the exceptionpublic static List<PersistenceUnitMetadata> findPersistenceUnits(URL url, String[] persistenceUnits) throws Exception
url - the urlException - the exceptionpublic static List<PersistenceUnitMetadata> findPersistenceUnits(URL url, String[] persistenceUnits, javax.persistence.spi.PersistenceUnitTransactionType defaultTransactionType) throws InvalidConfigurationException
url - the urldefaultTransactionType - the default transaction typeException - the exceptionInvalidConfigurationExceptionprivate static PersistenceUnitMetadata parsePersistenceUnit(URL url, String[] persistenceUnits, Element top, String versionName)
top - the topException - the exceptionpublic static javax.persistence.spi.PersistenceUnitTransactionType getTransactionType(String elementContent)
elementContent - the element contentprivate static boolean isEmpty(String str)
str - the strpublic static String getElementContent(Element element)
element - the elementException - the exceptionprivate static String getElementContent(Element element, String defaultStr)
element - The element to get the content for.defaultStr - The default to return when there is no content.Exception - the exceptionprivate static URL getPersistenceRootUrl(URL url)
url - raw urlCopyright © 2015. All Rights Reserved.