KickJava   Java API By Example, From Geeks To Geeks.

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


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

39 public class AnnotationValueImpl extends JBossObject implements AnnotationValue, Serializable JavaDoc
40 {
41    /** serialVersionUID */
42    private static final long serialVersionUID = 3257290210164289843L;
43
44    /** The annotation type */
45    protected AnnotationInfo annotationType;
46    
47    /** The attribute values */
48    protected HashMap JavaDoc attributeValues;
49    
50    /** The hash code */
51    protected int hash = -1;
52
53    /**
54     * Create a new Annotation value
55     */

56    public AnnotationValueImpl()
57    {
58    }
59
60    /**
61     * Create a new Annotation value
62     *
63     * @param annotationType the annotation info
64     * @param attributeValues the attribute values
65     */

66    public AnnotationValueImpl(AnnotationInfo annotationType, HashMap JavaDoc attributeValues)
67    {
68       this.annotationType = annotationType;
69       this.attributeValues = attributeValues;
70       calculateHash();
71    }
72
73    public AnnotationInfo getAnnotationType()
74    {
75       return annotationType;
76    }
77    
78    public Value getValue(String JavaDoc attributeName)
79    {
80       return (Value) attributeValues.get(attributeName);
81    }
82
83    public TypeInfo getType()
84    {
85       return annotationType;
86    }
87
88    public boolean equals(Object JavaDoc o)
89    {
90       if (this == o) return true;
91       if (!(o instanceof AnnotationValueImpl)) return false;
92
93       final AnnotationValueImpl annotationValue = (AnnotationValueImpl) o;
94
95       if (!annotationType.equals(annotationValue.annotationType)) return false;
96       if (!attributeValues.equals(annotationValue.attributeValues)) return false;
97
98       return true;
99    }
100
101    public int hashCode()
102    {
103       return hash;
104    }
105
106    /**
107     * Calculate the hashcode
108     */

109    protected void calculateHash()
110    {
111       int result;
112       result = (annotationType != null) ? annotationType.hashCode() : 0;
113       result = 29 * result + attributeValues.hashCode();
114       hash = result;
115    }
116 }
117
Popular Tags