/** * Adds all fields with the specified Annotation of class clazz and its superclasses to allFields * * @param annotationClass * @param clazz * @param allFields */ public static void addAllFields(Class<? extends Annotation> annotationClass, Class clazz, List<Field> allFields) { if (clazz == null) { return; } Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { Annotation ann = field.getAnnotation(annotationClass); if (ann!=null) { allFields.add(field); } } addAllFields(annotationClass, clazz.getSuperclass(), allFields); }
/** * * @param clazz * @param allInterfaces */ public static void addAllInterfaces(Class clazz, List<Class> allInterfaces) { if (clazz == null) { return; } Class[] interfaces = clazz.getInterfaces(); allInterfaces.addAll(Arrays.asList(interfaces)); addAllInterfaces(clazz.getSuperclass(), allInterfaces); }
/** * Adds all methods with the specified Annotation of class clazz and its superclasses to allFields * * @param annotationClass * @param clazz * @param allMethods */ public static void addAllMethods(Class<? extends Annotation> annotationClass, Class clazz, List<Method> allMethods) { if (clazz == null) { return; } Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { Annotation ann = method.getAnnotation(annotationClass); if (ann!=null) { allMethods.add(method); } } addAllMethods(annotationClass, clazz.getSuperclass(), allMethods); }
public List<InterceptorMapping> build(Class<?> actionClass, PackageConfig.Builder builder, String actionName, Action annotation) { List<InterceptorMapping> interceptorList = new ArrayList<>( 10); //from @InterceptorRefs annotation InterceptorRefs interceptorRefs = AnnotationUtils.findAnnotation(actionClass, InterceptorRefs.class); if (interceptorRefs != null) interceptorList.addAll(build(interceptorRefs.value(), actionName, builder)); //from @InterceptorRef annotation InterceptorRef interceptorRef = AnnotationUtils.findAnnotation(actionClass, InterceptorRef.class); if (interceptorRef != null) interceptorList.addAll(build(new InterceptorRef[] {interceptorRef}, actionName, builder)); //from @Action annotation if (annotation != null) { InterceptorRef[] interceptors = annotation.interceptorRefs(); if (interceptors != null) { interceptorList.addAll(build(interceptors, actionName, builder)); } } return interceptorList; }
/** * Invokes any @BeforeResult annotated methods * * @see com.opensymphony.xwork2.interceptor.PreResultListener#beforeResult(com.opensymphony.xwork2.ActionInvocation,String) */ public void beforeResult(ActionInvocation invocation, String resultCode) { Object action = invocation.getAction(); List<Method> methods = new ArrayList<Method>(AnnotationUtils.getAnnotatedMethods(action.getClass(), BeforeResult.class)); if (methods.size() > 0) { // methods are only sorted by priority Collections.sort(methods, new Comparator<Method>() { public int compare(Method method1, Method method2) { return comparePriorities(method1.getAnnotation(BeforeResult.class).priority(), method2.getAnnotation(BeforeResult.class).priority()); } }); for (Method m : methods) { try { m.invoke(action, (Object[]) null); } catch (Exception e) { throw new XWorkException(e); } } } }
private Set<String> getAllowedMethods(Class<?> actionClass) { List<AllowedMethods> annotations = AnnotationUtils.findAnnotations(actionClass, AllowedMethods.class); if (annotations == null || annotations.isEmpty()) { return Collections.emptySet(); } else { Set<String> methods = new HashSet<>(); for (AllowedMethods allowedMethods : annotations) { methods.addAll(Arrays.asList(allowedMethods.value())); } return methods; } }
/** * For the given <code>Class</code> get a collection of the the {@link AnnotatedElement}s * that match the given <code>annotation</code>s or if no <code>annotation</code>s are * specified then return all of the annotated elements of the given <code>Class</code>. * Includes only the method level annotations. * * @param clazz The {@link Class} to inspect * @param annotation the {@link Annotation}s to find * @return A {@link Collection}<{@link AnnotatedElement}> containing all of the * method {@link AnnotatedElement}s matching the specified {@link Annotation}s */ public static Collection<Method> getAnnotatedMethods(Class clazz, Class<? extends Annotation>... annotation){ Collection<Method> toReturn = new HashSet<Method>(); for(Method m : clazz.getMethods()){ if( ArrayUtils.isNotEmpty(annotation) && isAnnotatedBy(m, annotation) ){ toReturn.add(m); }else if( ArrayUtils.isEmpty(annotation) && ArrayUtils.isNotEmpty(m.getAnnotations())){ toReturn.add(m); } } return toReturn; }
key = AnnotationUtils.resolvePropertyName(method); if (LOG.isDebugEnabled()) { LOG.debug("Retrieved key [#0] from method name [#1]", key, method.getName());
Namespace namespaceAnnotation = AnnotationUtils.findAnnotation(actionClass, Namespace.class); if (namespaceAnnotation != null) { LOG.trace("Using non-default action namespace from Namespace annotation of [{}]", namespaceAnnotation.value()); Namespaces namespacesAnnotation = AnnotationUtils.findAnnotation(actionClass, Namespaces.class); if (namespacesAnnotation != null) { if (LOG.isTraceEnabled()) {
final Object action = invocation.getAction(); invocation.addPreResultListener(this); List<Method> methods = new ArrayList<Method>(AnnotationUtils.getAnnotatedMethods(action.getClass(), Before.class)); if (methods.size() > 0) { methods = new ArrayList<Method>(AnnotationUtils.getAnnotatedMethods(action.getClass(), After.class));
/** * {@inheritDoc} */ public String determineResultPath(Class<?> actionClass) { String localResultPath = resultPath; ResultPath resultPathAnnotation = AnnotationUtils.findAnnotation(actionClass, ResultPath.class); if (resultPathAnnotation != null) { if (resultPathAnnotation.value().equals("") && resultPathAnnotation.property().equals("")) { throw new ConfigurationException("The ResultPath annotation must have either" + " a value or property specified."); } String property = resultPathAnnotation.property(); if (property.equals("")) { localResultPath = resultPathAnnotation.value(); } else { try { ResourceBundle strutsBundle = ResourceBundle.getBundle("struts"); localResultPath = strutsBundle.getString(property); } catch (Exception e) { throw new ConfigurationException("The action class [" + actionClass + "] defines" + " a @ResultPath annotation and a property definition however the" + " struts.properties could not be found in the classpath using ResourceBundle" + " OR the bundle exists but the property [" + property + "] is not defined" + " in the file.", e); } } } return localResultPath; }
AnnotationUtils.addAllFields(Allowed.class, action.getClass(), annotatedFields); if (model != null) { AnnotationUtils.addAllFields(Allowed.class, model.getClass(), annotatedFields); AnnotationUtils.addAllFields(Blocked.class, action.getClass(), annotatedFields); if (model != null) { AnnotationUtils.addAllFields(Blocked.class, model.getClass(), annotatedFields);
ParentPackage parent = AnnotationUtils.findAnnotation(actionClass, ParentPackage.class); String parentName = null; if (parent != null) { DefaultInterceptorRef defaultInterceptorRef = AnnotationUtils.findAnnotation(actionClass, DefaultInterceptorRef.class); if (defaultInterceptorRef != null) { pkgConfig.defaultInterceptorRef(defaultInterceptorRef.value());