@Override
public void merge(WebFragment webFragment, WebApp webApp, MergeContext mergeContext) throws DeploymentException {
for (PersistenceUnitRef srcPersistenceUnitRef : webFragment.getPersistenceUnitRef()) {
String persistenceUnitRefName = srcPersistenceUnitRef.getPersistenceUnitRefName();
String persistenceUnitRefKey = createPersistenceUnitRefKey(persistenceUnitRefName);
MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(persistenceUnitRefKey);
if (mergeItem != null) {
if (mergeItem.isFromWebFragment()) {
throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateJNDIRefMessage("persistence-unit-ref", persistenceUnitRefName, mergeItem.getBelongedURL(), mergeContext.getCurrentJarUrl()));
} else if (mergeItem.isFromWebXml() && !isPersistenceUnitRefInjectTargetsConfiguredInInitialWebXML(persistenceUnitRefName, mergeContext)) {
//Merge InjectTarget
PersistenceUnitRef persistenceUnitRef = (PersistenceUnitRef) mergeItem.getValue();
for (InjectionTarget injectTarget : srcPersistenceUnitRef.getInjectionTarget()) {
String persistenceUnitRefInjectTargetKey = createPersistenceUnitRefInjectTargetKey(persistenceUnitRefName, injectTarget.getInjectionTargetClass(), injectTarget
.getInjectionTargetName());
if (!mergeContext.containsAttribute(persistenceUnitRefInjectTargetKey)) {
persistenceUnitRef.getInjectionTarget().add(injectTarget);
mergeContext.setAttribute(persistenceUnitRefInjectTargetKey, Boolean.TRUE);
}
}
}
} else {
webApp.getPersistenceUnitRef().add(srcPersistenceUnitRef);
mergeContext.setAttribute(persistenceUnitRefKey, new MergeItem(srcPersistenceUnitRef, mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
for (InjectionTarget injectionTarget : srcPersistenceUnitRef.getInjectionTarget()) {
mergeContext.setAttribute(createPersistenceUnitRefInjectTargetKey(persistenceUnitRefName, injectionTarget.getInjectionTargetClass(), injectionTarget.getInjectionTargetName()
), Boolean.TRUE);
}
}