@Override
public void merge(WebFragmentType webFragment, WebAppType webApp, MergeContext mergeContext) throws DeploymentException {
for (PersistenceContextRefType srcPersistenceContextRef : webFragment.getPersistenceContextRefArray()) {
String persistenceContextRefName = srcPersistenceContextRef.getPersistenceContextRefName().getStringValue();
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
PersistenceContextRefType persistenceContextRef = (PersistenceContextRefType) mergeItem.getValue();
for (InjectionTargetType injectTarget : srcPersistenceContextRef.getInjectionTargetArray()) {
String persistenceContextRefInjectTargetKey = createPersistenceContextRefInjectTargetKey(persistenceContextRefName, injectTarget.getInjectionTargetClass().getStringValue(), injectTarget
.getInjectionTargetName().getStringValue());
if (!mergeContext.containsAttribute(persistenceContextRefInjectTargetKey)) {
persistenceContextRef.addNewInjectionTarget().set(injectTarget);
mergeContext.setAttribute(persistenceContextRefInjectTargetKey, Boolean.TRUE);
}
}
}
} else {
PersistenceContextRefType targetPersistenceContextRef = (PersistenceContextRefType) webApp.addNewPersistenceContextRef().set(srcPersistenceContextRef);
mergeContext.setAttribute(persistenceContextRefKey, new MergeItem(targetPersistenceContextRef, mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
for (InjectionTargetType injectionTarget : targetPersistenceContextRef.getInjectionTargetArray()) {
mergeContext.setAttribute(createPersistenceContextRefInjectTargetKey(persistenceContextRefName, injectionTarget.getInjectionTargetClass().getStringValue(), injectionTarget.getInjectionTargetName()
.getStringValue()), Boolean.TRUE);
}
}