KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > services > classfile > ClassMember


1 /*
2
3    Derby - Class org.apache.derby.iapi.services.classfile.ClassMember
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.iapi.services.classfile;
23
24 import java.lang.reflect.Modifier JavaDoc;
25
26 import java.io.IOException JavaDoc;
27
28
29
30 public class ClassMember {
31     protected ClassHolder cpt;
32     protected int access_flags;
33     protected int name_index;
34     protected int descriptor_index;
35     protected Attributes attribute_info; // can be null
36

37     ClassMember(ClassHolder cpt, int modifier, int name, int descriptor) {
38         this.cpt = cpt;
39         name_index = name;
40         descriptor_index = descriptor;
41         access_flags = modifier;
42     }
43
44     /*
45     ** Public methods from ClassMember
46     */

47
48     public int getModifier() {
49             return access_flags;
50     }
51
52     public String JavaDoc getDescriptor() {
53         return cpt.nameIndexToString(descriptor_index);
54     }
55     
56     public String JavaDoc getName() {
57         return cpt.nameIndexToString(name_index);
58     }
59
60     public void addAttribute(String JavaDoc attributeName, ClassFormatOutput info) {
61
62         if (attribute_info == null)
63             attribute_info = new Attributes(1);
64
65         attribute_info.addEntry(new AttributeEntry(cpt.addUtf8(attributeName), info));
66     }
67
68
69     /*
70     ** ----
71     */

72
73     void put(ClassFormatOutput out) throws IOException JavaDoc {
74         out.putU2(access_flags);
75         out.putU2(name_index);
76         out.putU2(descriptor_index);
77
78         if (attribute_info != null) {
79             out.putU2(attribute_info.size());
80             attribute_info.put(out);
81         } else {
82             out.putU2(0);
83         }
84     }
85
86     int classFileSize() {
87         int size = 2 + 2 + 2 + 2;
88         if (attribute_info != null)
89             size += attribute_info.classFileSize();
90         return size;
91     }
92 }
93
Popular Tags