Web30MetaData metaData = new Web30MetaData();
AnnotationFinder<AnnotatedElement> finder = new DefaultAnnotationFinder<AnnotatedElement>();
// @WebServlet
final List<AnnotationTarget> webServletAnnotationTargets = index.getAnnotationTargets(webServlet);
if (webServletAnnotationTargets != null && webServletAnnotationTargets.size() > 0) {
WebServletProcessor processor = new WebServletProcessor(finder);
for (final AnnotationTarget target : webServletAnnotationTargets) {
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException("@WebServlet is only allowed at class level " + target);
}
ClassInfo classInfo = ClassInfo.class.cast(target);
Class<?> type = null;
try {
type = classLoader.loadClass(classInfo.name().toString());
} catch (Exception e) {
throw new DeploymentUnitProcessingException("Could not process @WebServlet on " + target);
}
if (type != null) {
processor.process(metaData, type);
}
}
}
// @WebFilter
final List<AnnotationTarget> webFilterAnnotationTargets = index.getAnnotationTargets(webFilter);
if (webFilterAnnotationTargets != null && webFilterAnnotationTargets.size() > 0) {
WebFilterProcessor processor = new WebFilterProcessor(finder);
for (final AnnotationTarget target : webFilterAnnotationTargets) {
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException("@WebFilter is only allowed at class level " + target);
}
ClassInfo classInfo = ClassInfo.class.cast(target);
Class<?> type = null;
try {
type = classLoader.loadClass(classInfo.name().toString());
} catch (Exception e) {
throw new DeploymentUnitProcessingException("Could not process @WebFilter on " + target);
}
if (type != null) {
processor.process(metaData, type);
}
}
}
// @WebListener
final List<AnnotationTarget> webListenerAnnotationTargets = index.getAnnotationTargets(webListener);
if (webListenerAnnotationTargets != null && webListenerAnnotationTargets.size() > 0) {
WebListenerProcessor processor = new WebListenerProcessor(finder);
for (final AnnotationTarget target : webListenerAnnotationTargets) {
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException("@WebListener is only allowed at class level " + target);
}
ClassInfo classInfo = ClassInfo.class.cast(target);
Class<?> type = null;
try {
type = classLoader.loadClass(classInfo.name().toString());
} catch (Exception e) {
throw new DeploymentUnitProcessingException("Could not process @WebListener on " + target);
}
if (type != null) {
processor.process(metaData, type);
}
}
}
// @RunAs
final List<AnnotationTarget> runAsAnnotationTargets = index.getAnnotationTargets(runAs);
if (runAsAnnotationTargets != null && runAsAnnotationTargets.size() > 0) {
RunAsProcessor processor = new RunAsProcessor(finder);
AnnotationsMetaData annotations = metaData.getAnnotations();
if (annotations == null) {
annotations = new AnnotationsMetaData();
metaData.setAnnotations(annotations);
}
for (final AnnotationTarget target : runAsAnnotationTargets) {
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException("@RunAs is only allowed at class level " + target);
}
ClassInfo classInfo = ClassInfo.class.cast(target);
Class<?> type = null;
try {
type = classLoader.loadClass(classInfo.name().toString());
} catch (Exception e) {
throw new DeploymentUnitProcessingException("Could not process @RunAs on " + target);
}
if (type != null) {
processor.process(annotations, type);
}
}
}
// @DeclareRoles
final List<AnnotationTarget> declareRolesAnnotationTargets = index.getAnnotationTargets(declareRoles);
if (declareRolesAnnotationTargets != null && declareRolesAnnotationTargets.size() > 0) {
DeclareRolesProcessor processor = new DeclareRolesProcessor(finder);
SecurityRolesMetaData securityRoles = metaData.getSecurityRoles();
if (securityRoles == null) {
securityRoles = new SecurityRolesMetaData();
metaData.setSecurityRoles(securityRoles);
}
for (final AnnotationTarget target : declareRolesAnnotationTargets) {
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException("@DeclareRoles is only allowed at class level " + target);
}
ClassInfo classInfo = ClassInfo.class.cast(target);
Class<?> type = null;
try {
type = classLoader.loadClass(classInfo.name().toString());
} catch (Exception e) {
throw new DeploymentUnitProcessingException("Could not process @DeclareRoles on " + target);
}
if (type != null) {
processor.process(securityRoles, type);
}
}
}
// @MultipartConfig
final List<AnnotationTarget> multipartConfigAnnotationTargets = index.getAnnotationTargets(multipartConfig);
if (multipartConfigAnnotationTargets != null && multipartConfigAnnotationTargets.size() > 0) {
MultipartConfigProcessor processor = new MultipartConfigProcessor(finder);
AnnotationsMetaData annotations = metaData.getAnnotations();
if (annotations == null) {
annotations = new AnnotationsMetaData();
metaData.setAnnotations(annotations);
}
for (final AnnotationTarget target : multipartConfigAnnotationTargets) {
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException("@MultipartConfig is only allowed at class level " + target);
}
ClassInfo classInfo = ClassInfo.class.cast(target);
Class<?> type = null;
try {
type = classLoader.loadClass(classInfo.name().toString());
} catch (Exception e) {
throw new DeploymentUnitProcessingException("Could not process @MultipartConfig on " + target);
}
if (type != null) {
processor.process(annotations, type);
}
}
}
// @ServletSecurity
final List<AnnotationTarget> servletSecurityAnnotationTargets = index.getAnnotationTargets(servletSecurity);
if (servletSecurityAnnotationTargets != null && servletSecurityAnnotationTargets.size() > 0) {
ServletSecurityProcessor processor = new ServletSecurityProcessor(finder);
AnnotationsMetaData annotations = metaData.getAnnotations();
if (annotations == null) {
annotations = new AnnotationsMetaData();
metaData.setAnnotations(annotations);
}
for (final AnnotationTarget target : servletSecurityAnnotationTargets) {
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException("@ServletSecurity is only allowed at class level " + target);
}
ClassInfo classInfo = ClassInfo.class.cast(target);
Class<?> type = null;
try {
type = classLoader.loadClass(classInfo.name().toString());
} catch (Exception e) {
throw new DeploymentUnitProcessingException("Could not process @ServletSecurity on " + target);
}
if (type != null) {
processor.process(annotations, type);
}
}
}
return metaData;
}