KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > reflect > plugins > AnnotationInfoImpl


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.reflect.plugins;
23
24 import org.jboss.reflect.spi.AnnotationAttribute;
25 import org.jboss.reflect.spi.AnnotationInfo;
26
27 import java.util.HashMap JavaDoc;
28
29 /**
30  * Annotation Info
31  *
32  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
33  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
34  */

35 public class AnnotationInfoImpl extends InterfaceInfoImpl implements AnnotationInfo
36 {
37    /** serialVersionUID */
38    private static final long serialVersionUID = 3546645408219542832L;
39    
40    /** The attributes */
41    protected AnnotationAttribute[] attributes;
42    
43    /** Attribute Map<String, AnnotationAttribute> */
44    protected HashMap JavaDoc<String JavaDoc, AnnotationAttribute> attributeMap;
45
46    /**
47     * Create a new AnnotationInfo.
48     */

49    public AnnotationInfoImpl()
50    {
51    }
52
53    /**
54     * Create a new AnnotationInfo.
55     *
56     * @param name the name
57     * @param modifiers the modifiers
58     */

59    public AnnotationInfoImpl(String JavaDoc name, int modifiers)
60    {
61       super(name, modifiers, null);
62    }
63
64    /**
65     * Set the attributes
66     *
67     * @param attributes the attributes
68     */

69    public void setAttributes(AnnotationAttributeImpl[] attributes)
70    {
71       this.attributes = attributes;
72       if (attributes != null && attributes.length > 0)
73       {
74          this.attributes = attributes;
75          attributeMap = new HashMap JavaDoc<String JavaDoc, AnnotationAttribute>();
76          for (int i = 0; i < attributes.length; i++)
77          {
78             attributeMap.put(attributes[i].getName(), attributes[i]);
79          }
80       }
81    }
82
83    public String JavaDoc getName()
84    {
85       return name;
86    }
87
88    public int getModifiers()
89    {
90       return modifiers;
91    }
92
93    public AnnotationAttribute[] getAttributes()
94    {
95       return attributes;
96    }
97
98    public AnnotationAttribute getAttribute(String JavaDoc name)
99    {
100       if (attributeMap == null)
101          return null;
102       return attributeMap.get(name);
103    }
104
105    public boolean equals(Object JavaDoc o)
106    {
107       if (this == o) return true;
108       if (!(o instanceof AnnotationInfoImpl)) return false;
109
110       final AnnotationInfoImpl annotationInfo = (AnnotationInfoImpl) o;
111
112       if (!name.equals(annotationInfo.name)) return false;
113
114       return true;
115    }
116
117    public int hashCode()
118    {
119       return name.hashCode();
120    }
121 }
122
Popular Tags