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   * Represents the source file attribute in a class file
24   */
25  public class SourceFileAttribute extends ClassAttribute {
26      /* The expected attribute name */
27      public static final String expectedAttrName = "SourceFile";
28  
29      /* The source file name */
30      private ConstUtf8 sourceFileName;
31  
32      /* public accessors */
33  
34      /***
35       * Returns the source file name
36       * The file name should not include directories
37       */
38      public ConstUtf8 fileName() {
39          return sourceFileName;
40      }
41  
42      /***
43       * Sets the source file name
44       */
45      public void setFileName(ConstUtf8 name) {
46          sourceFileName = name;
47      }
48  
49      /***
50       * Constructor for a source file attribute
51       */
52      public SourceFileAttribute(ConstUtf8 attrName, ConstUtf8 sourceName) {
53          super(attrName);
54          sourceFileName = sourceName;
55      }
56  
57      /* 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 */
58      static SourceFileAttribute read(ConstUtf8 attrName,
59                                      DataInputStream data, ConstantPool pool)
60          throws IOException {
61          int index = 0;
62          index = data.readUnsignedShort();
63  
64          return new SourceFileAttribute(attrName,
65                                         (ConstUtf8) pool.constantAt(index));
66      }
67  
68      void write(DataOutputStream out) throws IOException {
69          out.writeShort(attrName().getIndex());
70          out.writeInt(2);
71          out.writeShort(sourceFileName.getIndex());
72      }
73  
74      void print(PrintStream out, int indent) {
75          ClassPrint.spaces(out, indent);
76          out.println("SourceFile: " + sourceFileName.asString());
77      }
78  }