KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Modifier JavaDoc;
25
26 import org.jboss.reflect.spi.AnnotationValue;
27 import org.jboss.reflect.spi.ClassInfo;
28 import org.jboss.reflect.spi.FieldInfo;
29 import org.jboss.reflect.spi.TypeInfo;
30 import org.jboss.util.JBossStringBuilder;
31 import org.jboss.util.NotImplementedException;
32
33 /**
34  * A field info
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 FieldInfoImpl extends AnnotationHolder implements FieldInfo
40 {
41    /** serialVersionUID */
42    private static final long serialVersionUID = 3546084661584539959L;
43
44    /** The field name */
45    protected String JavaDoc name;
46    
47    /** The field type */
48    protected TypeInfo type;
49    
50    /** The field modifier */
51    protected int modifiers;
52    
53    /** The declaring class */
54    protected ClassInfo declaringClass;
55    
56    /** The hash code */
57    protected int hash = -1;
58
59    /**
60     * Create a new field info
61     */

62    public FieldInfoImpl()
63    {
64    }
65
66    /**
67     * Create a new FieldInfo.
68     *
69     * @param annotations the annotations
70     * @param name the name
71     * @param type the field type
72     * @param modifiers the field modifiers
73     * @param declaring the declaring class
74     */

75    public FieldInfoImpl(AnnotationValue[] annotations, String JavaDoc name, TypeInfo type, int modifiers, ClassInfo declaring)
76    {
77       super(annotations);
78       this.name = name;
79       this.type = type;
80       this.modifiers = modifiers;
81       this.declaringClass = declaring;
82       calculateHash();
83    }
84
85    public String JavaDoc getName()
86    {
87       return name;
88    }
89
90    public TypeInfo getType()
91    {
92       return type;
93    }
94
95    public ClassInfo getDeclaringClass()
96    {
97       return declaringClass;
98    }
99    
100    public int getModifiers()
101    {
102       return modifiers;
103    }
104    
105    public boolean isStatic()
106    {
107       return Modifier.isStatic(modifiers);
108    }
109    
110    public boolean isPublic()
111    {
112       return Modifier.isPublic(modifiers);
113    }
114    
115    public Object JavaDoc get(Object JavaDoc target) throws Throwable JavaDoc
116    {
117       throw new NotImplementedException("get");
118    }
119
120    public Object JavaDoc set(Object JavaDoc target, Object JavaDoc value) throws Throwable JavaDoc
121    {
122       throw new NotImplementedException("set");
123    }
124
125    protected void toString(JBossStringBuilder buffer)
126    {
127       buffer.append("name=").append(name);
128    }
129
130    public boolean equals(Object JavaDoc obj)
131    {
132       if (this == obj) return true;
133       if (obj == null || obj instanceof FieldInfo == false)
134          return false;
135
136       final FieldInfo other = (FieldInfo) obj;
137
138       if (name.equals(other.getName()) == false)
139          return false;
140       return declaringClass.equals(other.getDeclaringClass());
141    }
142
143    public int hashCode()
144    {
145       return hash;
146    }
147
148    /**
149     * Calculate the hash code
150     */

151    protected void calculateHash()
152    {
153       hash = name.hashCode();
154    }
155 }
156
Popular Tags