KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > classfile > SourceFileAttribute


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.classfile;
26
27 import java.io.*;
28
29 /**
30  * Represents the source file attribute in a class file
31  */

32
33 public class SourceFileAttribute extends ClassAttribute {
34   /* The expected attribute name */
35     public static final String JavaDoc expectedAttrName = "SourceFile";//NOI18N
36

37   /* The source file name */
38   private ConstUtf8 sourceFileName;
39
40   /* public accessors */
41
42   /**
43    * Returns the source file name
44    * The file name should not include directories
45    */

46   public ConstUtf8 fileName() {
47     return sourceFileName;
48   }
49
50   /**
51    * Sets the source file name
52    */

53   public void setFileName(ConstUtf8 name) {
54     sourceFileName = name;
55   }
56
57   /**
58    * Constructor for a source file attribute
59    */

60   public SourceFileAttribute(ConstUtf8 attrName, ConstUtf8 sourceName) {
61     super(attrName);
62     sourceFileName = sourceName;
63   }
64
65   /* package local methods */
66   static SourceFileAttribute read(ConstUtf8 attrName,
67                   DataInputStream data, ConstantPool pool)
68     throws IOException {
69     int index = 0;
70     index = data.readUnsignedShort();
71
72     return new SourceFileAttribute(attrName,
73                    (ConstUtf8) pool.constantAt(index));
74   }
75
76   void write(DataOutputStream out) throws IOException {
77     out.writeShort(attrName().getIndex());
78     out.writeInt(2);
79     out.writeShort(sourceFileName.getIndex());
80   }
81
82   void print(PrintStream out, int indent) {
83     ClassPrint.spaces(out, indent);
84     out.println("SourceFile: " + sourceFileName.asString());//NOI18N
85
}
86 }
87
88
Popular Tags