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; 014 015import java.lang.annotation.*; 016import java.lang.reflect.*; 017 018/** 019 * Parent interface for all class/method language-specific metadata providers. 020 */ 021public interface MetaProvider { 022 023 /** 024 * Default metadata provider. 025 */ 026 public static MetaProvider DEFAULT = new MetaProvider() { 027 028 @Override /* MetaProvider */ 029 public <A extends Annotation> A getAnnotation(Class<A> a, Class<?> c) { 030 return a == null || c == null ? null : c.getAnnotation(a); 031 } 032 033 @Override /* MetaProvider */ 034 public <A extends Annotation> A getDeclaredAnnotation(Class<A> a, Class<?> c) { 035 return a == null || c == null ? null : c.getDeclaredAnnotation(a); 036 } 037 038 @Override /* MetaProvider */ 039 public <A extends Annotation> A getAnnotation(Class<A> a, Method m) { 040 return a == null || m == null ? null : m.getAnnotation(a); 041 } 042 043 @Override /* MetaProvider */ 044 public <A extends Annotation> A getAnnotation(Class<A> a, Field f) { 045 return a == null || f == null ? null : f.getAnnotation(a); 046 } 047 048 @Override /* MetaProvider */ 049 public <A extends Annotation> A getAnnotation(Class<A> a, Constructor<?> c) { 050 return a == null || c == null ? null : c.getAnnotation(a); 051 } 052 }; 053 054 /** 055 * Finds the specified annotation on the specified class. 056 * 057 * @param <A> The annotation type to find. 058 * @param a The annotation type to find. 059 * @param c The class to search on. 060 * @return The annotation, or <jk>null</jk> if not found. 061 */ 062 <A extends Annotation> A getAnnotation(Class<A> a, Class<?> c); 063 064 /** 065 * Finds the specified declared annotation on the specified class. 066 * 067 * @param <A> The annotation type to find. 068 * @param a The annotation type to find. 069 * @param c The class to search on. 070 * @return The annotation, or <jk>null</jk> if not found. 071 */ 072 <A extends Annotation> A getDeclaredAnnotation(Class<A> a, Class<?> c); 073 074 /** 075 * Finds the specified annotation on the specified method. 076 * 077 * @param <A> The annotation type to find. 078 * @param a The annotation type to find. 079 * @param m The method to search on. 080 * @return The annotation, or <jk>null</jk> if not found. 081 */ 082 <A extends Annotation> A getAnnotation(Class<A> a, Method m); 083 084 /** 085 * Finds the specified annotation on the specified field. 086 * 087 * @param <A> The annotation type to find. 088 * @param a The annotation type to find. 089 * @param f The field to search on. 090 * @return The annotation, or <jk>null</jk> if not found. 091 */ 092 <A extends Annotation> A getAnnotation(Class<A> a, Field f); 093 094 /** 095 * Finds the specified annotation on the specified constructor. 096 * 097 * @param <A> The annotation type to find. 098 * @param a The annotation type to find. 099 * @param c The constructor to search on. 100 * @return The annotation, or <jk>null</jk> if not found. 101 */ 102 <A extends Annotation> A getAnnotation(Class<A> a, Constructor<?> c); 103}