001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JField.java 2059 2007-11-22 17:22:33Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.deployment.annotations;
025:
026: /**
027: * This class defines a Field object. It is not based on reflection.
028: * @author Florent Benoit
029: */
030: public class JField {
031:
032: /**
033: * Name of the field.
034: */
035: private String name = null;
036:
037: /**
038: * Access mode (see {@link org.ow2.easybeans.asm.Opcodes}).
039: */
040: private int access;
041:
042: /**
043: * Field's descriptor.
044: */
045: private String descriptor = null;
046:
047: /**
048: * Field's signature.
049: */
050: private String signature;
051:
052: /**
053: * Value of the field.
054: */
055: private Object value;
056:
057: /**
058: * Constructor. *
059: * @param access the field's access flags (see
060: * {@link org.ow2.easybeans.asm.Opcodes}). This parameter also indicates
061: * if the field is synthetic and/or deprecated.
062: * @param name the field's name.
063: * @param descriptor the field's descriptor (see
064: * {@link org.ow2.easybeans.asm.Type}).
065: * @param signature the field's signature. May be <tt>null</tt> if the
066: * field's type does not use generic types.
067: * @param value the field's initial value. This parameter, which may be
068: * <tt>null</tt> if the field does not have an initial value, must
069: * be an {@link Integer}, a {@link Float}, a {@link Long}, a
070: * {@link Double} or a {@link String} (for <tt>int</tt>,
071: * <tt>float</tt>, <tt>long</tt> or <tt>String</tt> fields
072: * respectively). <i>This parameter is only used for static fields</i>.
073: * Its value is ignored for non static fields, which must be
074: * initialized through bytecode instructions in constructors or
075: * methods.
076: */
077: public JField(final int access, final String name,
078: final String descriptor, final String signature,
079: final Object value) {
080: this .access = access;
081: this .name = name;
082: this .descriptor = descriptor;
083: this .signature = signature;
084: this .value = value;
085: }
086:
087: /**
088: * Indicates whether some other object is "equal to" this one.
089: * @param obj object to compare
090: * @return true if given object is equals
091: */
092: @Override
093: public boolean equals(final Object obj) {
094: if (obj != null && obj instanceof JField) {
095: JField other = (JField) obj;
096:
097: // same name
098: if (!this .name.equals(other.name)) {
099: return false;
100: }
101:
102: // same descriptor
103: if ((this .descriptor != null)
104: && (!this .descriptor.equals(other.descriptor))) {
105: return false;
106: }
107:
108: // same signature
109: if ((this .signature != null)
110: && (!this .signature.equals(other.signature))) {
111: return false;
112: }
113:
114: // if all tests succeed, return true
115: return true;
116: }
117: return false;
118: }
119:
120: /**
121: * @return a hash code value for the object.
122: */
123: @Override
124: public int hashCode() {
125: return name.hashCode();
126: }
127:
128: /**
129: * @return field's descriptor.
130: */
131: public String getDescriptor() {
132: return descriptor;
133: }
134:
135: /**
136: * @return field's value.
137: */
138: public Object getValue() {
139: return value;
140: }
141:
142: /**
143: * @return method name
144: */
145: public String getName() {
146: return name;
147: }
148:
149: /**
150: * @return method signature
151: */
152: public String getSignature() {
153: return signature;
154: }
155:
156: /**
157: * @return string representation
158: */
159: @Override
160: public String toString() {
161: StringBuilder sb = new StringBuilder();
162: // classname
163: sb.append(this .getClass().getName().substring(
164: this .getClass().getPackage().getName().length() + 1));
165:
166: // name
167: sb.append("[name=");
168: sb.append(name);
169:
170: // access
171: sb.append(", access=");
172: sb.append(access);
173:
174: // descriptor
175: if (descriptor != null) {
176: sb.append(", descriptor=");
177: sb.append(descriptor);
178: }
179:
180: // signature
181: if (signature != null) {
182: sb.append(", signature=");
183: sb.append(signature);
184: }
185:
186: // exceptions
187: if (value != null) {
188: sb.append(", value=");
189: sb.append(value);
190: }
191: sb.append("]");
192: return sb.toString();
193: }
194:
195: /**
196: * @return the field's access flags
197: */
198: public int getAccess() {
199: return access;
200: }
201: }
|