1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.compress.harmony.unpack200;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21
22 import org.apache.commons.compress.harmony.pack200.Codec;
23 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
24 import org.apache.commons.compress.harmony.unpack200.bytecode.AnnotationDefaultAttribute;
25 import org.apache.commons.compress.harmony.unpack200.bytecode.CodeAttribute;
26 import org.apache.commons.compress.harmony.unpack200.bytecode.ConstantValueAttribute;
27 import org.apache.commons.compress.harmony.unpack200.bytecode.DeprecatedAttribute;
28 import org.apache.commons.compress.harmony.unpack200.bytecode.EnclosingMethodAttribute;
29 import org.apache.commons.compress.harmony.unpack200.bytecode.ExceptionsAttribute;
30 import org.apache.commons.compress.harmony.unpack200.bytecode.InnerClassesAttribute;
31 import org.apache.commons.compress.harmony.unpack200.bytecode.LineNumberTableAttribute;
32 import org.apache.commons.compress.harmony.unpack200.bytecode.LocalVariableTableAttribute;
33 import org.apache.commons.compress.harmony.unpack200.bytecode.LocalVariableTypeTableAttribute;
34 import org.apache.commons.compress.harmony.unpack200.bytecode.SignatureAttribute;
35 import org.apache.commons.compress.harmony.unpack200.bytecode.SourceFileAttribute;
36
37
38
39
40 public class AttrDefinitionBands extends BandSet {
41
42 private int[] attributeDefinitionHeader;
43
44 private String[] attributeDefinitionLayout;
45
46 private String[] attributeDefinitionName;
47
48 private AttributeLayoutMap attributeDefinitionMap;
49
50 private final String[] cpUTF8;
51
52 public AttrDefinitionBands(final Segment segment) {
53 super(segment);
54 this.cpUTF8 = segment.getCpBands().getCpUTF8();
55 }
56
57 public AttributeLayoutMap getAttributeDefinitionMap() {
58 return attributeDefinitionMap;
59 }
60
61
62
63
64
65
66 @Override
67 public void read(final InputStream in) throws IOException, Pack200Exception {
68 final int attributeDefinitionCount = header.getAttributeDefinitionCount();
69 attributeDefinitionHeader = decodeBandInt("attr_definition_headers", in, Codec.BYTE1, attributeDefinitionCount);
70 attributeDefinitionName = parseReferences("attr_definition_name", in, Codec.UNSIGNED5, attributeDefinitionCount, cpUTF8);
71 attributeDefinitionLayout = parseReferences("attr_definition_layout", in, Codec.UNSIGNED5, attributeDefinitionCount, cpUTF8);
72
73 attributeDefinitionMap = new AttributeLayoutMap();
74
75 int overflowIndex = 32;
76 if (segment.getSegmentHeader().getOptions().hasClassFlagsHi()) {
77 overflowIndex = 63;
78 }
79 for (int i = 0; i < attributeDefinitionCount; i++) {
80 final int context = attributeDefinitionHeader[i] & 0x03;
81 int index = (attributeDefinitionHeader[i] >> 2) - 1;
82 if (index == -1) {
83 index = overflowIndex++;
84 }
85 final AttributeLayout layout = new AttributeLayout(attributeDefinitionName[i], context, attributeDefinitionLayout[i], index, false);
86 final NewAttributeBands newBands = new NewAttributeBands(segment, layout);
87 attributeDefinitionMap.add(layout, newBands);
88 }
89 attributeDefinitionMap.checkMap();
90 setupDefaultAttributeNames();
91 }
92
93 private void setupDefaultAttributeNames() {
94 AnnotationDefaultAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("AnnotationDefault"));
95 CodeAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("Code"));
96 ConstantValueAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("ConstantValue"));
97 DeprecatedAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("Deprecated"));
98 EnclosingMethodAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("EnclosingMethod"));
99 ExceptionsAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("Exceptions"));
100 InnerClassesAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("InnerClasses"));
101 LineNumberTableAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("LineNumberTable"));
102 LocalVariableTableAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("LocalVariableTable"));
103 LocalVariableTypeTableAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("LocalVariableTypeTable"));
104 SignatureAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("Signature"));
105 SourceFileAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("SourceFile"));
106 MetadataBandGroup.setRvaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeVisibleAnnotations"));
107 MetadataBandGroup.setRiaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeInvisibleAnnotations"));
108 MetadataBandGroup.setRvpaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeVisibleParameterAnnotations"));
109 MetadataBandGroup.setRipaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeInvisibleParameterAnnotations"));
110 }
111
112 @Override
113 public void unpack() throws Pack200Exception, IOException {
114
115 }
116
117 }