if (mergeItem != null) {
if (mergeItem.isFromWebFragment()) {
throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateJNDIRefMessage("service-ref", serviceRefName, mergeItem.getBelongedURL(), mergeContext.getCurrentJarUrl()));
} else if (mergeItem.isFromWebXml() && !isServiceRefInjectTargetsConfiguredInInitialWebXML(serviceRefName, mergeContext)) {
//Merge InjectTarget
ServiceRefType serviceRef = (ServiceRefType) mergeItem.getValue();
for (InjectionTargetType injectTarget : srcServiceRef.getInjectionTargetArray()) {
String serviceRefInjectTargetKey = createServiceRefInjectTargetKey(serviceRefName, injectTarget.getInjectionTargetClass().getStringValue(), injectTarget
.getInjectionTargetName().getStringValue());
if (!mergeContext.containsAttribute(serviceRefInjectTargetKey)) {
serviceRef.addNewInjectionTarget().set(injectTarget);
mergeContext.setAttribute(serviceRefInjectTargetKey, Boolean.TRUE);
}
}
}
} else {
ServiceRefType targetServiceRef = (ServiceRefType) webApp.addNewServiceRef().set(srcServiceRef);
mergeContext.setAttribute(serviceRefKey, new MergeItem(targetServiceRef, mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
for (InjectionTargetType injectionTarget : targetServiceRef.getInjectionTargetArray()) {
mergeContext.setAttribute(createServiceRefInjectTargetKey(serviceRefName, injectionTarget.getInjectionTargetClass().getStringValue(), injectionTarget.getInjectionTargetName()
.getStringValue()), Boolean.TRUE);
}
}
}