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.stehno.sjdbcx.RepositoryFactory.java

@Override
protected T createInstance() throws Exception {
    final ImplementationProvider implProvider = implementationProviderClass.newInstance();
    implProvider.setPrototype(objectType);
    implProvider.init(applicationContext);

    for (final Method method : objectType.getMethods()) {
        if (method.isAnnotationPresent(Sql.class)) {
            log.trace("Processing method: {}", method);

            implProvider.implement(method);

        } else {/*from  w w  w . j av  a2 s  . c o  m*/
            if (objectType.isInterface()) {
                log.warn("Found interface method ({}) without Sql annotation - ignoring.", method);
            } else {
                log.trace("Found non-annotated method ({}) - ignoring", method);
            }
        }
    }

    return (T) implProvider.instantiate();
}

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

private StatusLine getStatusLine(Method method) {
    if (method.isAnnotationPresent(alternate.class))
        return new BasicStatusLine(HttpVersion.HTTP_1_1, 302, "Alternate");
    if (method.isAnnotationPresent(describedby.class))
        return new BasicStatusLine(HttpVersion.HTTP_1_1, 303, "Described By");
    if (method.isAnnotationPresent(resides.class))
        return new BasicStatusLine(HttpVersion.HTTP_1_1, 307, "Resides");
    if (method.isAnnotationPresent(moved.class))
        return new BasicStatusLine(HttpVersion.HTTP_1_1, 308, "Moved");
    throw new AssertionError();
}

From source file:com.github.tddts.jet.config.spring.postprocessor.MessageAnnotationBeanPostProcessor.java

private boolean checkMethod(Method method, Class<?> type) {
    if (!method.isAnnotationPresent(Message.class)) {
        return false;
    }/*from   w  w  w.  j a v  a  2 s  . co m*/
    if (method.getParameterCount() == 1 && method.getParameterTypes()[0].equals(String.class)) {
        return true;
    }
    logger.warn("Method [" + type + "." + method.getName()
            + "] is not populated with message. Method should have a single String parameter.");
    return false;
}

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

private String[] getCommands(Method method) {
    if (method.isAnnotationPresent(canonical.class))
        return method.getAnnotation(canonical.class).value();
    if (method.isAnnotationPresent(alternate.class))
        return method.getAnnotation(alternate.class).value();
    if (method.isAnnotationPresent(describedby.class))
        return method.getAnnotation(describedby.class).value();
    if (method.isAnnotationPresent(resides.class))
        return method.getAnnotation(resides.class).value();
    if (method.isAnnotationPresent(moved.class))
        return method.getAnnotation(moved.class).value();
    return null;/*from  w ww .  j av a 2  s .c om*/
}

From source file:org.zanata.security.permission.PermissionEvaluator.java

/**
 * Registers all permission granter methods found in clazz to be used to
 * check permissions.//from   w ww  .  j a  v  a2 s . com
 *
 * @param clazz
 */
public void registerPermissionGranters(Class<?> clazz) {
    for (Method m : clazz.getDeclaredMethods()) {
        if (m.isAnnotationPresent(GrantsPermission.class)) {
            PermissionGranter granter = new PermissionGranter(m);
            granter.validate();

            if (granter.getEvaluatedActions().size() == 0) {
                // This granter is to apply to every action
                permissionGrantMethods.put(ALL_ACTION_GRANTER, granter);
            } else {
                for (String action : granter.getEvaluatedActions()) {
                    permissionGrantMethods.put(action, granter);
                }
            }
        }
    }
}

From source file:org.jtheque.ui.utils.AbstractController.java

/**
 * Generate the cache of methods./* w  ww.  ja  v a  2 s  . co m*/
 */
private void generateCache() {
    Method[] methods = getClass().getMethods();

    for (Method method : methods) {
        if (method.isAnnotationPresent(Action.class)) {
            Action action = method.getAnnotation(Action.class);

            methodCache.put(action.value(), method);
        }
    }
}

From source file:org.ff4j.aop.FeatureAutoProxy.java

private Object[] addAnnotedInterface(Class<?> currentInterface) {
    String currentInterfaceName = currentInterface.getCanonicalName();
    if (!currentInterfaceName.startsWith("java.")) {
        // Avoid process same interface several times
        Boolean isInterfaceFlipped = processedInterface.get(currentInterfaceName);
        if (isInterfaceFlipped != null) {
            if (isInterfaceFlipped) {
                return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
            }/*from   w  ww .  ja  v  a2s .c o  m*/
        } else {
            if (currentInterface.isAnnotationPresent(Flip.class)) {
                // If annotation is registered on Interface class 
                processedInterface.put(currentInterfaceName, true);
                return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
            } else {
                for (Method method : currentInterface.getDeclaredMethods()) {
                    if (method.isAnnotationPresent(Flip.class)) {
                        processedInterface.put(currentInterfaceName, true);
                        return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
                    }
                }
                processedInterface.put(currentInterfaceName, false);
            }
        }
    }
    return null;
}

From source file:org.sglj.service.rmi.AbstractRemoteServiceManager.java

/**
 * /*  w w  w.  ja  va2 s. c  o m*/
 * @param remoteServices services to be registered
 * @throws IllegalArgumentException if the contract defined in 
 * the {@link RemoteServiceManager} interface is broken.
 */
public <T2 extends T> AbstractRemoteServiceManager(T2... remoteServices) throws IllegalArgumentException {
    Validate.noNullElements(remoteServices, "Remote service cannot be null");

    Set<T> uniqueServices = new HashSet<T>(remoteServices.length);
    for (T remoteService : remoteServices) {
        uniqueServices.add(remoteService);
    }

    // ensure that there are no duplicate services
    Validate.isTrue(uniqueServices.size() == remoteServices.length, "Duplicate services detected");

    // ensure that services have distinct identifiers
    Set<Byte> ids = new HashSet<Byte>(uniqueServices.size());
    for (RemoteService service : remoteServices) {
        ids.add(service.getId());
    }
    Validate.isTrue(uniqueServices.size() == ids.size(), "Services with identical id detected");
    ids.clear(); // free memory before allocating new

    services = Collections.unmodifiableList(new ArrayList<T>(uniqueServices));

    // retrieve all remote methods and store them in a map by name
    for (RemoteService service : services) {
        Method[] methods = service.getClass().getMethods();
        Set<Pair<String, Integer>> set = new HashSet<Pair<String, Integer>>();
        for (Method m : methods) {
            if (m.isAnnotationPresent(RemoteMethod.class)) {
                int paramCount = m.getParameterTypes().length;
                if (!set.add(new Pair<String, Integer>(m.getName(), paramCount))) {
                    throw new IllegalArgumentException("Two methods with the same name \"" + m.getName()
                            + "\" and with " + paramCount + " parameters detected in service" + service);
                }
                registerRemoteMethod(service.getId(), m);
            }
        }
    }
}

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  ww w  .ja  va2 s . com
        }
    }
}

From source file:org.jtxer.proxy.TransactionInterceptor.java

public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    Object result = null;//from ww w .java 2  s  .co m
    if (method.isAnnotationPresent(Transaction.class)) {
        TransactionStatus tx = null;
        AnnotationTransactionManager manager = JtxerHelper.getAnnotationTxManager();
        try {
            TransactionDefinition definition = manager.getTransactionDefinition(obj.getClass(), method);
            System.out.println("TransactionMode=" + definition);
            String scope = manager.getScope(obj.getClass(), method);
            tx = manager.beginTransaction(definition, scope);
            result = proxy.invokeSuper(obj, args);
            manager.commitTransaction(tx);
        } catch (Exception ex) {
            ex.printStackTrace();
            manager.rollbackTransaction(tx, ex);
        }
    } else {
        result = proxy.invokeSuper(obj, args);
    }
    return result;
}