KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > classfile > ClassField


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.classfile;
26
27 import java.io.*;
28
29 /**
30  * ClassField models the static and non-static fields of a class within
31  * a class file.
32  */

33
34 final public class ClassField extends ClassMember {
35   /* access flag bit mask - see VMConstants */
36   private int accessFlags;
37
38   /* The name of the field */
39   private ConstUtf8 fieldName;
40
41   /* The type signature of the field */
42   private ConstUtf8 fieldSignature;
43
44   /* The attributes associated with the field */
45   private AttributeVector fieldAttributes;
46   
47
48   /* public accessors */
49
50   /**
51    * Is the field transient?
52    */

53   public boolean isTransient() {
54     return (accessFlags & ACCTransient) != 0;
55   }
56
57   /**
58    * Return the access flags for the field - see VMConstants
59    */

60   public int access() {
61     return accessFlags;
62   }
63
64   /**
65    * Update the access flags for the field - see VMConstants
66    */

67   public void setAccess(int newFlags) {
68     accessFlags = newFlags;
69   }
70
71   /**
72    * Return the name of the field
73    */

74   public ConstUtf8 name() {
75     return fieldName;
76   }
77
78   /**
79    * Change the name of the field
80    */

81   public void changeName(ConstUtf8 name) {
82     fieldName = name;
83   }
84
85   /**
86    * Return the type signature of the field
87    */

88   public ConstUtf8 signature() {
89     return fieldSignature;
90   }
91
92   /**
93    * Change the type signature of the field
94    */

95   public void changeSignature(ConstUtf8 newSig) {
96     fieldSignature = newSig;
97   }
98
99   /**
100    * Return the attributes associated with the field
101    */

102   public AttributeVector attributes() {
103     return fieldAttributes;
104   }
105
106   /**
107    * Construct a class field object
108    */

109   public ClassField(int accFlags, ConstUtf8 name, ConstUtf8 sig,
110                     AttributeVector field_attrs) {
111     accessFlags = accFlags;
112     fieldName = name;
113     fieldSignature = sig;
114     fieldAttributes = field_attrs;
115   }
116
117   /* package local methods */
118
119   static ClassField read(DataInputStream data, ConstantPool pool)
120     throws IOException {
121     ClassField f = null;
122     int accessFlags = data.readUnsignedShort();
123     int name_index = data.readUnsignedShort();
124     int sig_index = data.readUnsignedShort();
125     AttributeVector fieldAttribs = AttributeVector.readAttributes(data, pool);
126     f = new ClassField(accessFlags,
127                (ConstUtf8) pool.constantAt(name_index),
128                (ConstUtf8) pool.constantAt(sig_index),
129                fieldAttribs);
130     return f;
131   }
132
133   void write (DataOutputStream data) throws IOException {
134     data.writeShort(accessFlags);
135     data.writeShort(fieldName.getIndex());
136     data.writeShort(fieldSignature.getIndex());
137     fieldAttributes.write(data);
138   }
139
140   void print(PrintStream out, int indent) {
141     ClassPrint.spaces(out, indent);
142     out.print("'" + fieldName.asString() + "'");//NOI18N
143
out.print(" sig = " + fieldSignature.asString());//NOI18N
144
out.print(" access_flags = " + Integer.toString(accessFlags));//NOI18N
145
out.println(" attributes:");//NOI18N
146
fieldAttributes.print(out, indent+2);
147   }
148 }
149
150
Popular Tags