001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.annotation; 014 015import java.lang.annotation.*; 016 017import org.apache.juneau.*; 018import org.apache.juneau.reflect.*; 019 020/** 021 * Defines an invalid usage of an annotation. 022 * 023 */ 024public class InvalidAnnotationException extends BasicRuntimeException { 025 026 private static final long serialVersionUID = 1L; 027 028 /** 029 * Constructor. 030 * 031 * @param message Message. 032 * @param args Arguments. 033 */ 034 public InvalidAnnotationException(String message, Object...args) { 035 super(message, args); 036 } 037 038 /** 039 * Throws an {@link InvalidAnnotationException} if the specified method contains any of the specified annotations. 040 * 041 * @param m The method to check. 042 * @param a The annotations to check for. 043 * @throws InvalidAnnotationException Annotation was used in an invalid location. 044 */ 045 @SafeVarargs 046 public static void assertNoInvalidAnnotations(MethodInfo m, Class<? extends Annotation>...a) throws InvalidAnnotationException { 047 Annotation aa = m.getAnyLastAnnotation(a); 048 if (aa != null) 049 throw new InvalidAnnotationException("@{0} annotation cannot be used in a @{1} bean. Method=''{2}''", aa.getClass().getSimpleName(), m.getDeclaringClass().getSimpleName(), m); 050 } 051}