Example usage for java.lang.reflect Method getAnnotation

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

Introduction

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

Prototype

public <T extends Annotation> T getAnnotation(Class<T> annotationClass) 

Source Link

Usage

From source file:com.ivanzhangwb.interpose.core.InterposeBootStrap.java

/**
 * ?/*from   w w w.j  av a2s  .c  om*/
 * 
 * @param methods
 * @param i
 */
private void handleMethodAnnotation(Method method) {
    InterposeAnnotationCache.put(new MethodInfo(method.getName(), method.getParameterTypes()).toString(),
            method.getAnnotation(Interpose.class));
}

From source file:org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBHashAndRangeKeyMethodExtractorImpl.java

/**
 * Creates a new {@link DynamoDBHashAndRangeKeyMethodExtractor} for the given domain type.
 *
 * @param idType/*from w  w w. j  a v  a 2s .  co  m*/
 *            must not be {@literal null}.
 */
public DynamoDBHashAndRangeKeyMethodExtractorImpl(final Class<T> idType) {

    Assert.notNull(idType, "Id type must not be null!");
    this.idType = idType;
    ReflectionUtils.doWithMethods(idType, new MethodCallback() {
        @Override
        public void doWith(Method method) {
            if (method.getAnnotation(DynamoDBHashKey.class) != null) {
                Assert.isNull(hashKeyMethod,
                        "Multiple methods annotated by @DynamoDBHashKey within type " + idType.getName() + "!");
                ReflectionUtils.makeAccessible(method);
                hashKeyMethod = method;
            }
        }
    });
    ReflectionUtils.doWithFields(idType, new FieldCallback() {
        @Override
        public void doWith(Field field) {
            if (field.getAnnotation(DynamoDBHashKey.class) != null) {
                Assert.isNull(hashKeyField,
                        "Multiple fields annotated by @DynamoDBHashKey within type " + idType.getName() + "!");
                ReflectionUtils.makeAccessible(field);

                hashKeyField = field;
            }
        }
    });
    ReflectionUtils.doWithMethods(idType, new MethodCallback() {
        @Override
        public void doWith(Method method) {
            if (method.getAnnotation(DynamoDBRangeKey.class) != null) {
                Assert.isNull(rangeKeyMethod, "Multiple methods annotated by @DynamoDBRangeKey within type "
                        + idType.getName() + "!");
                ReflectionUtils.makeAccessible(method);
                rangeKeyMethod = method;
            }
        }
    });
    ReflectionUtils.doWithFields(idType, new FieldCallback() {
        @Override
        public void doWith(Field field) {
            if (field.getAnnotation(DynamoDBRangeKey.class) != null) {
                Assert.isNull(rangeKeyField,
                        "Multiple fields annotated by @DynamoDBRangeKey within type " + idType.getName() + "!");
                ReflectionUtils.makeAccessible(field);
                rangeKeyField = field;
            }
        }
    });
    if (hashKeyMethod == null && hashKeyField == null) {
        throw new IllegalArgumentException(
                "No method or field annotated by @DynamoDBHashKey within type " + idType.getName() + "!");
    }
    if (rangeKeyMethod == null && rangeKeyField == null) {
        throw new IllegalArgumentException(
                "No method or field annotated by @DynamoDBRangeKey within type " + idType.getName() + "!");
    }
    if (hashKeyMethod != null && hashKeyField != null) {
        throw new IllegalArgumentException(
                "Both method and field annotated by @DynamoDBHashKey within type " + idType.getName() + "!");
    }
    if (rangeKeyMethod != null && rangeKeyField != null) {
        throw new IllegalArgumentException(
                "Both method and field annotated by @DynamoDBRangeKey within type " + idType.getName() + "!");
    }
}

From source file:org.apache.aries.blueprint.plugin.model.Bean.java

public Bean(Class<?> clazz) {
    this.clazz = clazz;
    this.id = getBeanName(clazz);
    for (Method method : clazz.getDeclaredMethods()) {
        PostConstruct postConstruct = method.getAnnotation(PostConstruct.class);
        if (postConstruct != null) {
            this.initMethod = method.getName();
        }//from w  ww . ja v a  2s .  c om
        PreDestroy preDestroy = method.getAnnotation(PreDestroy.class);
        if (preDestroy != null) {
            this.destroyMethod = method.getName();
        }
    }
    this.persistenceUnitField = getPersistenceUnit();
    this.transactionDef = new JavaxTransactionFactory().create(clazz);
    if (this.transactionDef == null) {
        this.transactionDef = new SpringTransactionFactory().create(clazz);
    }
    properties = new TreeSet<Property>();
}

From source file:org.obiba.opal.web.security.AuthorizationInterceptor.java

@NotNull
private String getPath(Method method) {
    Path path = method.getAnnotation(Path.class);
    return path == null ? "" : path.value();
}

From source file:com.monarchapis.driver.spring.rest.ApiRequestHandlerInterceptor.java

/**
 * Handles the {@link ApiOperation}, {@link ApiVersion},
 * {@link BypassAnalytics}, and {@link Authorize} annotations.
 * /* www .ja  v  a  2 s.  c om*/
 * @param request
 *            The API request
 * @param response
 *            The API response
 * @param handler
 *            The handler method.
 * @return true unless an exception is thrown by the security checks.
 */
private boolean preHandleMethod(HttpServletRequest request, HttpServletResponse response,
        HandlerMethod handler) {
    Method method = handler.getMethod();

    ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
    String operation = apiOperation != null ? apiOperation.value() : method.getName();
    OperationNameHolder.setCurrent(operation);

    ApiVersion apiVersion = getAnnotation(method, ApiVersion.class);

    if (apiVersion != null) {
        VersionHolder.setCurrent(apiVersion.value());
    }

    BypassAnalytics bypassAnalytics = getAnnotation(method, BypassAnalytics.class);

    if (bypassAnalytics != null) {
        BypassAnalyticsHolder.setCurrent(true);
    }

    Authorize authorize = getAnnotation(method, Authorize.class);

    if (authorize != null) {
        RequestWeight requestWeight = method.getAnnotation(RequestWeight.class);
        BigDecimal weight = requestWeight != null ? new BigDecimal(requestWeight.value())
                : Authenticator.NORMAL_WEIGHT;
        String[] client = authorize.client();
        String[] delegated = authorize.delegated();
        boolean user = authorize.user();
        Claim[] claims = authorize.claims();

        Authenticator authenticator = ServiceResolver.getInstance().required(Authenticator.class);
        authenticator.performAccessChecks(weight, client, delegated, user, claims);
    }

    return true;
}

From source file:com.baomidou.kisso.web.interceptor.SSOSpringInterceptor.java

/**
 * ???//from  www .ja  v  a 2 s . c o m
 * <p>
 *  Controller ??
 * </p>
 */
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    /**
     * ? Controller 
     * <p>
     *  handler ? HandlerMethod 
     * </p>
     */
    if (handler instanceof HandlerMethod) {
        HandlerMethod handlerMethod = (HandlerMethod) handler;
        Method method = handlerMethod.getMethod();
        Login login = method.getAnnotation(Login.class);
        if (login != null) {
            if (login.action() == Action.Skip) {
                /**
                 * 
                 */
                return true;
            }
        }

        /**
         * 
         */
        Token token = SSOHelper.getToken(request);
        if (token == null) {
            if (HttpUtil.isAjax(request)) {
                /*
                 * Handler ? AJAX 
                 */
                this.getHandlerInterceptor().preTokenIsNullAjax(request, response);
                return false;
            } else {
                /*
                 * token  Handler ?
                 *  true ?????
                 */
                if (this.getHandlerInterceptor().preTokenIsNull(request, response)) {
                    logger.fine("logout. request url:" + request.getRequestURL());
                    SSOHelper.clearRedirectLogin(request, response);
                }
                return false;
            }
        } else {
            /*
             * request  token ?
             */
            request.setAttribute(SSOConfig.SSO_TOKEN_ATTR, token);
        }
    }

    /**
     * 
     */
    return true;
}

From source file:org.LexGrid.LexBIG.caCore.applicationservice.resource.RemoteResourceManager.java

private boolean doMethodsContainClientSideSafeAnnotation(Class<?> clazz) {
    for (Method method : clazz.getMethods()) {
        if (method.isAnnotationPresent(LgClientSideSafe.class)) {
            LgClientSideSafe css = method.getAnnotation(LgClientSideSafe.class);
            if (css.force()) {
                return true;
            }// ww w. j  av  a2  s.com
        }
    }
    return false;
}

From source file:com.googlecode.jdbcproc.daofactory.guice.DaoMethodInfoGuice.java

/**
 * Creates method info for bets performance
 * @param daoMethod method// www. j av  a 2 s. com
 * @return method info
 */
public DaoMethodInvoker createDaoMethodInvoker(Method daoMethod) {
    AStoredProcedure procedureAnnotation = daoMethod.getAnnotation(AStoredProcedure.class);
    Assert.notNull(procedureAnnotation, "Method must have @AStoredProcedure annotation");

    String procedureName = procedureAnnotation.name();
    Assert.hasText(procedureName,
            "Method " + daoMethod.toString() + " has empty name() parameter in @AStoredProcedure annotation");

    StoredProcedureInfo procedureInfo = storedProcedureInfoManager.getProcedureInfo(procedureName);
    if (LOG.isDebugEnabled()) {
        LOG.debug("      Found procedure info: " + procedureInfo);
    }
    Assert.notNull(procedureInfo, "There is no procedure '" + procedureName + "' in database");

    String callString = createCallString(procedureInfo);

    boolean isReturnIterator = BlockFactoryUtils.isReturnIterator(daoMethod);

    return new DaoMethodInvoker(procedureInfo.getProcedureName(), callString,
            registerOutParametersBlockService.create(procedureInfo),
            parametersSetterBlockService.create(jdbcTemplate, parameterConverterService, daoMethod,
                    procedureInfo, metaLoginInfoService),
            callableStatementExecutorBlockService.create(daoMethod, procedureInfo),
            outputParametersGetterBlockService.create(parameterConverterService, daoMethod, procedureInfo),
            resultSetConverterBlockService.create(daoMethod, procedureInfo, parameterConverterService),
            isReturnIterator, callableStatementSetStrategy, preparedStatementStrategy);
}

From source file:com.baomidou.kisso.web.interceptor.SSOShiroInterceptor.java

/**
 * ???//from ww w .  j  av a2 s . c  o m
 * <p>
 *  Controller ??
 * </p>
 */
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    if (handler instanceof HandlerMethod) {
        SSOToken token = SSOHelper.attrToken(request);
        if (token == null) {
            return true;
        }

        /**
         * shiro ??
         */
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession(false);
        if (session != null) {
            session.touch();
        }

        /**
         * shiro ?
         */
        if (!currentUser.isAuthenticated()) {
            currentUser.login(new SSOAuthToken(token));
            logger.fine(" shiro login success. ");
        }

        /**
         * URL ???
         */
        if (SSOConfig.getInstance().isPermissionUri()) {
            String uri = request.getRequestURI();
            if (uri == null || currentUser.isPermitted(uri)) {
                return true;
            }
        }

        /**
         * ???
         */
        HandlerMethod handlerMethod = (HandlerMethod) handler;
        Method method = handlerMethod.getMethod();
        Permission pm = method.getAnnotation(Permission.class);
        if (pm != null) {
            if (pm.action() == Action.Skip) {
                /**
                 * 
                 */
                return true;
            } else if (!"".equals(pm.value()) && currentUser.isPermitted(pm.value())) {
                /**
                 * ???
                 */
                return true;
            }
        }

        /**
         * ??
         */
        return unauthorizedAccess(request, response);
    }

    return true;
}

From source file:com.betfair.tornjak.monitor.aop.MonitorAOP.java

private MonitorMethod getAnnotation(final ProceedingJoinPoint pjp) {
    MethodSignature signature = (MethodSignature) pjp.getSignature();
    MonitorMethod fromSignature = signature.getMethod().getAnnotation(MonitorMethod.class);
    if (fromSignature != null) {
        return fromSignature;
    }//from  w  ww .j  av  a  2  s  .  c  om
    // right, couldn't find it on the method signature, but we might be looking at an implementation of an interface
    // so now look at the target object/class
    try {
        Method m = pjp.getTarget().getClass().getDeclaredMethod(signature.getName(),
                signature.getParameterTypes());
        return m.getAnnotation(MonitorMethod.class);
    } catch (NoSuchMethodException e) {
        // hmm, not sure we should ever see this
        throw new IllegalStateException("Couldn't find method that was called on the object it was called on");
    }
}