KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > classfile > AnnotatedMethodAttribute


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.classfile;
26
27 import java.io.*;
28
29 /**
30  * AnnotatedMethodAttribute represents a class level attribute
31  * class file which identifies the level of annotation of the class.
32  */

33
34 public class AnnotatedMethodAttribute extends ClassAttribute {
35
36   /* The expected attribute name */
37     public final static String JavaDoc expectedAttrName = "filter.annotatedMethod";//NOI18N
38

39   /* The expected attribute version */
40   public final static short expectedAttrVersion = 1;
41
42   /* Bit mask indicating that the class was filter generated */
43   public final static short generatedFlag = 0x1;
44
45   /* Bit mask indicating that the class was filter annotated */
46   public final static short annotatedFlag = 0x2;
47
48     /* Bit mask indicating that the class was "repackaged" *///NOI18N
49
public final static short modifiedFlag = 0x4;
50
51   /* The version of the attribute */
52   private short attrVersion;
53
54   /* Flags associated with the annotation */
55   private short annotationFlags;
56
57   /* list of targets in the code sequence delimiting inserted instruction
58    * sequences. Even index targets are a range start (inclusive) and odd
59    * targets represent a range end (exclusive) */

60   private InsnTarget annotationRanges[];
61
62   /* public accessors */
63
64   public short getVersion() {
65     return attrVersion;
66   }
67
68   public void setVersion(short version) {
69     attrVersion = version;
70   }
71
72   public short getFlags() {
73     return annotationFlags;
74   }
75
76   public void setFlags(short flags) {
77     annotationFlags = flags;
78   }
79
80   public InsnTarget[] getAnnotationRanges() {
81     return annotationRanges;
82   }
83
84   public void setAnnotationRanges(InsnTarget[] ranges) {
85     annotationRanges = ranges;
86   }
87
88   /**
89    * Constructor
90    */

91   public AnnotatedMethodAttribute(
92     ConstUtf8 nameAttr, short version, short annFlags,
93     InsnTarget[] annRanges) {
94     super(nameAttr);
95     attrVersion = version;
96     annotationFlags = annFlags;
97     annotationRanges = annRanges;
98   }
99
100   /* package local methods */
101
102   static AnnotatedMethodAttribute read(
103     ConstUtf8 attrName, DataInputStream data, CodeEnv env)
104     throws IOException {
105     short version = data.readShort();
106     short annFlags = data.readShort();
107
108     short nRanges = data.readShort();
109
110     InsnTarget ranges[] = new InsnTarget[nRanges*2];
111     for (int i=0; i<nRanges; i++) {
112       ranges[i*2] = env.getTarget(data.readShort());
113       ranges[i*2+1] = env.getTarget(data.readShort());
114     }
115     return new AnnotatedMethodAttribute(attrName, version, annFlags, ranges);
116   }
117
118   void write(DataOutputStream out) throws IOException {
119     out.writeShort(attrName().getIndex());
120     if (annotationRanges == null)
121       out.writeShort(2);
122     else
123       out.writeShort(4 + 2 * annotationRanges.length);
124     out.writeShort(attrVersion);
125     out.writeShort(annotationFlags);
126     if (annotationRanges == null)
127       out.writeShort(0);
128     else {
129       out.writeShort(annotationRanges.length / 2);
130       for (int i=0; i<annotationRanges.length; i++)
131     out.writeShort(annotationRanges[i].offset());
132     }
133   }
134
135   void print(PrintStream out, int indent) {
136     ClassPrint.spaces(out, indent);
137     out.println("version: " + attrVersion);//NOI18N
138
out.println(" flags: " + annotationFlags);//NOI18N
139
if (annotationRanges != null) {
140         out.println("Annotations: ");//NOI18N
141
for (int i=0; i<annotationRanges.length/2; i++) {
142     ClassPrint.spaces(out, indent+2);
143     out.println(annotationRanges[i*2] + " to " +//NOI18N
144
annotationRanges[i*2+1]);
145       }
146     }
147   }
148 }
149
Popular Tags