KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > bytecode > JAnnotation


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.bytecode;
31
32 import java.util.Map JavaDoc;
33
34 /**
35  * Represents an introspected annotation.
36  */

37 abstract public class JAnnotation {
38   /**
39    * Returns the class name.
40    */

41   abstract public String JavaDoc getType();
42
43   /**
44    * Returns the annotation values.
45    */

46   abstract public Map JavaDoc<String JavaDoc,Object JavaDoc> getValueMap();
47
48   /**
49    * Returns the annotation value.
50    */

51   public Object JavaDoc get(String JavaDoc name)
52   {
53     return getValueMap().get(name);
54   }
55
56   /**
57    * Returns the annotation value.
58    */

59   public String JavaDoc getString(String JavaDoc name)
60   {
61     return (String JavaDoc) get(name);
62   }
63
64   /**
65    * Returns the annotation value.
66    */

67   public JClass getClass(String JavaDoc name)
68   {
69     return (JClass) get(name);
70   }
71
72   /**
73    * Returns the annotation value.
74    */

75   public int getInt(String JavaDoc name)
76   {
77     Integer JavaDoc value = (Integer JavaDoc) get(name);
78
79     if (value != null)
80       return value.intValue();
81     else
82       return 0;
83   }
84
85   /**
86    * Returns the annotation value.
87    */

88   public boolean getBoolean(String JavaDoc name)
89   {
90     return Boolean.TRUE.equals(get(name));
91   }
92
93   /**
94    * Returns the annotation value.
95    */

96   public JAnnotation getAnnotation(String JavaDoc name)
97   {
98     return (JAnnotation) get(name);
99   }
100   
101   /**
102    * Returns true if equals.
103    */

104   public boolean equals(Object JavaDoc o)
105   {
106     if (o == this)
107       return true;
108     else if (o == null || getClass() != o.getClass())
109       return false;
110
111     JAnnotation jAnnotation = (JAnnotation) o;
112
113     // note that the equality test doesn't include the class loader
114
return getType().equals(jAnnotation.getType());
115   }
116
117   public String JavaDoc toString()
118   {
119     return "JAnnotation[" + getType() + "]";
120   }
121 }
122
Popular Tags