Author: markt Date: Fri Feb 2 11:06:55 2018 New Revision: 1822946 URL: http://svn.apache.org/viewvc?rev=1822946&view=rev Log: Code clean-up. No functional change.
Modified: tomcat/trunk/java/org/apache/catalina/startup/WebAnnotationSet.java Modified: tomcat/trunk/java/org/apache/catalina/startup/WebAnnotationSet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/WebAnnotationSet.java?rev=1822946&r1=1822945&r2=1822946&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/startup/WebAnnotationSet.java (original) +++ tomcat/trunk/java/org/apache/catalina/startup/WebAnnotationSet.java Fri Feb 2 11:06:55 2018 @@ -37,10 +37,9 @@ import org.apache.tomcat.util.descriptor import org.apache.tomcat.util.res.StringManager; /** - * <p><strong>AnnotationSet</strong> for processing the annotations of the web application - * classes (<code>/WEB-INF/classes</code> and <code>/WEB-INF/lib</code>).</p> - * - * @author Fabien Carrion + * <strong>AnnotationSet</strong> for processing the annotations of the web + * application classes (<code>/WEB-INF/classes</code> and + * <code>/WEB-INF/lib</code>). */ public class WebAnnotationSet { @@ -49,70 +48,68 @@ public class WebAnnotationSet { /** * The string resources for this package. */ - protected static final StringManager sm = - StringManager.getManager(Constants.Package); + protected static final StringManager sm = StringManager.getManager(Constants.Package); - // --------------------------------------------------------- Public Methods + // ---------------------------------------------------------- Public Methods /** * Process the annotations on a context. + * * @param context The context which will have its annotations processed */ public static void loadApplicationAnnotations(Context context) { - loadApplicationListenerAnnotations(context); loadApplicationFilterAnnotations(context); loadApplicationServletAnnotations(context); - - } - // -------------------------------------------------------- protected Methods - + // ------------------------------------------------------- Protected Methods /** * Process the annotations for the listeners. + * * @param context The context which will have its annotations processed */ protected static void loadApplicationListenerAnnotations(Context context) { String[] applicationListeners = context.findApplicationListeners(); for (String className : applicationListeners) { - Class<?> classClass = Introspection.loadClass(context, className); - if (classClass == null) { + Class<?> clazz = Introspection.loadClass(context, className); + if (clazz == null) { continue; } - loadClassAnnotation(context, classClass); - loadFieldsAnnotation(context, classClass); - loadMethodsAnnotation(context, classClass); + loadClassAnnotation(context, clazz); + loadFieldsAnnotation(context, clazz); + loadMethodsAnnotation(context, clazz); } } /** * Process the annotations for the filters. + * * @param context The context which will have its annotations processed */ protected static void loadApplicationFilterAnnotations(Context context) { FilterDef[] filterDefs = context.findFilterDefs(); for (FilterDef filterDef : filterDefs) { - Class<?> classClass = Introspection.loadClass(context, - filterDef.getFilterClass()); - if (classClass == null) { + Class<?> clazz = Introspection.loadClass(context, filterDef.getFilterClass()); + if (clazz == null) { continue; } - loadClassAnnotation(context, classClass); - loadFieldsAnnotation(context, classClass); - loadMethodsAnnotation(context, classClass); + loadClassAnnotation(context, clazz); + loadFieldsAnnotation(context, clazz); + loadMethodsAnnotation(context, clazz); } } /** * Process the annotations for the servlets. + * * @param context The context which will have its annotations processed */ protected static void loadApplicationServletAnnotations(Context context) { @@ -126,48 +123,47 @@ public class WebAnnotationSet { continue; } - Class<?> classClass = Introspection.loadClass(context, - wrapper.getServletClass()); - if (classClass == null) { + Class<?> clazz = Introspection.loadClass(context, wrapper.getServletClass()); + if (clazz == null) { continue; } - loadClassAnnotation(context, classClass); - loadFieldsAnnotation(context, classClass); - loadMethodsAnnotation(context, classClass); + loadClassAnnotation(context, clazz); + loadFieldsAnnotation(context, clazz); + loadMethodsAnnotation(context, clazz); /* Process RunAs annotation which can be only on servlets. * Ref JSR 250, equivalent to the run-as element in * the deployment descriptor */ - RunAs annotation = classClass.getAnnotation(RunAs.class); + RunAs annotation = clazz.getAnnotation(RunAs.class); if (annotation != null) { wrapper.setRunAs(annotation.value()); } } } - } /** * Process the annotations on a context for a given className. + * * @param context The context which will have its annotations processed - * @param classClass The class to examine for Servlet annotations + * @param clazz The class to examine for Servlet annotations */ protected static void loadClassAnnotation(Context context, - Class<?> classClass) { + Class<?> clazz) { /* Process Resource annotation. * Ref JSR 250 */ - Resource resourceAnnotation = classClass.getAnnotation(Resource.class); + Resource resourceAnnotation = clazz.getAnnotation(Resource.class); if (resourceAnnotation != null) { addResource(context, resourceAnnotation); } /* Process Resources annotation. * Ref JSR 250 */ - Resources resourcesAnnotation = classClass.getAnnotation(Resources.class); + Resources resourcesAnnotation = clazz.getAnnotation(Resources.class); if (resourcesAnnotation != null && resourcesAnnotation.value() != null) { for (Resource resource : resourcesAnnotation.value()) { addResource(context, resource); @@ -177,7 +173,7 @@ public class WebAnnotationSet { * Ref JSR 224, equivalent to the ejb-ref or ejb-local-ref * element in the deployment descriptor. { - EJB annotation = classClass.getAnnotation(EJB.class); + EJB annotation = clazz.getAnnotation(EJB.class); if (annotation != null) { if ((annotation.mappedName().length() == 0) @@ -214,7 +210,7 @@ public class WebAnnotationSet { * the deployment descriptor. * The service-ref registration is not implemented { - WebServiceRef annotation = classClass + WebServiceRef annotation = clazz .getAnnotation(WebServiceRef.class); if (annotation != null) { ContextService service = new ContextService(); @@ -246,8 +242,7 @@ public class WebAnnotationSet { * Ref JSR 250, equivalent to the security-role element in * the deployment descriptor */ - DeclareRoles declareRolesAnnotation = classClass - .getAnnotation(DeclareRoles.class); + DeclareRoles declareRolesAnnotation = clazz.getAnnotation(DeclareRoles.class); if (declareRolesAnnotation != null && declareRolesAnnotation.value() != null) { for (String role : declareRolesAnnotation.value()) { context.addSecurityRole(role); @@ -256,15 +251,14 @@ public class WebAnnotationSet { } - protected static void loadFieldsAnnotation(Context context, - Class<?> classClass) { + protected static void loadFieldsAnnotation(Context context, Class<?> clazz) { // Initialize the annotations - Field[] fields = Introspection.getDeclaredFields(classClass); + Field[] fields = Introspection.getDeclaredFields(clazz); if (fields != null && fields.length > 0) { for (Field field : fields) { Resource annotation = field.getAnnotation(Resource.class); if (annotation != null) { - String defaultName = classClass.getName() + SEPARATOR + field.getName(); + String defaultName = clazz.getName() + SEPARATOR + field.getName(); Class<?> defaultType = field.getType(); addResource(context, annotation, defaultName, defaultType); } @@ -273,10 +267,9 @@ public class WebAnnotationSet { } - protected static void loadMethodsAnnotation(Context context, - Class<?> classClass) { + protected static void loadMethodsAnnotation(Context context, Class<?> clazz) { // Initialize the annotations - Method[] methods = Introspection.getDeclaredMethods(classClass); + Method[] methods = Introspection.getDeclaredMethods(clazz); if (methods != null && methods.length > 0) { for (Method method : methods) { Resource annotation = method.getAnnotation(Resource.class); @@ -286,17 +279,17 @@ public class WebAnnotationSet { "webAnnotationSet.invalidInjection")); } - String defaultName = classClass.getName() + SEPARATOR + + String defaultName = clazz.getName() + SEPARATOR + Introspection.getPropertyName(method); - Class<?> defaultType = - (method.getParameterTypes()[0]); + Class<?> defaultType = (method.getParameterTypes()[0]); addResource(context, annotation, defaultName, defaultType); } } } } + /** * Process a Resource annotation to set up a Resource. * Ref JSR 250, equivalent to the resource-ref, @@ -309,8 +302,9 @@ public class WebAnnotationSet { addResource(context, annotation, null, null); } - protected static void addResource(Context context, Resource annotation, - String defaultName, Class<?> defaultType) { + + protected static void addResource(Context context, Resource annotation, String defaultName, + Class<?> defaultType) { String name = getName(annotation, defaultName); String type = getType(annotation, defaultType); @@ -365,11 +359,9 @@ public class WebAnnotationSet { resource.setName(name); resource.setType(type); - if (annotation.authenticationType() - == Resource.AuthenticationType.CONTAINER) { + if (annotation.authenticationType() == Resource.AuthenticationType.CONTAINER) { resource.setAuth("Container"); - } else if (annotation.authenticationType() - == Resource.AuthenticationType.APPLICATION) { + } else if (annotation.authenticationType() == Resource.AuthenticationType.APPLICATION) { resource.setAuth("Application"); } @@ -410,7 +402,6 @@ public class WebAnnotationSet { resource.setDescription(annotation.description()); context.getNamingResources().addResourceEnvRef(resource); - } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org