@Override
public void merge(WebFragmentType webFragment, WebAppType webApp, MergeContext mergeContext) throws DeploymentException {
for (MessageDestinationRefType srcMessageDestinationRef : webFragment.getMessageDestinationRefArray()) {
String messageDestinationRefName = srcMessageDestinationRef.getMessageDestinationRefName().getStringValue();
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
MessageDestinationRefType messageDestinationRef = (MessageDestinationRefType) mergeItem.getValue();
for (InjectionTargetType injectTarget : srcMessageDestinationRef.getInjectionTargetArray()) {
String messageDestinationRefInjectTargetKey = createMessageDestinationRefInjectTargetKey(messageDestinationRefName, injectTarget.getInjectionTargetClass().getStringValue(), injectTarget
.getInjectionTargetName().getStringValue());
if (!mergeContext.containsAttribute(messageDestinationRefInjectTargetKey)) {
messageDestinationRef.addNewInjectionTarget().set(injectTarget);
mergeContext.setAttribute(messageDestinationRefInjectTargetKey, Boolean.TRUE);
}
}
}
} else {
MessageDestinationRefType targetMessageDestinationRef = (MessageDestinationRefType) webApp.addNewMessageDestinationRef().set(srcMessageDestinationRef);
mergeContext.setAttribute(messageDestinationRefKey, new MergeItem(targetMessageDestinationRef, mergeContext.getCurrentJarUrl(), ElementSource.WEB_FRAGMENT));
for (InjectionTargetType injectionTarget : targetMessageDestinationRef.getInjectionTargetArray()) {
mergeContext.setAttribute(createMessageDestinationRefInjectTargetKey(messageDestinationRefName, injectionTarget.getInjectionTargetClass().getStringValue(), injectionTarget.getInjectionTargetName()
.getStringValue()), Boolean.TRUE);
}
}