Example usage for java.lang.reflect Method getParameterAnnotations

List of usage examples for java.lang.reflect Method getParameterAnnotations

Introduction

In this page you can find the example usage for java.lang.reflect Method getParameterAnnotations.

Prototype

@Override
public Annotation[][] getParameterAnnotations() 

Source Link

Usage

From source file:org.ext4spring.parameter.DefaultParameterResolver.java

protected void resolveQualifier(Metadata metadata, Method method, Object[] invocationArgumnets) {
    Annotation[][] paramAnnotations = method.getParameterAnnotations();
    for (int paramIndex = 0; paramIndex < paramAnnotations.length; paramIndex++) {
        {//from  w w  w .jav  a2s . c  o  m
            for (Annotation annotation : paramAnnotations[paramIndex]) {
                if (annotation instanceof ParameterQualifier) {
                    metadata.setQualified(true);
                    if (invocationArgumnets != null && invocationArgumnets[paramIndex] != null) {
                        metadata.setQualifier(invocationArgumnets[paramIndex].toString());
                    }
                }
            }
        }
    }
}

From source file:org.activiti.spring.components.aop.ProcessStartingMethodInterceptor.java

@SuppressWarnings("unchecked")
private <K extends Annotation, V> Map<K, V> mapOfAnnotationValues(Class<K> annotationType,
        MethodInvocation invocation) {//w  w w  . java 2s.co m
    Method method = invocation.getMethod();
    Annotation[][] annotations = method.getParameterAnnotations();
    Map<K, V> vars = new HashMap<K, V>();
    int paramIndx = 0;
    for (Annotation[] annPerParam : annotations) {
        for (Annotation annotation : annPerParam) {
            if (!annotationType.isAssignableFrom(annotation.getClass())) {
                continue;
            }
            K pv = (K) annotation;
            V v = (V) invocation.getArguments()[paramIndx];
            vars.put(pv, v);

        }
        paramIndx += 1;
    }
    return vars;
}

From source file:org.openengsb.core.services.internal.RequestHandlerImpl.java

private Object[] retrieveArguments(MethodCall call, Method method) {
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    Object[] originalArgs = call.getArgs();
    for (int i = 0; i < originalArgs.length; i++) {
        Annotation[] currentArgAnnotations = parameterAnnotations[i];
        Class<? extends CustomJsonMarshaller<?>> transformationAnnotation = searchForTransformationAnnotation(
                currentArgAnnotations);//  ww  w. j a  va  2  s  .co  m
        if (transformationAnnotation == null) {
            continue;
        }
        CustomJsonMarshaller<?> transformationInstance = createTransformationInstance(transformationAnnotation);
        originalArgs[i] = transformationInstance.transformArg(originalArgs[i]);
    }
    return originalArgs;
}

From source file:com.github.carlomicieli.rest.ValidatorAspect.java

@Before("execution(* *(@com.github.carlomicieli.rest.Valid(*)))")
public void validate(JoinPoint jp) throws NoSuchMethodException {

    Set<ConstraintViolation<?>> violations = new HashSet<ConstraintViolation<?>>();

    Method methodSignature = ((MethodSignature) jp.getSignature()).getMethod();

    Method targetMethod = jp.getTarget().getClass().getMethod(methodSignature.getName(),
            methodSignature.getParameterTypes());

    Annotation[][] annotationParameters = targetMethod.getParameterAnnotations();

    for (int i = 0; i < annotationParameters.length; i++) {
        Annotation[] annotations = annotationParameters[i];
        for (Annotation a : annotations) {
            if (a.annotationType().equals(Valid.class)) {
                Object arg = jp.getArgs()[i];
                violations.addAll(validator.validate(arg));
            }/*  ww w  . java2s. c  o  m*/
        }
    }

    if (!violations.isEmpty()) {
        throw new ConstraintViolationException(violations);
    }
}

From source file:com.googlecode.android_scripting.rpc.MethodDescriptorTest.java

private void assertDefaultThrows(Method m, int param) {
    try {//from   w ww .  j  ava2  s  .  c  o m
        MethodDescriptor.getDefaultValue(m.getParameterTypes()[param], m.getParameterAnnotations()[param]);
    } catch (Exception expected) {
    }
}

From source file:net.paslavsky.springrest.SpringAnnotationPreprocessor.java

private Integer getRequestParameter(Method method) {
    Integer requestParameter = null;
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    for (int i = 0, parameterAnnotationsLength = parameterAnnotations.length; i < parameterAnnotationsLength; i++) {
        Annotation[] annotations = parameterAnnotations[i];
        if (isAnnotationPresent(annotations, RequestBody.class)) {
            requestParameter = i;/*from w  w  w  .  j  ava2 s  .  c om*/
        }
    }
    return requestParameter;
}

From source file:edu.umn.msi.tropix.persistence.aop.AutoUserAspect.java

@Before(value = "execution(* edu.umn.msi.tropix.persistence.service.*+.*(..))")
public void autoCreateUsers(final JoinPoint joinPoint) {
    final Method method = AopUtils.getMethod(joinPoint);
    //if(method.getAnnotation(PersistenceMethod.class) == null) {
    //  return;/*from ww  w. ja va  2 s  . c  o m*/
    //}
    final Annotation[][] annotations = method.getParameterAnnotations();
    for (int i = 0; i < annotations.length; i++) {
        final AutoUser autoUserAnnotation = getAnnnotation(AutoUser.class, annotations[i]);
        if (autoUserAnnotation != null) {
            final String autoId = (String) joinPoint.getArgs()[i];
            if (StringUtils.hasText(autoId)) {
                UserUtils.ensureUserExists(autoId, userDao, tropixObjectDao);
            }
        }
    }
}

From source file:org.callimachusproject.rewrite.RedirectAdviceFactory.java

FluidType[] getBindingTypes(Method method, String[] bindingNames) {
    Type[] types = method.getGenericParameterTypes();
    Annotation[][] anns = method.getParameterAnnotations();
    FluidType[] bindingTypes = new FluidType[anns.length];
    loop: for (int i = 0; i < bindingTypes.length; i++) {
        if (bindingNames[i] == null)
            continue;
        for (Annotation ann : anns[i]) {
            if (type.class.equals(ann.annotationType())) {
                bindingTypes[i] = new FluidType(types[i], ((type) ann).value());
                continue loop;
            }/*from  w w  w . j  av  a 2 s .  c o  m*/
        }
        bindingTypes[i] = new FluidType(types[i]);
    }
    return bindingTypes;
}

From source file:org.bigmouth.nvwa.session.spring.SessionAdvisor.java

@Override
public void before(Method method, Object[] args, Object target) throws Throwable {
    if (method.isAnnotationPresent(SessionValidator.class)) {
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        Trackable trackable = getTrackable(args, parameterAnnotations);
        if (null != trackable) {
            Session session = sessionHolder.getSession(trackable);
            if (null == session) {
                throw new SessionNotExistsException(trackable);
            }//from w ww  .j av a2s . co m
        }
    }
}

From source file:com.googlecode.android_scripting.rpc.MethodDescriptorTest.java

private void assertDefault(Object expected, Method m, int param) {
    assertEquals(expected,//from   w w w . j  a v  a 2 s .c o  m
            MethodDescriptor.getDefaultValue(m.getParameterTypes()[param], m.getParameterAnnotations()[param]));
}