01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package EDU.purdue.cs.bloat.file;
22:
23: import java.io.*;
24:
25: /**
26: * Attribute is an abstract class for an attribute defined for a method, field,
27: * or class. An attribute consists of its name (represented as an index into the
28: * constant pool) and its length. Attribute is extended to represent a constant
29: * value, code, exceptions, etc.
30: *
31: * @see Code
32: * @see ConstantValue
33: * @see Exceptions
34: *
35: * @author Nate Nystrom (<a
36: * href="mailto:nystrom@cs.purdue.edu">nystrom@cs.purdue.edu</a>)
37: */
38: public abstract class Attribute {
39: protected int nameIndex;
40:
41: protected int length;
42:
43: /**
44: * Constructor.
45: *
46: * @param nameIndex
47: * The index into the constant pool of the name of the attribute.
48: * @param length
49: * The length of the attribute, excluding the header.
50: */
51: public Attribute(final int nameIndex, final int length) {
52: this .nameIndex = nameIndex;
53: this .length = length;
54: }
55:
56: /**
57: * Write the attribute to a data stream.
58: *
59: * @param out
60: * The data stream of the class file.
61: */
62: public abstract void writeData(DataOutputStream out)
63: throws IOException;
64:
65: /**
66: * Returns a string representation of the attribute.
67: */
68: public String toString() {
69: return "(attribute " + nameIndex + " " + length + ")";
70: }
71:
72: /**
73: * Returns the index into the constant pool of the name of the attribute.
74: */
75: public int nameIndex() {
76: return nameIndex;
77: }
78:
79: /**
80: * Returns the length of the attribute, excluding the header.
81: */
82: public int length() {
83: return length;
84: }
85:
86: public Object clone() {
87: throw new UnsupportedOperationException(
88: "Cannot clone Attribute! " + " (subclass: "
89: + this .getClass() + ")");
90: }
91: }
|