Example usage for java.lang.reflect Method isAnnotationPresent

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

Introduction

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

Prototype

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 

Source Link

Usage

From source file:com.rockagen.gnext.service.spring.aspect.OpLogAspect.java

/**
 * Get {@link com.rockagen.gnext.annotation.Plog} value
 * /* w ww  .j  av  a 2  s .c  om*/
 * @param method method
 * @return {@link com.rockagen.gnext.annotation.Plog} value
 */
private String getPlogValue(Method method) {
    if (method.isAnnotationPresent(Plog.class)) {
        Plog plog = method.getAnnotation(Plog.class);
        return plog.value();
    } else {
        return method.getDeclaringClass() + "#" + method.getName();
    }
}

From source file:modelos.Aluno.java

@Override
public String toString() {
    List<String> str = new ArrayList<>();
    for (Method m : this.getClass().getDeclaredMethods()) {
        if (m.isAnnotationPresent(Printable.class)) {
            try {
                str.add(m.getAnnotation(Printable.class).posicao(),
                        (m.invoke(this, new Object[] {})).toString());
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                continue;
            }//from ww w.j  a v a 2  s  .c  o m
        }
    }
    String result = "";
    for (String piece : str) {
        result += piece + " ";
    }
    return result.trim();
}

From source file:grails.plugin.springsecurity.acl.AclAutoProxyCreator.java

protected boolean beanIsAnnotated(final Class<?> c) {
    for (Class<? extends Annotation> annotation : ANNOTATIONS) {
        if (c.isAnnotationPresent(annotation)) {
            return true;
        }/*  w  w  w.j ava2  s .  c  o  m*/

        for (Method method : c.getMethods()) {
            if (method.isAnnotationPresent(annotation)) {
                return true;
            }
        }
    }
    return false;
}

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

private String getSystemId(Method m) {
    if (m.isAnnotationPresent(Iri.class))
        return m.getAnnotation(Iri.class).value();
    Class<?> dclass = m.getDeclaringClass();
    String mame = m.getName();//from w  ww .  j  ava2s . co  m
    if (dclass.isAnnotationPresent(Iri.class)) {
        String url = dclass.getAnnotation(Iri.class).value();
        if (url.indexOf('#') >= 0)
            return url.substring(0, url.indexOf('#') + 1) + mame;
        return url + "#" + mame;
    }
    String name = dclass.getSimpleName() + ".class";
    URL url = dclass.getResource(name);
    if (url != null)
        return url.toExternalForm() + "#" + mame;
    return "java:" + dclass.getName() + "#" + mame;
}

From source file:com.shigengyu.hyperion.cache.WorkflowTransitionCacheLoader.java

@Override
public ImmutableList<WorkflowTransition> load(WorkflowDefinition workflowDefinition) throws Exception {

    List<WorkflowTransition> workflowTransitions = Lists.newArrayList();

    for (Method method : ReflectionUtils
            .getAllDeclaredMethods(workflowDefinition.getWorkflowDefinitionType())) {
        if (method.isAnnotationPresent(Transition.class)) {
            Transition transition = method.getAnnotation(Transition.class);
            TransitionShared transitionShared = method.getAnnotation(TransitionShared.class);
            workflowTransitions.add(new WorkflowTransition(method, transition, transitionShared));
        } else if (method.isAnnotationPresent(Transitions.class)) {
            Transitions transitions = method.getAnnotation(Transitions.class);
            for (Transition transition : transitions.value()) {
                TransitionShared transitionShared = method.getAnnotation(TransitionShared.class);
                workflowTransitions.add(new WorkflowTransition(method, transition, transitionShared));
            }//from  w  ww .  j  ava 2 s .  c o  m
        }
    }

    return ImmutableList.copyOf(workflowTransitions);
}

From source file:com.zhumeng.dream.orm.hibernate.HibernateDao.java

/**
 * ?,hibernate???select count(o) from Xxx o?BUG,
 * hibernatejpql??sqlselect count(field1,field2,...),count()
 * ??HQL?:"select count(*) from Object"/*from  www . ja v a2  s. co m*/
 * @author: lizhong
 * @param <E>
 * @param clazz
 * @return
 */
protected static <E> String getCountField(Class<E> clazz) {
    String out = "o";
    try {
        PropertyDescriptor[] propertys = Introspector.getBeanInfo(clazz).getPropertyDescriptors();
        for (PropertyDescriptor property : propertys) {
            Method method = property.getReadMethod();
            if (method != null && method.isAnnotationPresent(EmbeddedId.class)) {
                PropertyDescriptor[] props = Introspector.getBeanInfo(property.getPropertyType())
                        .getPropertyDescriptors();
                out = "o." + property.getName() + "."
                        + (!props[1].getName().equals("class") ? props[1].getName() : props[0].getName());
                break;
            }
        }
    } catch (IntrospectionException e) {
        e.printStackTrace();
    }
    return out;
}

From source file:com.iisigroup.cap.operation.step.CapCaptchaOpStep.java

@Override
public OpStepContext execute(OpStepContext ctx, IRequest params, IHandler handler) {
    String methodId = params.get(FormHandler.FORM_ACTION, "");
    if (!CapString.isEmpty(methodId)) {
        for (Method method : handler.getClass().getDeclaredMethods()) {
            if (methodId.equals(method.getName())) {
                if (method.isAnnotationPresent(Captcha.class)) {
                    String key = method.getAnnotation(Captcha.class).value();
                    CapSecurityCaptcha captcha = CapAppContext.getBean(CapCaptchaServlet.DEF_RENDERER);
                    if (captcha == null || !CaptchaStatus.SUCCESS.equals(captcha.valid(params.get(key)))) {
                        // ?
                        throw new CapMessageException(CapAppContext.getMessage(captcha.getErrorMessage()),
                                getClass());
                    }//  w w  w .  j av  a  2 s  . co  m
                }
            }
        }
    }
    return ctx.setGoToStep(NEXT);
}

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

private Class<?> getResponseType0(Method method) {
    if (method.isAnnotationPresent(ResponseBody.class)) {
        return method.getReturnType();
    } else {//  ww  w .  j  av a  2  s .c o  m
        if (method.getReturnType() == ResponseEntity.class) {
            Type methodGenericReturnType = method.getGenericReturnType();
            if (methodGenericReturnType instanceof ParameterizedTypeImpl) {
                ParameterizedTypeImpl parameterizedType = (ParameterizedTypeImpl) methodGenericReturnType;
                Type type = parameterizedType.getActualTypeArguments()[0];
                return typeToClass(type);
            } else {
                // TODO Message to the log: recommendation to use ResponseEntity with generic parameter
                return byte[].class;
            }
        }
        return Void.class;
    }
}

From source file:org.colombbus.tangara.commons.resinject.ActionResourceImpl.java

public void initialize() {
    checkAttributeSet(classResource, "classResource not set"); //$NON-NLS-1$
    checkAttributeSet(actionHolder, "actionHolder not set"); //$NON-NLS-1$

    for (Method method : actionHolder.getClass().getDeclaredMethods()) {
        if (method.isAnnotationPresent(ActionPerformer.class))
            parseMethod(method);//from  www . ja  v a  2s . c  om
    }
}

From source file:org.atteo.moonshine.websocket.jsonmessages.HandlerDispatcher.java

public <T> void addHandler(Class<T> klass, Provider<? extends T> provider) {
    for (Method method : klass.getMethods()) {
        if (method.isAnnotationPresent(OnMessage.class)) {
            registerOnMessageMethod(method, provider);
        }/*from w w  w  . java 2  s  . co m*/
    }
}