@Override
public void merge(WebFragment webFragment, WebApp webApp, MergeContext mergeContext) throws DeploymentException {
for (EjbLocalRef srcEjbLocalRef : webFragment.getEjbLocalRef()) {
String ejbLocalRefName = srcEjbLocalRef.getEjbRefName();
String ejbLocalRefKey = createEjbLocalRefKey(ejbLocalRefName);
MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(ejbLocalRefKey);
if (mergeItem != null) {
if (mergeItem.isFromWebFragment()) {
throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateJNDIRefMessage("ejb-local-ref", ejbLocalRefName, mergeItem.getBelongedURL(), mergeContext.getCurrentJarUrl()));
} else if (mergeItem.isFromWebXml() && !isEjbLocalRefInjectTargetsConfiguredInInitialWebXML(ejbLocalRefName, mergeContext)) {
//Merge InjectTarget
EjbLocalRef ejbLocalRef = (EjbLocalRef) mergeItem.getValue();
for (InjectionTarget injectTarget : srcEjbLocalRef.getInjectionTarget()) {
String ejbLocalRefInjectTargetKey = createEjbLocalRefInjectTargetKey(ejbLocalRefName, injectTarget.getInjectionTargetClass(), injectTarget
.getInjectionTargetName());
if (!mergeContext.containsAttribute(ejbLocalRefInjectTargetKey)) {
ejbLocalRef.getInjectionTarget().add(injectTarget);
mergeContext.setAttribute(ejbLocalRefInjectTargetKey, Boolean.TRUE);
}
}
}
} else {
webApp.getEjbLocalRef().add(srcEjbLocalRef);
mergeContext.setAttribute(ejbLocalRefKey, new MergeItem(srcEjbLocalRef, mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
for (InjectionTarget injectionTarget : srcEjbLocalRef.getInjectionTarget()) {
mergeContext.setAttribute(createEjbLocalRefInjectTargetKey(ejbLocalRefName, injectionTarget.getInjectionTargetClass(), injectionTarget.getInjectionTargetName()
), Boolean.TRUE);
}
}