KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.Serializable JavaDoc;
25
26 import org.jboss.reflect.spi.AnnotationAttribute;
27 import org.jboss.reflect.spi.TypeInfo;
28 import org.jboss.reflect.spi.Value;
29 import org.jboss.util.JBossObject;
30
31 /**
32  * An annotation attribute
33  *
34  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
35  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
36  */

37 public class AnnotationAttributeImpl extends JBossObject implements AnnotationAttribute, Serializable JavaDoc
38 {
39    /** serialVersionUID */
40    private static final long serialVersionUID = 3546645408219542832L;
41
42    /** The name */
43    protected String JavaDoc name;
44    
45    /** The attribute type */
46    protected TypeInfo type;
47    
48    /** The default value */
49    protected Value defaultValue;
50    
51    /** The hash code */
52    protected int hash = -1;
53
54    /**
55     * Create a new annotation attribute
56     */

57    public AnnotationAttributeImpl()
58    {
59    }
60
61    /**
62     * Create a new AnnotationAttribute.
63     *
64     * @param name the annotation name
65     * @param type the attribute type
66     * @param defaultValue the default value
67     */

68    public AnnotationAttributeImpl(String JavaDoc name, TypeInfo type, Value defaultValue)
69    {
70       this.name = name;
71       this.type = type;
72       this.defaultValue = defaultValue;
73       calcHashCode();
74    }
75
76    public String JavaDoc getName()
77    {
78       return name;
79    }
80
81    public TypeInfo getType()
82    {
83       return type;
84    }
85
86    public Value getDefaultValue()
87    {
88       return defaultValue;
89    }
90
91    public boolean equals(Object JavaDoc obj)
92    {
93       if (this == obj)
94          return true;
95       if (obj == null || obj instanceof AnnotationAttributeImpl == false)
96          return false;
97
98       final AnnotationAttributeImpl other = (AnnotationAttributeImpl) obj;
99
100       if (!name.equals(other.name))
101          return false;
102       if (!type.equals(other.type))
103          return false;
104
105       return true;
106    }
107
108    public int hashCode()
109    {
110       return hash;
111    }
112
113    /**
114     * Calculate the hash code
115     */

116    protected void calcHashCode()
117    {
118       int result;
119       result = name.hashCode();
120       result = 29 * result + type.hashCode();
121       hash = result;
122    }
123 }
124
Popular Tags