@Override
public void merge(WebFragment webFragment, WebApp webApp, MergeContext mergeContext) throws DeploymentException {
for (MessageDestinationRef srcMessageDestinationRef : webFragment.getMessageDestinationRef()) {
String messageDestinationRefName = srcMessageDestinationRef.getMessageDestinationRefName();
String messageDestinationRefKey = createMessageDestinationRefKey(messageDestinationRefName);
MergeItem mergeItem = (MergeItem) mergeContext.getAttribute(messageDestinationRefKey);
if (mergeItem != null) {
if (mergeItem.isFromWebFragment()) {
throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateJNDIRefMessage("message-destination-ref", messageDestinationRefName, mergeItem.getBelongedURL(), mergeContext.getCurrentJarUrl()));
} else if (mergeItem.isFromWebXml() && !isMessageDestinationRefInjectTargetsConfiguredInInitialWebXML(messageDestinationRefName, mergeContext)) {
//Merge InjectTarget
MessageDestinationRef messageDestinationRef = (MessageDestinationRef) mergeItem.getValue();
for (InjectionTarget injectTarget : srcMessageDestinationRef.getInjectionTarget()) {
String messageDestinationRefInjectTargetKey = createMessageDestinationRefInjectTargetKey(messageDestinationRefName, injectTarget.getInjectionTargetClass(), injectTarget
.getInjectionTargetName());
if (!mergeContext.containsAttribute(messageDestinationRefInjectTargetKey)) {
messageDestinationRef.getInjectionTarget().add(injectTarget);
mergeContext.setAttribute(messageDestinationRefInjectTargetKey, Boolean.TRUE);
}
}
}
} else {
webApp.getMessageDestinationRef().add(srcMessageDestinationRef);
mergeContext.setAttribute(messageDestinationRefKey, new MergeItem(srcMessageDestinationRef, mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
for (InjectionTarget injectionTarget : srcMessageDestinationRef.getInjectionTarget()) {
mergeContext.setAttribute(createMessageDestinationRefInjectTargetKey(messageDestinationRefName, injectionTarget.getInjectionTargetClass(), injectionTarget.getInjectionTargetName()
), Boolean.TRUE);
}
}