@Override
public void merge(WebFragmentType webFragment, WebAppType webApp, MergeContext mergeContext) throws DeploymentException {
for (ResourceEnvRefType srcResourceEnvRef : webFragment.getResourceEnvRefArray()) {
String resourceEnvRefName = srcResourceEnvRef.getResourceEnvRefName().getStringValue();
String resourceEnvRefKey = createResourceEnvRefKey(resourceEnvRefName);
MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(resourceEnvRefKey);
if (mergeItem != null) {
if (mergeItem.isFromWebFragment()) {
throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateJNDIRefMessage("resource-env-ref", resourceEnvRefName, mergeItem.getBelongedURL(), mergeContext.getCurrentJarUrl()));
} else if (mergeItem.isFromWebXml() && !isResourceEnvRefInjectTargetsConfiguredInInitialWebXML(resourceEnvRefName, mergeContext)) {
//Merge InjectTarget
ResourceEnvRefType resourceEnvRef = (ResourceEnvRefType) mergeItem.getValue();
for (InjectionTargetType injectTarget : srcResourceEnvRef.getInjectionTargetArray()) {
String resourceEnvRefInjectTargetKey = createResourceEnvRefInjectTargetKey(resourceEnvRefName, injectTarget.getInjectionTargetClass().getStringValue(), injectTarget
.getInjectionTargetName().getStringValue());
if (!mergeContext.containsAttribute(resourceEnvRefInjectTargetKey)) {
resourceEnvRef.addNewInjectionTarget().set(injectTarget);
mergeContext.setAttribute(resourceEnvRefInjectTargetKey, Boolean.TRUE);
}
}
}
} else {
ResourceEnvRefType targetResourceEnvRef = (ResourceEnvRefType) webApp.addNewResourceEnvRef().set(srcResourceEnvRef);
mergeContext.setAttribute(resourceEnvRefKey, new MergeItem(targetResourceEnvRef, mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
for (InjectionTargetType injectionTarget : targetResourceEnvRef.getInjectionTargetArray()) {
mergeContext.setAttribute(createResourceEnvRefInjectTargetKey(resourceEnvRefName, injectionTarget.getInjectionTargetClass().getStringValue(), injectionTarget.getInjectionTargetName()
.getStringValue()), Boolean.TRUE);
}
}