1    
2    /*
3    
4      The author of this software is Ian Kaplan
5      Bear Products International
6      www.bearcave.com
7      iank@bearcave.com
8    
9      Copyright (c) Ian Kaplan, 1999, 2000
10   
11     See copyright file for usage and licensing
12   
13   */
14   
15   package attr;
16   
17   import java.io.*;
18   import util.*;
19   import jconst.*;
20   
21   
22   /**
23   
24      This object represents the source file attribute.  The structure of
25      this attribute is:
26   
27   <pre>
28         SourceFile_attribute {
29           u2 attribute_name_index;
30           u4 attribute_length;
31   	u2 sourcefile_index;
32         }
33   </pre>
34   
35   <p>
36      The attribute_name_index and attribute length are read by the
37      attrFactory.allocAttr method.  These values are passed into the class
38      constructor.
39   
40   <p>
41      The sourcefile_index points to a constUtf8 object in the constant
42      pool.  This object contains the file name for the object.  There
43      can be no more than one SourceFile attribute in the attributes
44      table of a given ClassFile structure.
45   
46      @author Ian Kaplan
47    */
48   public class srcFileAttr extends attrInfo {
49     private constUtf8 srcFile = null;
50     
51     public srcFileAttr( String name, int length, 
52   		      DataInputStream dStream, constPool constPoolSec ) {
53       super( name, length );
54       constBase obj;
55       int srcFileIx;
56   
57       srcFileIx = readU2( dStream );
58       if (srcFileIx > 0) {
59         obj = constPoolSec.constPoolElem( srcFileIx );
60         if (obj instanceof constUtf8) {
61   	srcFile = (constUtf8)obj;
62         }
63         else {
64   	System.out.println("srcFileAttr: object not Utf8");
65         }
66       }
67     } // srcFileAttr constructor
68   
69     /**
70        @return a String object for the source file name
71      */
72     public String getFileName() {
73       String name = null;
74   
75       if (srcFile != null) {
76         name = srcFile.getString();
77       }
78       
79       return name;
80     } // getFileName
81   
82   
83     public void pr() {
84       super.pr();
85       
86       if (srcFile != null)
87         srcFile.pr();
88     } // pr
89   
90   } // srcFileAttr
91   
92