"The Class {0} having annotation {1} need to be a derived class of {2}.",
new Object[] { webCompClass.getName(), WebServlet.class.getName(), HttpServlet.class.getName() }));
return getDefaultFailedResult();
}
WebServlet webServletAn = (WebServlet)ainfo.getAnnotation();
String servletName = getServletName(webServletAn, webCompClass);
if (!servletName.equals(webCompDesc.getCanonicalName())) {
// skip the processing as it is not for given webCompDesc
return getDefaultProcessedResult();
}
String webCompImpl = webCompDesc.getWebComponentImplementation();
if (webCompImpl != null && webCompImpl.length() > 0 &&
(!webCompImpl.equals(webCompClass.getName()) || !webCompDesc.isServlet())) {
String messageKey = null;
String defaultMessage = null;
if (webCompDesc.isServlet()) {
messageKey = "web.deployment.annotation.handlers.servletimpldontmatch";
defaultMessage = "The servlet '{0}' has implementation '{1}' in xml. It does not match with '{2}' from annotation @{3}.";
} else {
messageKey = "web.deployment.annotation.handlers.servletimpljspdontmatch";
defaultMessage = "The servlet '{0}' is a jsp '{1}' in xml. It does not match with '{2}' from annotation @{3}.";
}
log(Level.SEVERE, ainfo,
localStrings.getLocalString(messageKey, defaultMessage,
new Object[] { webCompDesc.getCanonicalName(), webCompImpl, webCompClass.getName(),
WebServlet.class.getName() }));
return getDefaultFailedResult();
}
webCompDesc.setServlet(true);
webCompDesc.setWebComponentImplementation(webCompClass.getName());
if (webCompDesc.getUrlPatternsSet().size() == 0) {
String[] urlPatterns = webServletAn.urlPatterns();
if (urlPatterns == null || urlPatterns.length == 0) {
urlPatterns = webServletAn.value();
}
// no url patterns is accepted as it may be defined in top level xml
boolean validUrlPatterns = true;
if (urlPatterns != null && urlPatterns.length > 0) {
for (String up : urlPatterns) {
if (!URLPattern.isValid(up)) {
validUrlPatterns = false;
break;
}
webCompDesc.addUrlPattern(up);
}
}
if (!validUrlPatterns) {
String urlPatternString =
(urlPatterns != null) ? Arrays.toString(urlPatterns) : "";
throw new IllegalArgumentException(localStrings.getLocalString(
"web.deployment.annotation.handlers.invalidUrlPatterns",
"Invalid url patterns for {0}: {1}.",
new Object[] { webCompClass, urlPatternString }));
}
}
if (webCompDesc.getLoadOnStartUp() == null) {
webCompDesc.setLoadOnStartUp(webServletAn.loadOnStartup());
}
WebInitParam[] initParams = webServletAn.initParams();
if (initParams != null && initParams.length > 0) {
for (WebInitParam initParam : initParams) {
webCompDesc.addInitializationParameter(
new EnvironmentProperty(
initParam.name(), initParam.value(),
initParam.description()));
}
}
if (webCompDesc.getSmallIconUri() == null) {
webCompDesc.setSmallIconUri(webServletAn.smallIcon());
}
if (webCompDesc.getLargeIconUri() == null) {
webCompDesc.setLargeIconUri(webServletAn.largeIcon());
}
if (webCompDesc.getDescription() == null ||
webCompDesc.getDescription().length() == 0) {
webCompDesc.setDescription(webServletAn.description());
}
if (webCompDesc.getDisplayName() == null ||
webCompDesc.getDisplayName().length() == 0) {
webCompDesc.setDisplayName(webServletAn.displayName());
}
if (webCompDesc.isAsyncSupported() == null) {
webCompDesc.setAsyncSupported(webServletAn.asyncSupported());
}
return getDefaultProcessedResult();
}