Java Code Examples for java.lang.reflect.Method.getAnnotation()

The following are Jave code examples for showing how to use getAnnotation() of the java.lang.reflect.Method class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Pogamut3   File: AnnotationListenerRegistrator.java   View Source Code Vote up 6 votes
public LevelDListener(Method method) {
	NullCheck.check(method, "method");
	this.method = method; 
	
	// check the annotation
	if (getAnnotation() == null) {
		throw new ListenerMethodParametersException(method, "There is no ObjectListener annotation on the method!", AnnotationListenerRegistrator.this);				
	}
	
	// check the method signature
	if (method.getParameterTypes().length != 1 ||
	    !method.getParameterTypes()[0].isAssignableFrom(IWorldObjectEvent.class)) { 
		throw new ListenerMethodParametersException(method, method.getAnnotation(ObjectListener.class), AnnotationListenerRegistrator.this);
	}
	
	objectId = getId(method, getAnnotation());
}
 
Example 2
Project: easyweb   File: LogUtils.java   View Source Code Vote up 6 votes
@Override
public void run() {
    // 获取日志标题
    if (StringUtils.isBlank(log.getTitle())) {
        String permission = "";
        if (handler instanceof HandlerMethod) {
            Method m = ((HandlerMethod) handler).getMethod();
            RequiresPermissions rp = m.getAnnotation(RequiresPermissions.class);
            permission = (rp != null ? StringUtils.join(rp.value(), ",") : "");
        }
    }
    // 如果有异常,设置异常信息
    log.setException(Exceptions.getStackTraceAsString(ex));
    // 如果无标题并无异常日志,则不保存信息
    if (StringUtils.isBlank(log.getTitle()) && StringUtils.isBlank(log.getException())) {
        return;
    }
    logService.insert(log);
}
 
Example 3
Project: openjdk-jdk10   File: SJFM_TestBase.java   View Source Code Vote up 6 votes
/**
 * Tests a specific file manager, by calling all methods annotated
 * with {@code @Test} passing this file manager as an argument.
 *
 * @param fm the file manager to be tested
 * @throws Exception if the test fails
 */
void test(StandardJavaFileManager fm) throws Exception {
    System.err.println("Testing " + fm);
    for (Method m: getClass().getDeclaredMethods()) {
        Annotation a = m.getAnnotation(Test.class);
        if (a != null) {
            try {
                System.err.println("Test " + m.getName());
                m.invoke(this, new Object[] { fm });
            } catch (InvocationTargetException e) {
                Throwable cause = e.getCause();
                throw (cause instanceof Exception) ? ((Exception) cause) : e;
            }
            System.err.println();
        }
    }
}
 
Example 4
Project: sharding-quickstart   File: PackageUtil.java   View Source Code Vote up 6 votes
public static Set<Method> findShardMethodsAndRegist(String fullClassName,Class<? extends Annotation> anno,boolean check) throws ClassNotFoundException {
    Set<Method> methodSet = new HashSet<Method>();
    Class<?> clz = Class.forName(fullClassName);
    Method[] methods = clz.getDeclaredMethods();
    for (Method method : methods) {
        int modifiers = method.getModifiers();
        if (Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) {
            continue;
        }
        Annotation annotation = method.getAnnotation(anno);
        
        String statementId = fullClassName + DIAN + method.getName();
        
        if (annotation != null) {
            if (check) {
                Method checkExists = ShardMethodFactory.getStatementMethodById(statementId);
                if (checkExists!=null) {
                    throw new IllegalArgumentException(" duplicate key : "+statementId);
                }
            }
            ShardMethodFactory.regMethod(statementId, method);
            methodSet.add(method);
        }
    }
    return methodSet;
}
 
Example 5
Project: vertx-zero   File: UnityTunnel.java   View Source Code Vote up 6 votes
private Transit getTransit(final Method method) {
    final Annotation annotation = method.getAnnotation(Ipc.class);
    // 1. Check only one is enough because of Error-40043
    // 2. to and from must not be null at the same time because of Error-40045
    final String to = Instance.invoke(annotation, "to");
    final Transit transit;
    if (StringUtil.isNil(to)) {
        // Node transit
        transit = Instance.singleton(FinalTransit.class);
        LOGGER.info(Info.NODE_FINAL, method, method.getDeclaringClass());
    } else {
        // Final transit
        transit = Instance.singleton(NodeTransit.class);
        LOGGER.info(Info.NODE_MIDDLE, method, method.getDeclaringClass());
    }
    // Connect for transit
    transit.connect(method);
    return transit;
}
 
Example 6
Project: AndroidBackendlessChat   File: AndroidDeferredObject.java   View Source Code Vote up 6 votes
protected AndroidExecutionScope determineAndroidExecutionScope(Class<?> clazz, String methodName, Class<?> ... arguments) {
	ExecutionScope scope = null;
	
	if (methodName != null) {
		try {
			Method method = clazz.getMethod(methodName, arguments);
			scope = method.getAnnotation(ExecutionScope.class);
		} catch (NoSuchMethodException e) {
			throw new RuntimeException(e);
		}
	}
	if (scope == null) {
		scope = clazz.getAnnotation(ExecutionScope.class);
	}
	
	return scope == null ? defaultAndroidExecutionScope : scope.value();
}
 
Example 7
Project: ServerCommons   File: CommandFramework.java   View Source Code Vote up 5 votes
public void unregisterCommands(Object obj) {
    for (Method m : obj.getClass().getMethods()) {
        if (m.getAnnotation(Command.class) != null) {
            Command command = m.getAnnotation(Command.class);
            this.commandMap.remove(command.name().toLowerCase());
            this.commandMap.remove(this.plugin.getName() + ":" + command.name().toLowerCase());
            this.map.getCommand(command.name().toLowerCase()).unregister(this.map);
        }
    }
}
 
Example 8
Project: openjdk-jdk10   File: APITest.java   View Source Code Vote up 5 votes
/** Invoke all methods annotated with @Test. */
protected void run() throws Exception {
    for (Method m: getClass().getDeclaredMethods()) {
        Annotation a = m.getAnnotation(Test.class);
        if (a != null) {
            testCount++;
            testName = m.getName();
            System.err.println("test: " + testName);
            try {
                m.invoke(this, new Object[] { });
            } catch (InvocationTargetException e) {
                Throwable cause = e.getCause();
                throw (cause instanceof Exception) ? ((Exception) cause) : e;
            }
            System.err.println();
        }
    }

    if (testCount == 0)
        error("no tests found");

    StringBuilder summary = new StringBuilder();
    if (testCount != 1)
        summary.append(testCount).append(" tests");
    if (errorCount > 0) {
        if (summary.length() > 0) summary.append(", ");
        summary.append(errorCount).append(" errors");
    }
    System.err.println(summary);
    if (errorCount > 0)
        throw new Exception(errorCount + " errors found");
}
 
Example 9
Project: unitimes   File: Localization.java   View Source Code Vote up 5 votes
private Map<String, String> getStrutsActions(Object proxy, Class<? extends LocalizedLookupDispatchAction> apply) throws Throwable {
	Map<String, String> ret = new HashMap<String, String>();
	for (Method m: iMessages.getDeclaredMethods()) {
		if (m.getParameterTypes().length > 0) continue;
		org.unitime.localization.messages.Messages.StrutsAction action = m.getAnnotation(org.unitime.localization.messages.Messages.StrutsAction.class);
		if (action != null) {
			Messages.DefaultMessage dm = m.getAnnotation(Messages.DefaultMessage.class);
			if (action.apply() == null || action.apply().length == 0) {
				try {
					if (apply.getMethod(action.value(), new Class<?>[] {
						ActionMapping.class, ActionForm.class, HttpServletRequest.class, HttpServletResponse.class
						}) != null) {
						ret.put((String)invoke(proxy, m, new Object[] {}), action.value());
						if (dm != null)
							ret.put(dm.value(), action.value());
					}
				} catch (NoSuchMethodException e) {}
			} else {
				for (Class<? extends LocalizedLookupDispatchAction> a: action.apply())
					if (a.equals(apply)) {
						ret.put((String)invoke(proxy, m, new Object[] {}), action.value());
						if (dm != null)
							ret.put(dm.value(), action.value());
					}
			}
		}
	}
	return ret;
}
 
Example 10
Project: Rubus   File: HardwareReport.java   View Source Code Vote up 5 votes
public static Map<String, Method> infoMethods(Class<?> c) {
    Map<String, Method> mets = new TreeMap<String, Method>();
    for (Method met : c.getMethods()) {
        InfoName name = met.getAnnotation(InfoName.class);
        if (name == null) {
            continue;
        }
        mets.put(name.value(), met);
    }
    return mets;
}
 
Example 11
Project: elasticsearch_my   File: LoggingListenerTests.java   View Source Code Vote up 5 votes
public void testInvalidMethodTestLoggingAnnotation() throws Exception {
    final LoggingListener loggingListener = new LoggingListener();

    final Description suiteDescription = Description.createSuiteDescription(InvalidMethod.class);

    loggingListener.testRunStarted(suiteDescription);

    final Method method = InvalidMethod.class.getMethod("invalidMethod");
    final TestLogging annotation = method.getAnnotation(TestLogging.class);
    Description testDescription = Description.createTestDescription(InvalidMethod.class, "invalidMethod", annotation);
    final IllegalArgumentException e =
        expectThrows(IllegalArgumentException.class, () -> loggingListener.testStarted(testDescription));
    assertThat(e.getMessage(), equalTo("invalid test logging annotation [abc:INFO:WARN]"));
}
 
Example 12
Project: RetrofitCache   File: RetrofitCache.java   View Source Code Vote up 5 votes
public Mock getMockObject(String url){
    for (Map serviceMethodCache:mVector) {

        for (Object entry:serviceMethodCache.keySet()){
            Object o = serviceMethodCache.get(entry);
            try {

                if (mUrlAragsMap.containsKey(url)){
                    Object[] args = (Object[]) mUrlAragsMap.get(url);
                    String reqUrl =  buildRequestUrl(o,args);
                    if (reqUrl.equals(url)){
                        Method m = (Method) entry;
                        Mock mock =  m.getAnnotation(Mock.class);
                        if (mock!=null){
                            return  mock;
                        }
                        return null;
                    }
                }
            } catch (Exception e) {
                LogUtil.l(e);
            }
        }
    }

    return null;
}
 
Example 13
Project: bibliome-java-utils   File: CLIOParser.java   View Source Code Vote up 5 votes
private Map<String,Method> getOptions() {
	Map<String,Method> result = new TreeMap<String,Method>();
	Class<?> klass = getClass();
	Class<CLIOption> optionClass = CLIOption.class;
	for (Method meth : klass.getMethods()) {
		if (!meth.isAnnotationPresent(optionClass))
			continue;
		CLIOption annotation = meth.getAnnotation(optionClass);
		String option = annotation.value();
		if (result.containsKey(option))
			throw new RuntimeException("duplicate option " + option);
		result.put(option, meth);
	}
	return result;
}
 
Example 14
Project: uavstack   File: TypeUtils.java   View Source Code Vote up 5 votes
public static JSONField getSupperMethodAnnotation(Class<?> clazz, Method method) {
    for (Class<?> interfaceClass : clazz.getInterfaces()) {
        for (Method interfaceMethod : interfaceClass.getMethods()) {
            if (!interfaceMethod.getName().equals(method.getName())) {
                continue;
            }

            if (interfaceMethod.getParameterTypes().length != method.getParameterTypes().length) {
                continue;
            }

            boolean match = true;
            for (int i = 0; i < interfaceMethod.getParameterTypes().length; ++i) {
                if (!interfaceMethod.getParameterTypes()[i].equals(method.getParameterTypes()[i])) {
                    match = false;
                    break;
                }
            }

            if (!match) {
                continue;
            }

            JSONField annotation = interfaceMethod.getAnnotation(JSONField.class);
            if (annotation != null) {
                return annotation;
            }
        }
    }

    return null;
}
 
Example 15
Project: harshencastle   File: CommandHarshenCastleLoader.java   View Source Code Vote up 5 votes
public ArrayList<String> getAllAvalibleMethods()
{
	ArrayList<String> stringList = new ArrayList<>();
	for(Method method : HarshenCastleCommands.class.getMethods())
		if(method.getAnnotation(HarshenCommand.class) != null)
			stringList.add(method.getName());
	return stringList;
}
 
Example 16
Project: bubichain-sdk-java   File: HttpServiceAgent.java   View Source Code Vote up 4 votes
private ServiceActionContext resolveAction(ServiceEndpoint serviceEndpoint, Method mth, String servicePath){
    // 生成路径模板;
    HttpAction actionAnno = mth.getAnnotation(HttpAction.class);
    String actionPath = StringUtils.cleanPath(actionAnno.path());
    if (StringUtils.isEmpty(actionPath)) {
        actionPath = mth.getName();
    }
    RequestPathTemplate pathTemplate = new RequestPathTemplate(serviceEndpoint, servicePath, actionPath);

    // 校验请求你方法;
    if (actionAnno.method() == null) {
        throw new IllegalHttpServiceDefinitionException("The http method of action was not specified!");
    }

    RequestParamFilter reqParamFilter = createRequestParamFilter(actionAnno);
    ResponseConverter responseConverter = createResponseConverter(actionAnno, mth);

    // 获取参数定义;
    // 参数列表中, RequestBody 最多只能定义一个;
    RequestBodyResolver bodyResolver = null;
    Class<?>[] paramTypes = mth.getParameterTypes();
    Annotation[][] paramAnnos = mth.getParameterAnnotations();

    List<ArgDefEntry<RequestParam>> reqParamAnnos = new LinkedList<>();
    List<ArgDefEntry<RequestParamMap>> reqParamMapAnnos = new LinkedList<>();
    List<ArgDefEntry<PathParam>> pathParamAnnos = new LinkedList<>();
    for (int i = 0; i < paramTypes.length; i++) {
        RequestBody reqBodyAnno = findAnnotation(RequestBody.class, paramAnnos[i]);
        RequestParam reqParamAnno = findAnnotation(RequestParam.class, paramAnnos[i]);
        RequestParamMap reqParamsAnno = findAnnotation(RequestParamMap.class, paramAnnos[i]);
        PathParam pathParamAnno = findAnnotation(PathParam.class, paramAnnos[i]);
        if (hasConflictiveAnnotation(reqBodyAnno, reqParamAnno, reqParamsAnno, pathParamAnno)) {
            // 存在冲突的定义;
            throw new IllegalHttpServiceDefinitionException(
                    "The argument[" + i + "] of action has conflictive definition!");
        }
        if (bodyResolver != null && reqBodyAnno != null) {
            throw new IllegalHttpServiceDefinitionException("Define more than one request body for the action!");
        }
        if (reqBodyAnno != null) {
            bodyResolver = createBodyResolver(new ArgDefEntry<>(i, paramTypes[i], reqBodyAnno));
        }
        if (reqParamAnno != null) {
            reqParamAnnos.add(new ArgDefEntry<>(i, paramTypes[i], reqParamAnno));
        }
        if (reqParamsAnno != null) {
            reqParamMapAnnos.add(new ArgDefEntry<>(i, paramTypes[i], reqParamsAnno));
        }
        if (pathParamAnno != null) {
            pathParamAnnos.add(new ArgDefEntry<>(i, paramTypes[i], pathParamAnno));
        }
    }
    RequestParamResolver reqParamResolver = createRequestParamResolver(reqParamAnnos, reqParamMapAnnos);
    PathParamResolver pathParamResolver = createPathParamResolver(pathParamAnnos);
    if (bodyResolver == null) {
        bodyResolver = RequestBodyResolvers.NULL_BODY_RESOLVER;
    }

    // 获取声明的异常列表;
    Class<?>[] thrownExceptionTypes = mth.getExceptionTypes();

    ServiceActionContext actionContext = new ServiceActionContext(mth, actionAnno.method(), pathTemplate,
            pathParamResolver, reqParamFilter, reqParamResolver, bodyResolver, responseConverter,
            thrownExceptionTypes, actionAnno.resolveContentOnHttpError());
    return actionContext;
}
 
Example 17
Project: cerebro   File: LoggingAspect.java   View Source Code Vote up 4 votes
@Around(value = "@within(com.vsct.supervision.notification.log.Loggable) || @annotation(com.vsct.supervision.notification.log.Loggable)")
public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {


    final MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature();
    final Method method = signature.getMethod();
    final Class clazz = signature.getClass();
    final Loggable loggableMethod = method.getAnnotation(Loggable.class);

    final Loggable loggableClass = proceedingJoinPoint.getTarget().getClass().getAnnotation(Loggable.class);

    //get current log level
    final LogLevel logLevel = loggableMethod != null ? loggableMethod.value() : loggableClass.value();

    final String service = StringUtils.isNotBlank(loggableClass.service()) ? loggableClass.service() :  clazz.getName();
    final String methodName = StringUtils.isNotBlank(loggableClass.method()) ? loggableClass.method() :  method.getName();

    final String star = "**********";
    //before
    LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel, star + service + "." + methodName + "() start execution" + star);


    //show traceParams
    final  boolean showParams = loggableMethod != null ? loggableMethod.traceParams() : loggableClass.traceParams();
    if (showParams) {

        if (proceedingJoinPoint.getArgs() != null && proceedingJoinPoint.getArgs().length > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < proceedingJoinPoint.getArgs().length; i++) {
                sb.append(method.getParameterTypes()[i].getName() + ":" + proceedingJoinPoint.getArgs()[i]);
                if (i < proceedingJoinPoint.getArgs().length - 1)
                    sb.append(", ");
            }

            LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel, service + "." + methodName + "() args " + sb);
        }

    }

    final long startTime = System.currentTimeMillis();
    //start method execution
    final Object result = proceedingJoinPoint.proceed();

    final long endTime = System.currentTimeMillis();

    //show results
    if (result != null) {
        boolean showResults = loggableMethod != null ? loggableMethod.traceResult() : loggableClass.traceResult();
        if (showResults) {
            LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel, service + "." + methodName + "() Result : " + result);
        }
    }

    //show after
    LogWriter.write(proceedingJoinPoint.getTarget().getClass(), logLevel, star + service + "." + methodName + "() finished execution and takes "+(endTime-startTime)+" millis time to execute " + star);

    return result;
}
 
Example 18
Project: incubator-netbeans   File: NativeExecutionBaseTestSuite.java   View Source Code Vote up 4 votes
/**
 * Searches for 
 * - test methods
 * - constructors
 *
 * Test method is one that either is annotated with @Test
 * or its name starts with "test"
 *
 * NB: such method should be public and return type should be void
 * If it is not a warning is added to tests result
 *
 * @param testClass class to search methods in
 * @return an array of method names
 */
private TestClassData findTestData(Class<?> testClass) {

    TestClassData result = new TestClassData();

    for(Class<?> superClass = testClass; Test.class.isAssignableFrom(superClass);
    superClass = superClass.getSuperclass()) {
        for (Method method : superClass.getDeclaredMethods()) {
            if (!result.containsMethod(method.getName())) {
                ForAllEnvironments forAllEnvAnnotation = method.getAnnotation(ForAllEnvironments.class);
                
                if (method.getName().startsWith("test") 
                        || method.getAnnotation(org.junit.Test.class) != null
                        || forAllEnvAnnotation != null) {
                    if (!Modifier.isPublic(method.getModifiers())) {
                        addWarningTest("Method " + testClass.getName() + '.' + method.getName() + " should be public");
                    } else if (! method.getReturnType().equals(Void.TYPE)) {
                        addWarningTest("Method " + testClass.getName() + '.' + method.getName() + " should be void");
                    } else if (method.getParameterTypes().length > 0) {
                        addWarningTest("Method " + testClass.getName() + '.' + method.getName() + " should have no parameters");
                    } else {
                        if (method.getAnnotation(org.junit.Ignore.class) == null) {
                            If ifAnnotation = method.getAnnotation(If.class);
                            String condSection = (ifAnnotation == null) ? null : ifAnnotation.section();
                            String condKey = (ifAnnotation == null) ? null : ifAnnotation.key();
                            boolean condDefault = (ifAnnotation == null) ? false : ifAnnotation.defaultValue();
                            Ifdef ifdefAnnotation = method.getAnnotation(Ifdef.class);
                            String ifdefSection = (ifdefAnnotation == null) ? null : ifdefAnnotation.section();
                            String ifdefKey = (ifdefAnnotation == null) ? null : ifdefAnnotation.key();
                            if (forAllEnvAnnotation != null) {
                                String envSection = forAllEnvAnnotation.section();
                                if (envSection == null || envSection.length() == 0) {
                                    envSection = defaultSection;
                                }
                                if (envSection != null && envSection.length() > 0) {
                                    result.testMethods.add(new TestMethodData(method.getName(), envSection, condSection, condKey, condDefault, ifdefSection, ifdefKey));
                                } else {
                                    addWarningTest("@ForAllEnvironments annotation for method " + testClass.getName() + '.' + method.getName() + " does not specify section");
                                }
                            } else {
                                result.testMethods.add(new TestMethodData(method.getName(), null, condSection, condKey, condDefault, ifdefSection, ifdefKey));
                            }
                        }
                    }
                }
            }
        }
    }

    for (Constructor<?> ctor : testClass.getConstructors()) {
        Class<?>[] parameters = ctor.getParameterTypes();
        if (parameters.length == 1 && parameters[0].equals(String.class)) {
            result.ordinaryConstructor = ctor;
        }
        if (parameters.length == 2
                && parameters[0].equals(String.class)
                && parameters[1].equals(ExecutionEnvironment.class)) {
            result.forAllEnvConstructor = ctor;
        }
    }

    return result;
}
 
Example 19
Project: json-log-domain   File: LoggingFeature.java   View Source Code Vote up 4 votes
@Override
public void configure(final ResourceInfo resourceInfo,
                      final FeatureContext context) {
 
    final Method resourceMethod = resourceInfo.getResourceMethod();
    Path path = resourceMethod.getAnnotation(Path.class);
    if(path != null) {
    	Logged annotation = resourceMethod.getAnnotation(Logged.class);
    	if(annotation == null) {
    		annotation = resourceInfo.getResourceClass().getAnnotation(Logged.class);
    	}

    	if(annotation != null) {
     	Class<? extends DomainMarker> value = annotation.value();
     	
     	DomainMarker marker;
     	try {
	marker = value.newInstance();
} catch (Exception e) {
	throw new RuntimeException(e);
}
     	
     	List<String> keys = new ArrayList<>();
     	List<Integer> indexes = new ArrayList<>();
     	
     	String paths[] = path.value().split("/"); // assume /a/b/c
     	for(int i = 0; i < paths.length; i++) {
     		// Now create matcher object.
             Matcher m = pattern.matcher(paths[i]);
          if(m.matches()) {
          	String key = m.group("key");
          	if(marker.definesKey(key)) {
           	keys.add(key);
           	indexes.add(i - 1);
          	}
          }
     	}
     	
     	if(!keys.isEmpty()) {
	        	int[] indexArray = new int[indexes.size()];
	        	for(int i = 0; i < indexArray.length; i++) {
	        		indexArray[i] = indexes.get(i);
	        	}
	        	
	        	context.register(new LogFilter(keys.toArray(new String[keys.size()]), indexArray, value));
     	}
    	}
    }
    
}
 
Example 20
Project: app-ms   File: DefaultAssertionRequiredPredicate.java   View Source Code Vote up 3 votes
/**
 * <p>
 * The key logic for the test is as follows:
 * </p>
 * <p>
 * Let:
 * </p>
 * <table>
 * <tr>
 * <td>a =</td>
 * <td>resourceMethodHasRolesAllowed</td>
 * </tr>
 * <tr>
 * <td>b =</td>
 * <td>resourceClassHasRolesAllowed</td>
 * </tr>
 * <tr>
 * <td>c =</td>
 * <td>resourceMethodHasPermitAll</td>
 * </tr>
 * <tr>
 * <td>d =</td>
 * <td>resourceClassHasPermitAll</td>
 * </tr>
 * </table>
 * <p>
 * The rules that need to be applied translate to:
 * </p>
 *
 * <pre>
 * = a || ( b && !c ) || ( !a && !b && !c && !d )
 * = (a || b || !d) && ( a || !c )
 * </pre>
 *
 * @param resourceInfo
 *            resource info
 * @return <code>true</code> if the resource is protected
 */
@Override
public boolean test(final ResourceInfo resourceInfo) {

    final Method resourceMethod = resourceInfo.getResourceMethod();
    final Class<?> resourceClass = resourceInfo.getResourceClass();

    final boolean resourceMethodHasRolesAllowed = resourceMethod.getAnnotation(RolesAllowed.class) != null;
    final boolean resourceClassHasRolesAllowed = resourceClass.getAnnotation(RolesAllowed.class) != null;

    final boolean resourceMethodHasPermitAll = resourceMethod.getAnnotation(PermitAll.class) != null;
    final boolean resourceClassHasPermitAll = resourceClass.getAnnotation(PermitAll.class) != null;

    if (LOG.isDebugEnabled()) {
        LOG.debug("resourceMethod={} PermitAll={} RolesAllowed={}", resourceMethod, resourceMethodHasPermitAll, resourceMethodHasRolesAllowed);
        LOG.debug("resourceClass={} PermitAll={} RolesAllowed={}", resourceClass, resourceClassHasPermitAll, resourceClassHasRolesAllowed);
    }

    if (resourceMethodHasRolesAllowed && resourceMethodHasPermitAll) {
        throw new IllegalArgumentException("The resource method " + resourceMethod + " may not have both @RolesAllowed and @PermitAll annotations.");
    } else if (resourceClassHasRolesAllowed && resourceClassHasPermitAll) {
        throw new IllegalArgumentException("The resource class " + resourceClass + " may not have both @RolesAllowed and @PermitAll annotations.");
    } else {
        return (resourceMethodHasRolesAllowed || resourceClassHasRolesAllowed || !resourceClassHasPermitAll) && (resourceMethodHasRolesAllowed || !resourceMethodHasPermitAll);
    }

}