return units;
}
private static PersistenceMetadata parsePersistenceUnit(Element top, PersistenceUnitTransactionType defaultTransactionType)
throws Exception {
PersistenceMetadata metadata = new PersistenceMetadata();
String puName = top.getAttribute( "name" );
if ( StringHelper.isNotEmpty( puName ) ) {
log.trace( "Persistent Unit name from persistence.xml: " + puName );
metadata.setName( puName );
}
PersistenceUnitTransactionType transactionType = getTransactionType( top.getAttribute( "transaction-type" ) );
//parsing a persistence.xml means we are in a JavaSE environment
transactionType = transactionType != null ? transactionType : defaultTransactionType;
metadata.setTransactionType( transactionType );
NodeList children = top.getChildNodes();
for ( int i = 0; i < children.getLength() ; i++ ) {
if ( children.item( i ).getNodeType() == Node.ELEMENT_NODE ) {
Element element = (Element) children.item( i );
String tag = element.getTagName();
// if ( tag.equals( "name" ) ) {
// String puName = XmlHelper.getElementContent( element );
// log.trace( "FOUND PU NAME: " + puName );
// metadata.setName( puName );
// }
// else
if ( tag.equals( "non-jta-data-source" ) ) {
metadata.setNonJtaDatasource( XmlHelper.getElementContent( element ) );
}
else if ( tag.equals( "jta-data-source" ) ) {
metadata.setJtaDatasource( XmlHelper.getElementContent( element ) );
}
else if ( tag.equals( "provider" ) ) {
metadata.setProvider( XmlHelper.getElementContent( element ) );
}
else if ( tag.equals( "class" ) ) {
metadata.getClasses().add( XmlHelper.getElementContent( element ) );
}
else if ( tag.equals( "mapping-file" ) ) {
metadata.getMappingFiles().add( XmlHelper.getElementContent( element ) );
}
else if ( tag.equals( "jar-file" ) ) {
metadata.getJarFiles().add( XmlHelper.getElementContent( element ) );
}
else if ( tag.equals( "exclude-unlisted-classes" ) ) {
metadata.setExcludeUnlistedClasses( true );
}
else if ( tag.equals( "properties" ) ) {
NodeList props = element.getChildNodes();
for ( int j = 0; j < props.getLength() ; j++ ) {
if ( props.item( j ).getNodeType() == Node.ELEMENT_NODE ) {
Element propElement = (Element) props.item( j );
if ( !"property".equals( propElement.getTagName() ) ) continue;
String propName = propElement.getAttribute( "name" ).trim();
String propValue = propElement.getAttribute( "value" ).trim();
if ( StringHelper.isEmpty( propValue ) ) {
//fall back to the natural (Hibernate) way of description
propValue = XmlHelper.getElementContent( propElement, "" );
}
metadata.getProps().put( propName, propValue );
}
}
}
}