/** * Reads method's alias value. */ protected String parseMethodAlias(final ActionAnnotationValues annotationValues) { String alias = null; if (annotationValues != null) { alias = annotationValues.alias(); } return alias; }
/** * Reads annotation value from annotated element. If annotation does not exist, returns {@code null}. */ public ActionAnnotationValues readAnnotationValue(final AnnotatedElement annotatedElement) { for (final AnnotationParser annotationParser : annotationParsers) { if (annotationParser.hasAnnotationOn(annotatedElement)) { return ActionAnnotationValues.of(annotationParser, annotatedElement); } } return null; }
/** * Resolves action config. */ protected ActionConfig resolveActionConfig(final ActionAnnotationValues annotationValues) { final Class<? extends Annotation> annotationType; if (annotationValues == null) { annotationType = Action.class; } else { annotationType = annotationValues.annotationType(); } return actionConfigManager.lookup(annotationType); }
@Test void testCustomActionAnnotation() throws NoSuchMethodException { final AnnotationParser annotationParser = parserFor(CustomAction.class); Method method = this.getClass().getMethod("hello3"); ActionAnnotationValues annotationValues = ActionAnnotationValues.of(annotationParser, method); assertEquals("ALIAS", annotationValues.alias()); assertNull(annotationValues.value()); method = this.getClass().getMethod("hello4"); annotationValues = ActionAnnotationValues.of(annotationParser, method); assertEquals("ALIAS", annotationValues.alias()); assertNull(annotationValues.value()); }
@Test void testActionAnnotationOnly() throws NoSuchMethodException { Method method = this.getClass().getMethod("hello"); ActionAnnotationValues annotationValues = annValueOf(method); assertNull(annotationValues.alias()); assertNull(annotationValues.value()); method = this.getClass().getMethod("hello2"); annotationValues = annValueOf(method); assertEquals("alias", annotationValues.alias); assertEquals("value.ext", annotationValues.value); }
/** * Reads action path from the action method. */ protected String[] readMethodActionPath(final String methodName, final ActionAnnotationValues annotationValues, final ActionConfig actionConfig) { // read annotation String methodActionPath = annotationValues != null ? annotationValues.value() : null; if (methodActionPath == null) { methodActionPath = methodName; } else { if (methodActionPath.equals(Action.NONE)) { return ArraysUtil.array(null, null); } } // check for defaults for (String path : actionConfig.getActionMethodNames()) { if (methodActionPath.equals(path)) { methodActionPath = null; break; } } return ArraysUtil.array(methodName, methodActionPath); }
public static ActionAnnotationValues of(final AnnotationParser annotationParser, final AnnotatedElement annotatedElement) { if (!annotationParser.hasAnnotationOn(annotatedElement)) { return null; } return new ActionAnnotationValues(annotationParser.of(annotatedElement)); }
@Test void testMiscActionAnnotation() throws NoSuchMethodException { final AnnotationParser annotationParser = parserFor(MiscAnnotation.class); Method method = this.getClass().getMethod("hello5"); ActionAnnotationValues annotationValues = ActionAnnotationValues.of(annotationParser, method); assertNull(annotationValues.alias()); assertEquals("VAL", annotationValues.value()); method = this.getClass().getMethod("hello6"); annotationValues = ActionAnnotationValues.of(annotationParser, method); assertNull(annotationValues.alias()); assertEquals("VAL", annotationValues.value()); }
/** * Shortcut method assuming default annotation. */ public static ActionAnnotationValues annValueOf(final AnnotatedElement annotatedElement) { return ActionAnnotationValues.of(new AnnotationParser(Action.class), annotatedElement); }