@Override
public void merge(Servlet srcServlet, Servlet targetServlet, MergeContext mergeContext) throws DeploymentException {
String servletName = srcServlet.getServletName();
for (ParamValue paramValue : srcServlet.getInitParam()) {
MergeItem existedMergeItem = (MergeItem) mergeContext.getAttribute(createServletInitParamKey(servletName, paramValue.getParamName()));
if (existedMergeItem == null) {
targetServlet.getInitParam().add(paramValue);
addServletInitParam(servletName, paramValue, ElementSource.WEB_FRAGMENT, mergeContext.getCurrentJarUrl(), mergeContext);
} else {
ParamValue existedParamValue = (ParamValue) existedMergeItem.getValue();
switch (existedMergeItem.getSourceType()) {
case WEB_XML:
continue;
case WEB_FRAGMENT:
if (existedParamValue.getParamValue().equals(paramValue.getParamValue())
|| existedMergeItem.getBelongedURL().equals(mergeContext.getCurrentJarUrl())) {
break;
} else {
throw new DeploymentException(WebDeploymentMessageUtils.createDuplicateKeyValueMessage("servlet " + servletName, "param-name", paramValue.getParamName(),
"param-value", existedParamValue.getParamValue(), existedMergeItem.getBelongedURL(), paramValue.getParamValue(), mergeContext
.getCurrentJarUrl()));
}
case ANNOTATION:
//Spec 8.1.n.iii Init params for servlets and filters defined via annotations, will be
//overridden in the descriptor if the name of the init param exactly matches
//the name specified via the annotation. Init params are additive between the
//annotations and descriptors.
//In my understanding, the value of init-param should be overridden even if it is merged from annotation before the current web-fragment.xml file
existedParamValue.setParamValue(paramValue.getParamValue());
existedMergeItem.setBelongedURL(mergeContext.getCurrentJarUrl());
existedMergeItem.setSourceType(ElementSource.WEB_FRAGMENT);
}
}
}
}