1 /*
2 * Copyright 2012 The Kuali Foundation
3 *
4 * Licensed under the the Educational Community License, Version 1.0
5 * (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl1.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.student.common.spring;
17
18 import java.lang.annotation.Annotation;
19 import java.util.HashSet;
20 import java.util.Set;
21
22 /**
23 * @author Kuali Student Team
24 *
25 */
26 public final class AnnotationUtils {
27
28 private AnnotationUtils() {
29 }
30
31
32 /**
33 * Extract the set of java interfaces from the class hierarchy of the bean provided that match the annotation provided.
34 *
35 * @param bean
36 * @param annotation
37 * @return the set of java interfaces that match the annotation.
38 */
39 public static Set<Class<?>> extractInterfaceContainingAnnotation(Object bean, Class <? extends Annotation> annotation) {
40
41 Class<? extends Object> beanClass = bean.getClass();
42
43 Class<?>[] interfaces = beanClass.getInterfaces();
44
45 Set<Class<?>>matchingInterfaces = new HashSet<Class<?>>();
46
47 for (Class<?> candidateInterface : interfaces) {
48
49 Annotation ws = candidateInterface.getAnnotation(annotation);
50
51 if (ws != null)
52 matchingInterfaces.add(candidateInterface);
53 }
54
55 return matchingInterfaces;
56 }
57
58 }