001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@objectweb.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 47 2006-02-28 10:42:29Z benoitf $
023: * --------------------------------------------------------------------------
024: */package com.bm.ejb3metadata.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.ejb3unit.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.ejb3unit.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.ejb3unit.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: * a hash code value for the object.
122: * @return a hash code value for the object.
123: */
124: @Override
125: public int hashCode() {
126: return name.hashCode();
127: }
128:
129: /**
130: * field's descriptor.
131: * @return field's descriptor.
132: */
133: public String getDescriptor() {
134: return descriptor;
135: }
136:
137: /**
138: * field's value.
139: * @return field's value.
140: */
141: public Object getValue() {
142: return value;
143: }
144:
145: /**
146: * method name.
147: * @return method name
148: */
149: public String getName() {
150: return name;
151: }
152:
153: /**
154: * method signature.
155: * @return method signature
156: */
157: public String getSignature() {
158: return signature;
159: }
160:
161: /**
162: * {@inheritDoc}
163: */
164: @Override
165: public String toString() {
166: StringBuilder sb = new StringBuilder();
167: // classname
168: sb.append(this .getClass().getName().substring(
169: this .getClass().getPackage().getName().length() + 1));
170:
171: // name
172: sb.append("[name=");
173: sb.append(name);
174:
175: // access
176: sb.append(", access=");
177: sb.append(access);
178:
179: // descriptor
180: if (descriptor != null) {
181: sb.append(", descriptor=");
182: sb.append(descriptor);
183: }
184:
185: // signature
186: if (signature != null) {
187: sb.append(", signature=");
188: sb.append(signature);
189: }
190:
191: // exceptions
192: if (value != null) {
193: sb.append(", value=");
194: sb.append(value);
195: }
196: sb.append("]");
197: return sb.toString();
198: }
199:
200: /**
201: * the field's access flags.
202: * @return the field's access flags
203: */
204: public int getAccess() {
205: return access;
206: }
207: }
|