@Override public void processParams(final ProcessParameterContext processParameterContext) { final Class<?>[] parameterTypes = processParameterContext.getMethod().getParameterTypes(); if (processParameterContext.getParamNum() >= parameterTypes.length) { // ignore return; } if (!isString(parameterTypes[processParameterContext.getParamNum()])) { return; } final Annotation[] parameterAnnotations = getParameterAnnotations(processParameterContext.getMethod())[processParameterContext.getParamNum()]; for (final Annotation parameterAnnotation : parameterAnnotations) { if (parameterAnnotation instanceof RegEx) { final RegEx annotation = (RegEx) parameterAnnotation; addRegexFacetAndCorrespondingTitleFacet(processParameterContext.getFacetHolder(), annotation); return; } } }
private void addRegexFacetAndCorrespondingTitleFacet(final FacetHolder holder, final RegEx annotation) { final RegExFacet regexFacet = createRegexFacet(annotation, holder); if (regexFacet == null) { return; } FacetUtil.addFacet(regexFacet); final TitleFacet titleFacet = createTitleFacet(regexFacet); FacetUtil.addFacet(titleFacet); }
public void testRegExAnnotationIgnoredForPrimitiveOnActionParameter() { final RegExFacetAnnotationForParameterFacetFactory facetFactory = new RegExFacetAnnotationForParameterFacetFactory(); class Customer { @SuppressWarnings("unused") public void someAction(@RegEx(validation = "^A.*", caseSensitive = false) final int foo) { } } final Method method = findMethod(Customer.class, "someAction", new Class[] { int.class }); facetFactory.processParams(new ProcessParameterContext(method, 0, facetedMethodParameter)); assertNull(facetedMethod.getFacet(RegExFacet.class)); }
public void testRegExAnnotationIgnoredForNonStringsProperty() { final RegExFacetAnnotationForParameterFacetFactory facetFactory = new RegExFacetAnnotationForParameterFacetFactory(); class Customer { @SuppressWarnings("unused") @RegEx(validation = "^A.*", caseSensitive = false) public int getNumberOfOrders() { return 0; } } final Method method = findMethod(Customer.class, "getNumberOfOrders"); facetFactory.process(new ProcessMethodContext(Customer.class, method, methodRemover, facetedMethod)); assertNull(facetedMethod.getFacet(RegExFacet.class)); }
public void testRegExAnnotationPickedUpOnActionParameter() { final RegExFacetAnnotationForParameterFacetFactory facetFactory = new RegExFacetAnnotationForParameterFacetFactory(); class Customer { @SuppressWarnings("unused") public void someAction(@RegEx(validation = "^A.*", caseSensitive = false) final String foo) { } } final Method method = findMethod(Customer.class, "someAction", new Class[] { String.class }); facetFactory.processParams(new ProcessParameterContext(method, 0, facetedMethodParameter)); final Facet facet = facetedMethodParameter.getFacet(RegExFacet.class); assertNotNull(facet); assertTrue(facet instanceof RegExFacetAnnotationForParameter); final RegExFacetAnnotationForParameter regExFacet = (RegExFacetAnnotationForParameter) facet; assertEquals("^A.*", regExFacet.validation()); assertEquals(false, regExFacet.caseSensitive()); }