1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.classfile; 23 24 25 import com.sun.org.apache.bcel.internal.Constants; 26 import java.io.*; 27 28 /** 29 * This class is derived from <em>Attribute</em> and represents a reference 30 * to a <a href="http://www.inf.fu-berlin.de/~bokowski/pmgjava/index.html">PMG</a> 31 * attribute. 32 * 33 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 34 * @see Attribute 35 */ 36 public final class PMGClass extends Attribute { 37 private int pmg_class_index, pmg_index; 38 39 /** 40 * Initialize from another object. Note that both objects use the same 41 * references (shallow copy). Use clone() for a physical copy. 42 */ 43 public PMGClass(PMGClass c) { 44 this(c.getNameIndex(), c.getLength(), c.getPMGIndex(), c.getPMGClassIndex(), 45 c.getConstantPool()); 46 } 47 48 /** 49 * Construct object from file stream. 50 * @param name_index Index in constant pool to CONSTANT_Utf8 51 * @param length Content length in bytes 52 * @param file Input stream 53 * @param constant_pool Array of constants 54 * @throws IOException 55 */ 56 PMGClass(int name_index, int length, DataInputStream file, 57 ConstantPool constant_pool) throws IOException 58 { 59 this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), 60 constant_pool); 61 } 62 63 /** 64 * @param name_index Index in constant pool to CONSTANT_Utf8 65 * @param length Content length in bytes 66 * @param constant_pool Array of constants 67 * @param PMGClass_index Index in constant pool to CONSTANT_Utf8 68 */ 69 public PMGClass(int name_index, int length, int pmg_index, int pmg_class_index, 70 ConstantPool constant_pool) 71 { 72 super(Constants.ATTR_PMG, name_index, length, constant_pool); 73 this.pmg_index = pmg_index; 74 this.pmg_class_index = pmg_class_index; 75 } 76 77 /** 78 * Called by objects that are traversing the nodes of the tree implicitely 79 * defined by the contents of a Java class. I.e., the hierarchy of methods, 80 * fields, attributes, etc. spawns a tree of objects. 81 * 82 * @param v Visitor object 83 */ 84 public void accept(Visitor v) { 85 System.err.println("Visiting non-standard PMGClass object"); 86 } 87 88 /** 89 * Dump source file attribute to file stream in binary format. 90 * 91 * @param file Output file stream 92 * @throws IOException 93 */ 94 public final void dump(DataOutputStream file) throws IOException 95 { 96 super.dump(file); 97 file.writeShort(pmg_index); 98 file.writeShort(pmg_class_index); 99 } 100 101 /** 102 * @return Index in constant pool of source file name. 103 */ 104 public final int getPMGClassIndex() { return pmg_class_index; } 105 106 /** 107 * @param PMGClass_index. 108 */ 109 public final void setPMGClassIndex(int pmg_class_index) { 110 this.pmg_class_index = pmg_class_index; 111 } 112 113 /** 114 * @return Index in constant pool of source file name. 115 */ 116 public final int getPMGIndex() { return pmg_index; } 117 118 /** 119 * @param PMGClass_index. 120 */ 121 public final void setPMGIndex(int pmg_index) { 122 this.pmg_index = pmg_index; 123 } 124 125 /** 126 * @return PMG name. 127 */ 128 public final String getPMGName() { 129 ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(pmg_index, 130 Constants.CONSTANT_Utf8); 131 return c.getBytes(); 132 } 133 134 /** 135 * @return PMG class name. 136 */ 137 public final String getPMGClassName() { 138 ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(pmg_class_index, 139 Constants.CONSTANT_Utf8); 140 return c.getBytes(); 141 } 142 143 /** 144 * @return String representation 145 */ 146 public final String toString() { 147 return "PMGClass(" + getPMGName() + ", " + getPMGClassName() + ")"; 148 } 149 150 /** 151 * @return deep copy of this attribute 152 */ 153 public Attribute copy(ConstantPool constant_pool) { 154 return (PMGClass)clone(); 155 } 156 }