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