@Override
public void merge(WebFragment webFragment, WebApp webApp, MergeContext mergeContext) throws DeploymentException {
for (PersistenceContextRef srcPersistenceContextRef : webFragment.getPersistenceContextRef()) {
String persistenceContextRefName = srcPersistenceContextRef.getPersistenceContextRefName();
String persistenceContextRefKey = createPersistenceContextRefKey(persistenceContextRefName);
MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(persistenceContextRefKey);
if (mergeItem != null) {
if (mergeItem.isFromWebFragment()) {
throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateJNDIRefMessage("persistence-context-ref", persistenceContextRefName, mergeItem.getBelongedURL(), mergeContext.getCurrentJarUrl()));
} else if (mergeItem.isFromWebXml() && !isPersistenceContextRefInjectTargetsConfiguredInInitialWebXML(persistenceContextRefName, mergeContext)) {
//Merge InjectTarget
PersistenceContextRef persistenceContextRef = (PersistenceContextRef) mergeItem.getValue();
for (InjectionTarget injectTarget : srcPersistenceContextRef.getInjectionTarget()) {
String persistenceContextRefInjectTargetKey = createPersistenceContextRefInjectTargetKey(persistenceContextRefName, injectTarget.getInjectionTargetClass(), injectTarget
.getInjectionTargetName());
if (!mergeContext.containsAttribute(persistenceContextRefInjectTargetKey)) {
persistenceContextRef.getInjectionTarget().add(injectTarget);
mergeContext.setAttribute(persistenceContextRefInjectTargetKey, Boolean.TRUE);
}
}
}
} else {
webApp.getPersistenceContextRef().add(srcPersistenceContextRef);
mergeContext.setAttribute(persistenceContextRefKey, new MergeItem(srcPersistenceContextRef, mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
for (InjectionTarget injectionTarget : srcPersistenceContextRef.getInjectionTarget()) {
mergeContext.setAttribute(createPersistenceContextRefInjectTargetKey(persistenceContextRefName, injectionTarget.getInjectionTargetClass(), injectionTarget.getInjectionTargetName()
), Boolean.TRUE);
}
}