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