* the exception
*/
private static PersistenceUnitMetadata parsePersistenceUnit(final URL url, final String[] persistenceUnits,
Element top, final String versionName)
{
PersistenceUnitMetadata metadata = new PersistenceUnitMetadata(versionName, getPersistenceRootUrl(url), url);
String puName = top.getAttribute("name");
if (!Arrays.asList(persistenceUnits).contains(puName))
{
// Returning null because this persistence unit is not intended for
// creating entity manager factory.
return null;
}
if (!isEmpty(puName))
{
log.trace("Persistent Unit name from persistence.xml: " + puName);
metadata.setPersistenceUnitName(puName);
String transactionType = top.getAttribute("transaction-type");
if (StringUtils.isEmpty(transactionType)
|| PersistenceUnitTransactionType.RESOURCE_LOCAL.name().equals(transactionType))
{
metadata.setTransactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL);
}
else if (PersistenceUnitTransactionType.JTA.name().equals(transactionType))
{
metadata.setTransactionType(PersistenceUnitTransactionType.JTA);
}
}
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("provider"))
{
metadata.setProvider(getElementContent(element));
}
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 element is not "property" then skip
if (!"property".equals(propElement.getTagName()))
{
continue;
}
String propName = propElement.getAttribute("name").trim();
String propValue = propElement.getAttribute("value").trim();
if (isEmpty(propValue))
{
propValue = getElementContent(propElement, "");
}
metadata.getProperties().put(propName, propValue);
}
}
}
else if (tag.equals("class"))
{
metadata.getClasses().add(getElementContent(element));
}
else if (tag.equals("jar-file"))
{
metadata.addJarFile(getElementContent(element));
}
else if (tag.equals("exclude-unlisted-classes"))
{
String excludeUnlisted = getElementContent(element);
metadata.setExcludeUnlistedClasses(Boolean.parseBoolean(excludeUnlisted));
}
}
}
PersistenceUnitTransactionType transactionType = getTransactionType(top.getAttribute("transaction-type"));
if (transactionType != null)
{
metadata.setTransactionType(transactionType);
}
return metadata;
}