View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  
18  package org.apache.jdo.impl.enhancer.classfile;
19  
20  import java.io.*;
21  
22  /***
23   * AnnotatedClassAttribute represents a class level attribute
24   * class file which identifies the level of annotation of the class.
25   */
26  public class AnnotatedClassAttribute extends ClassAttribute {
27  
28      /* The expected attribute name */
29      public final static String expectedAttrName = "filter.annotatedClass";
30  
31      /* The expected attribute version */
32      public final static short expectedAttrVersion = 1;
33  
34      /* Bit mask indicating that the class was filter generated */
35      public final static short generatedFlag = 0x1;
36  
37      /* Bit mask indicating that the class was filter annotated */
38      public final static short annotatedFlag = 0x2;
39  
40      /* Bit mask indicating that the class was "repackaged" or similarly
41       * modified */
42      public final static short modifiedFlag = 0x4;
43  
44      /* The version of the attribute */
45      private short attrVersion;
46  
47      /* Flags associated with the annotation */
48      private short annotationFlags;
49  
50      /* The modification date of the class file at the time of modification */
51      private long classModTime;
52  
53      /* The date of the annotation */
54      private long classAnnotationTime;
55  
56      /* public accessors */
57  
58      public short getVersion() {
59          return attrVersion;
60      }
61  
62      public void setVersion(short version) {
63          attrVersion = version;
64      }
65  
66      public short getFlags() {
67          return annotationFlags;
68      }
69  
70      public void setFlags(short flags) {
71          annotationFlags = flags;
72      }
73  
74      public long getModTime() {
75          return classModTime;
76      }
77  
78      public void setModTime(long time) {
79          classModTime = time;
80      }
81  
82      public long getAnnotationTime() {
83          return classAnnotationTime;
84      }
85  
86      public void setAnnotationTime(long time) {
87          classAnnotationTime = time;
88      }
89  
90      /***
91       * Constructor
92       */
93      public AnnotatedClassAttribute(
94  	ConstUtf8 nameAttr, short version, short annFlags,
95  	long modTime, long annTime) {
96          super(nameAttr);
97          attrVersion = version;
98          annotationFlags = annFlags;
99          classModTime = modTime;
100         classAnnotationTime = annTime;
101     }
102 
103     /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">/* package local methods *//package-summary.html">class="comment"> package local methods */
104 
105     static AnnotatedClassAttribute read(
106 	ConstUtf8 attrName, DataInputStream data, ConstantPool pool)
107         throws IOException {
108         short version = data.readShort();
109         short annFlags = data.readShort();
110         long modTime = data.readLong();
111         long annTime = data.readLong();
112         return  new AnnotatedClassAttribute(attrName, version, annFlags,
113                                             modTime, annTime);
114     }
115 
116     void write(DataOutputStream out) throws IOException {
117         out.writeShort(attrName().getIndex());
118         out.writeShort(20);
119         out.writeShort(attrVersion);
120         out.writeShort(annotationFlags);
121         out.writeLong(classModTime);
122         out.writeLong(classAnnotationTime);
123     }
124 
125     void print(PrintStream out, int indent) {
126         ClassPrint.spaces(out, indent);
127         out.println("version: " + attrVersion);
128         out.println(" flags: " + annotationFlags);
129         out.println(" modTime: " + classModTime);
130         out.println(" annTime: " + classAnnotationTime);
131     }
132 }