Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/chaoswg/xtc4y/classdesc/SourceFileAttribute.java


1   //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/SourceFileAttribute.java,v 1.1.1.1 2003/08/07 13:40:28 toggm Exp $
2   /******************************************************************************
3    * XTC4y - eXtreme Testing Collection 4 you                                   *
4    * -------------------------------------------------------------------------- *
5    * URL: http://www.chaoswg.com/xtc4y                                          *
6    * Author: Mike Toggweiler (2.dog@gmx.ch)                                     *
7    *                                                                            *
8    * Last Updated: $Date: 2003/08/07 13:40:28 $, by $Author: toggm $            *
9    * Version: $Revision: 1.1.1.1 $                                                  *
10   * -------------------------------------------------------------------------- *
11   * COPYRIGHT:   (c) 2003 by Mike Toggweiler                                   *
12   *                                                                            *
13   * This program is free software; you can redistribute it and/or modify       *
14   * it under the terms of the GNU General Public License as published by       *
15   * the Free Software Foundation; either version 2 of the License, or          *
16   * (at your option) any later version.                                        *
17   *****************************************************************************/
18  package com.chaoswg.xtc4y.classdesc;
19  
20  import java.io.DataInputStream;
21  import java.io.DataOutputStream;
22  import java.io.IOException;
23  
24  /**
25   * This class describes the information for a sourcefile attribute ($4.7.7)
26   * @author Mike Toggweiler
27   **/
28  public class SourceFileAttribute extends Attribute {
29  
30      public static final String NAME = "SourceFile";
31  
32      private String filename;
33      
34  
35      /**
36       * Creates a SourceFileAttribute and initializes it from a 
37       * DataInputStream
38       * The attribute name and length 
39       * of the attribute information was already read.
40       * @param dis the DataInputStream to read from
41       * @param cp the constant pool to resolve indices
42       * @param length the length of the attribute information provided 
43       * on the DataInputStream    
44       **/
45      protected SourceFileAttribute(DataInputStream dis, ConstantPool cp, 
46            int length) 
47    throws IOException {    
48    super(dis, cp, length);
49    
50    if (!getName().equals(NAME)) {
51        throw new ClassFormatError("Attribute name does not match");
52    }    
53  
54    short index = (short)dis.readUnsignedShort();
55    filename = ((UTF8CPEntry)cp.getCPEntryAt(index)).getString();
56      }    
57  
58      /**
59       * construct a new source file attribute with the filename as parameter
60       * from the JVM book:
61       * 'the name of the source file from which this class file was compiled. 
62       * It will not be interpreted as indicating the name of a directory 
63       * containing the file or an absolute path name for the file; such 
64       * platform-specific additional information must be supplied by the 
65       * runtime interpreter or development tool at the time the file name is 
66       * actually used.'
67       **/
68      public SourceFileAttribute(String filename) {
69    this.filename = filename;
70      }
71  
72      /**
73       * Write the attribute information onto the DataOutputStream, using the 
74       * constant pool to register variables. The Attribute name and the 
75       * length of the information will already be written. A specific 
76       * attribute implementation should overwrite this method.
77       * @param dos the DataOutputStream to write on
78       * @param cp The constant pool to register variables
79       **/
80      protected void writeAttribute(DataOutputStream dos, ConstantPool cp) 
81    throws IOException {
82    dos.writeShort(cp.addCPEntry(new UTF8CPEntry(filename)));
83      }
84  
85      /**
86       * @return the name of the attribute
87       **/
88      public String getName() {
89    return NAME;
90      }  
91  
92      /**
93       * set the new source filename
94       * @param filename the new filename
95       **/
96      public void setFileName(String filename) {
97    this.filename = filename;
98      }
99  
100     /**
101      * @return the source filename
102      **/
103     public String getFileName() {
104   return filename;
105     }
106 }