View Javadoc

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