View Javadoc

1   /*
2    * $Id: AnnotationMetaData.java 17838 2010-07-03 10:27:17Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.util.annotation;
11  
12  import java.lang.annotation.Annotation;
13  import java.lang.annotation.ElementType;
14  import java.lang.reflect.Member;
15  
16  /**
17   * A data class that associates context information about an annotation. This class allows for associated annotation data
18   * to be passed between methods.
19   */
20  public class AnnotationMetaData
21  {
22      private ElementType type;
23  
24      private Member member;
25  
26      private Class clazz;
27  
28      private Annotation annotation;
29  
30      public AnnotationMetaData(Class clazz, Member member, ElementType type, Annotation annotation)
31      {
32          this.type = type;
33          this.clazz = clazz;
34          this.member = member;
35          this.annotation = annotation;
36      }
37  
38      public ElementType getType()
39      {
40          return type;
41      }
42  
43      public String getElementName()
44      {
45          if (member == null)
46          {
47              return clazz.getName();
48          }
49          return member.getName();
50      }
51  
52      public Annotation getAnnotation()
53      {
54          return annotation;
55      }
56  
57      public Member getMember()
58      {
59          return member;
60      }
61  
62      public Class getClazz()
63      {
64          return clazz;
65      }
66  
67      @Override
68      public String toString()
69      {
70          return "AnnotationMetaData{" +
71                  "type=" + type +
72                  ", member=" + member +
73                  ", clazz=" + clazz +
74                  ", annotation=" + annotation +
75                  '}';
76      }
77  
78      @Override
79      public boolean equals(Object o)
80      {
81          if (this == o)
82          {
83              return true;
84          }
85          if (o == null || getClass() != o.getClass())
86          {
87              return false;
88          }
89  
90          AnnotationMetaData that = (AnnotationMetaData) o;
91  
92          if (annotation != null ? !annotation.equals(that.annotation) : that.annotation != null)
93          {
94              return false;
95          }
96          if (clazz != null ? !clazz.equals(that.clazz) : that.clazz != null)
97          {
98              return false;
99          }
100         if (member != null ? !member.equals(that.member) : that.member != null)
101         {
102             return false;
103         }
104         if (type != that.type)
105         {
106             return false;
107         }
108 
109         return true;
110     }
111 
112     @Override
113     public int hashCode()
114     {
115         int result = type != null ? type.hashCode() : 0;
116         result = 31 * result + (member != null ? member.hashCode() : 0);
117         result = 31 * result + (clazz != null ? clazz.hashCode() : 0);
118         result = 31 * result + (annotation != null ? annotation.hashCode() : 0);
119         return result;
120     }
121 }