KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > attributes > RuntimeAnnotationsAttribute


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7 package org.gjt.jclasslib.structures.attributes;
8
9 import org.gjt.jclasslib.structures.AttributeInfo;
10 import org.gjt.jclasslib.structures.InvalidByteCodeException;
11 import org.gjt.jclasslib.structures.elementvalues.AnnotationElementValue;
12
13 import java.io.*;
14
15 /**
16  * Common class for runtime annotations.
17  *
18  * @author <a HREF="mailto:vitor.carreira@gmail.com">Vitor Carreira</a>
19  * @version $Revision: 1.1 $ $Date: 2004/12/28 13:04:32 $
20  */

21 public class RuntimeAnnotationsAttribute extends AttributeInfo {
22     private static final int INITIAL_LENGTH = 2;
23
24     protected AnnotationElementValue[] runtimeAnnotations;
25
26
27     /**
28      * Get the list of runtime annotations associations of the parent
29      * structure as an array of <tt>Annotation</tt> structures.
30      *
31      * @return the array
32      */

33     public AnnotationElementValue[] getRuntimeAnnotations() {
34         return runtimeAnnotations;
35     }
36
37     /**
38      * Set the list of runtime annotations associations of the parent
39      * structure as an array of <tt>Annotation</tt> structures.
40      *
41      * @param runtimeAnnotations the array
42      */

43     public void setRuntimeAnnotations(AnnotationElementValue[] runtimeAnnotations) {
44         this.runtimeAnnotations = runtimeAnnotations;
45     }
46
47     public void read(DataInput in)
48             throws InvalidByteCodeException, IOException {
49
50         super.read(in);
51
52         int runtimeVisibleAnnotationsLength = in.readUnsignedShort();
53         runtimeAnnotations = new AnnotationElementValue[runtimeVisibleAnnotationsLength];
54         for (int i = 0; i < runtimeVisibleAnnotationsLength; i++) {
55             runtimeAnnotations[i] = new AnnotationElementValue();
56             runtimeAnnotations[i].setClassFile(classFile);
57             runtimeAnnotations[i].read(in);
58         }
59
60         if (debug) debug("read ");
61     }
62
63     public void write(DataOutput out)
64             throws InvalidByteCodeException, IOException {
65
66         super.write(out);
67
68         int runtimeVisibleAnnotationsLength = getLength(runtimeAnnotations);
69
70         out.writeShort(runtimeVisibleAnnotationsLength);
71         for (int i = 0; i < runtimeVisibleAnnotationsLength; i++) {
72             runtimeAnnotations[i].write(out);
73         }
74
75         if (debug) debug("wrote ");
76     }
77
78     public int getAttributeLength() {
79         int length = INITIAL_LENGTH;
80         for (int i = 0; i < runtimeAnnotations.length; i++) {
81             length += runtimeAnnotations[i].getLength();
82         }
83         return length;
84     }
85 }
86
Popular Tags