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.b3log.latke.servlet.converter.Converters.java

/**
 * getRendererId from mark {@link org.b3log.latke.servlet.annotation.Render},using"-" as split:class_method_PARAMETER.
 *
 * @param processorClass  class/*from w w w  .j a  va2s .c  om*/
 * @param processorMethod method
 * @param i               the index of the
 * @return string
 */
private static String getRendererId(final Class<?> processorClass, final Method processorMethod, final int i) {
    final StringBuilder sb = new StringBuilder();

    if (processorClass.isAnnotationPresent(Render.class)) {
        final String v = processorClass.getAnnotation(Render.class).value();

        if (StringUtils.isNotBlank(v)) {
            sb.append(v).append(v);
        }
    }

    if (processorMethod.isAnnotationPresent(Render.class)) {

        final String v = processorClass.getAnnotation(Render.class).value();

        if (StringUtils.isNotBlank(v)) {
            if (sb.length() > 0) {
                sb.append("-");
            }
            sb.append(v).append(v);
        }
    }

    for (java.lang.annotation.Annotation annotation : processorMethod.getParameterAnnotations()[i]) {
        if (annotation instanceof Render) {
            final String v = ((PathVariable) annotation).value();

            if (sb.length() > 0) {
                sb.append("-");
            }
            sb.append(v).append(v);
        }
    }

    return sb.toString();
}

From source file:org.openhab.model.script.ui.contentassist.ActionEObjectHoverProvider.java

private ParamDoc getParamDoc(Method m, int i) {
    Annotation[][] paramAnnotations = m.getParameterAnnotations();
    Annotation[] annotations = paramAnnotations[i];
    for (Annotation a : annotations) {
        if (a instanceof ParamDoc) {
            return (ParamDoc) a;
        }//w  w  w .  j a  v a 2 s.co  m
    }
    return null;
}

From source file:org.craftercms.commons.validation.validators.impl.ValidateParamsAspect.java

@Before("@within(org.craftercms.commons.validation.annotations.param.ValidateParams) || "
        + "@annotation(org.craftercms.commons.validation.annotations.param.ValidateParams)")
public void doValidation(JoinPoint joinPoint) {
    Object[] args = joinPoint.getArgs();
    Method method = AopUtils.getActualMethod(joinPoint);
    Annotation[][] allParamAnnotations = method.getParameterAnnotations();
    ValidationResult result = new ValidationResult(errorMessageBundle);

    if (ArrayUtils.isNotEmpty(allParamAnnotations)) {
        for (int i = 0; i < args.length; i++) {
            Object param = args[i];
            Annotation[] paramAnnotations = allParamAnnotations[i];

            for (Annotation annotation : paramAnnotations) {
                validateParam(annotation, param, result);
            }/*from   ww w.  jav a 2s.c o  m*/
        }
    }

    if (result.hasErrors()) {
        String methodStr = method.toGenericString();

        result.setMessage(ValidationUtils.getErrorMessage(errorMessageBundle, INVALID_METHOD_PARAMS_ERROR_CODE,
                methodStr));

        throw new ValidationRuntimeException(result);
    }
}

From source file:org.kantega.dogmaticmvc.web.DefaultMethodParameterFactory.java

private <T extends Annotation> T getParamAnnotation(Method method, int i, Class<T> annotation) {
    for (Annotation a : method.getParameterAnnotations()[i]) {
        if (annotation.isAssignableFrom(a.getClass())) {
            return (T) a;
        }/*from   w w  w.  java  2s.  co  m*/
    }
    return null;
}

From source file:org.craftercms.commons.security.permissions.annotations.HasPermissionAnnotationHandler.java

protected Object getAnnotatedSecuredObject(Method method, ProceedingJoinPoint pjp) {
    Annotation[][] paramAnnotations = method.getParameterAnnotations();
    Object[] params = pjp.getArgs();

    for (int i = 0; i < paramAnnotations.length; i++) {
        for (Annotation a : paramAnnotations[i]) {
            if (a instanceof SecuredObject) {
                return params[i];
            }//w w  w  .ja  va 2  s .  co  m
        }
    }

    return null;
}

From source file:com.sf.ddao.shards.conn.ShardedConnectionHandler.java

protected ShardKeyGetter createShardKeyGetter(Method method) {
    Annotation[][] parametersAnnotations = method.getParameterAnnotations();
    for (int i = 0; i < parametersAnnotations.length; i++) {
        Annotation[] parameterAnnotations = parametersAnnotations[i];
        for (Annotation parameterAnnotation : parameterAnnotations) {
            if (parameterAnnotation instanceof ShardKey) {
                final ShardKey shardKey = (ShardKey) parameterAnnotation;
                final int argIdx = i;
                return new ShardKeyGetter() {
                    public Object getShardKey(Object[] args) {
                        return extractShardKey(shardKey.value(), args[argIdx]);
                    }/*from  w  w  w .j  av a 2  s  .  c  o  m*/
                };
            }
        }
    }
    return null;
}

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

String[] getBindingNames(Method method, Substitution[] substitutions) {
    Annotation[][] anns = method.getParameterAnnotations();
    String[] bindingNames = new String[anns.length];
    for (int i = 0; i < bindingNames.length; i++) {
        for (Annotation ann : anns[i]) {
            if (Iri.class.equals(ann.annotationType())) {
                String local = local(((Iri) ann).value());
                for (Substitution substitution : substitutions) {
                    if (substitution.containsVariableName(local)) {
                        bindingNames[i] = local;
                    }//  w ww .  ja  va 2 s  . c  o  m
                }
            }
        }
    }
    return bindingNames;
}

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

public ProxyPostAdvice(String[] bindingNames, FluidType[] bindingTypes, Substitution[] replacers,
        Method method) {
    super(bindingNames, bindingTypes, replacers, method);
    Annotation[][] panns = method.getParameterAnnotations();
    Type[] gtypes = method.getGenericParameterTypes();
    for (int i = 0; i < panns.length; i++) {
        if (bindingNames[i] == null) {
            for (Annotation ann : panns[i]) {
                if (ann instanceof type) {
                    bodyIndices.put(method, i);
                    String[] media = ((type) ann).value();
                    bodyFluidType = new FluidType(gtypes[i], media);
                    for (Annotation bann : panns[i]) {
                        if (bann instanceof Iri) {
                            bodyIri = ((Iri) bann).value();
                        }//from  w  w w.j a v a 2 s.  co  m
                    }
                }
            }
        }
    }
}

From source file:org.motechproject.server.omod.advice.RunAsUserAdvice.java

private User getUserToBecome(Method method, Object[] args) {

    Annotation[][] paramAnnotationsArrays = method.getParameterAnnotations();

    for (int i = 0; i < paramAnnotationsArrays.length; i++) {
        Annotation[] paramAnnotations = paramAnnotationsArrays[i];
        for (Annotation paramAnnotation : paramAnnotations) {
            if (paramAnnotation instanceof RunAsUserParam) {
                String userResolverName = ((RunAsUserParam) paramAnnotation).resolverBean();
                UserResolver userResolver = getResolverBean(userResolverName);
                return userResolver.lookupUser(args[i]);
            }// w ww .  jav  a2 s  .com
        }
    }

    throw new IllegalArgumentException(
            "method " + method + " has no " + RunAsUserParam.class.getName() + " annotation");
}

From source file:org.echocat.jemoni.jmx.reflection.ReflectionBasedOperationInvoker.java

@Nonnull
protected ArgumentDefinition[] getArgumentDefinitionsFor(@Nonnull Method method) {
    final Class<?>[] types = method.getParameterTypes();
    final Annotation[][] annotations = method.getParameterAnnotations();
    final ArgumentDefinition[] result = new ArgumentDefinition[types.length];
    for (int i = 0; i < types.length; i++) {
        result[i] = getArgumentDefinitionFor(types[i], annotations[i], i);
    }/*from w  w  w . ja  v a 2  s  .  c  o  m*/
    return result;
}