KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > deployment > annotations > JField


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JField.java 47 2006-02-28 10:42:29Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.deployment.annotations;
27
28 /**
29  * This class defines a Field object. It is not based on reflection.
30  * @author Florent Benoit
31  */

32 public class JField {
33
34     /**
35      * Name of the field.
36      */

37     private String JavaDoc name = null;
38
39     /**
40      * Access mode (see {@link org.objectweb.asm.Opcodes}).
41      */

42     private int access;
43
44     /**
45      * Field's descriptor.
46      */

47     private String JavaDoc descriptor = null;
48
49     /**
50      * Field's signature.
51      */

52     private String JavaDoc signature;
53
54     /**
55      * Value of the field.
56      */

57     private Object JavaDoc value;
58
59     /**
60      * Constructor. *
61      * @param access the field's access flags (see
62      * {@link org.objectweb.asm.Opcodes}). This parameter also indicates
63      * if the field is synthetic and/or deprecated.
64      * @param name the field's name.
65      * @param descriptor the field's descriptor (see
66      * {@link org.objectweb.asm.Type}).
67      * @param signature the field's signature. May be <tt>null</tt> if the
68      * field's type does not use generic types.
69      * @param value the field's initial value. This parameter, which may be
70      * <tt>null</tt> if the field does not have an initial value, must
71      * be an {@link Integer}, a {@link Float}, a {@link Long}, a
72      * {@link Double} or a {@link String} (for <tt>int</tt>,
73      * <tt>float</tt>, <tt>long</tt> or <tt>String</tt> fields
74      * respectively). <i>This parameter is only used for static fields</i>.
75      * Its value is ignored for non static fields, which must be
76      * initialized through bytecode instructions in constructors or
77      * methods.
78      */

79     public JField(final int access, final String JavaDoc name, final String JavaDoc descriptor, final String JavaDoc signature,
80             final Object JavaDoc value) {
81         this.access = access;
82         this.name = name;
83         this.descriptor = descriptor;
84         this.signature = signature;
85         this.value = value;
86     }
87
88     /**
89      * Indicates whether some other object is "equal to" this one.
90      * @param obj object to compare
91      * @return true if given object is equals
92      */

93     @Override JavaDoc
94     public boolean equals(final Object JavaDoc obj) {
95         if (obj != null && obj instanceof JField) {
96             JField other = (JField) obj;
97
98             // same name
99
if (!this.name.equals(other.name)) {
100                 return false;
101             }
102
103             // same descriptor
104
if ((this.descriptor != null) && (!this.descriptor.equals(other.descriptor))) {
105                 return false;
106             }
107
108             // same signature
109
if ((this.signature != null) && (!this.signature.equals(other.signature))) {
110                 return false;
111             }
112
113             // if all tests succeed, return true
114
return true;
115         }
116         return false;
117     }
118
119     /**
120      * @return a hash code value for the object.
121      */

122     @Override JavaDoc
123     public int hashCode() {
124         return name.hashCode();
125     }
126
127     /**
128      * @return field's descriptor.
129      */

130     public String JavaDoc getDescriptor() {
131         return descriptor;
132     }
133
134     /**
135      * @return field's value.
136      */

137     public Object JavaDoc getValue() {
138         return value;
139     }
140
141     /**
142      * @return method name
143      */

144     public String JavaDoc getName() {
145         return name;
146     }
147
148     /**
149      * @return method signature
150      */

151     public String JavaDoc getSignature() {
152         return signature;
153     }
154
155     /**
156      * @return string representation
157      */

158     @Override JavaDoc
159     public String JavaDoc toString() {
160         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
161         // classname
162
sb.append(this.getClass().getName().substring(this.getClass().getPackage().getName().length() + 1));
163
164         // name
165
sb.append("[name=");
166         sb.append(name);
167
168         // access
169
sb.append(", access=");
170         sb.append(access);
171
172         // descriptor
173
if (descriptor != null) {
174             sb.append(", descriptor=");
175             sb.append(descriptor);
176         }
177
178         // signature
179
if (signature != null) {
180             sb.append(", signature=");
181             sb.append(signature);
182         }
183
184         // exceptions
185
if (value != null) {
186             sb.append(", value=");
187             sb.append(value);
188         }
189         sb.append("]");
190         return sb.toString();
191     }
192
193     /**
194      * @return the field's access flags
195      */

196     public int getAccess() {
197         return access;
198     }
199 }
200
Popular Tags