1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.jdo.impl.enhancer.classfile;
20
21 import java.io.*;
22 import java.util.Stack;
23
24 /***
25 * GenericAttribute represents a class attribute in a class file which
26 * is not recognized as any supported attribute type. These attributes
27 * are maintained, and are not modified in any way.
28 */
29
30 public class GenericAttribute extends ClassAttribute {
31
32
33 byte attributeBytes[];
34
35
36
37 /***
38 * constructor
39 */
40 public GenericAttribute(ConstUtf8 attrName, byte attrBytes[]) {
41 super(attrName);
42 attributeBytes = attrBytes;
43 }
44
45 /***
46 * Compares this instance with another for structural equality.
47 */
48
49 public boolean isEqual(Stack msg, Object obj) {
50 if (!(obj instanceof GenericAttribute)) {
51 msg.push("obj/obj.getClass() = "
52 + (obj == null ? null : obj.getClass()));
53 msg.push("this.getClass() = "
54 + this.getClass());
55 return false;
56 }
57 GenericAttribute other = (GenericAttribute)obj;
58
59 if (!super.isEqual(msg, other)) {
60 return false;
61 }
62
63 if (this.attributeBytes.length != other.attributeBytes.length) {
64 msg.push("attributeBytes.length "
65 + String.valueOf(other.attributeBytes.length));
66 msg.push("attributeBytes.length "
67 + String.valueOf(this.attributeBytes.length));
68 return false;
69 }
70
71 for (int i = 0; i < attributeBytes.length; i++) {
72 byte b1 = this.attributeBytes[i];
73 byte b2 = other.attributeBytes[i];
74 if (b1 != b2) {
75 msg.push("attributeBytes[" + i + "] = "
76 + String.valueOf(b2));
77 msg.push("attributeBytes[" + i + "] = "
78 + String.valueOf(b1));
79 return false;
80 }
81 }
82 return true;
83 }
84
85 void write(DataOutputStream out) throws IOException {
86 out.writeShort(attrName().getIndex());
87 out.writeInt(attributeBytes.length);
88 out.write(attributeBytes, 0, attributeBytes.length);
89 }
90
91 void print(PrintStream out, int indent) {
92 ClassPrint.spaces(out, indent);
93 out.println("Generic Attribute(" + attrName().asString() + "): " +
94 Integer.toString(attributeBytes.length) +
95 " in length");
96 for (int i=0; i<attributeBytes.length; i++) {
97 if ((i % 16) == 0) {
98 if (i != 0)
99 out.println();
100 out.print(i + " :");
101 }
102 out.print(" " + Integer.toString((attributeBytes[i] & 0xff), 16));
103 }
104 out.println();
105 }
106 }
107