< prev index next >

src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Deprecated.java

Print this page




  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 package com.sun.org.apache.bcel.internal.classfile;
  22 
  23 import java.io.DataInput;
  24 import java.io.DataOutputStream;
  25 import java.io.IOException;
  26 
  27 import com.sun.org.apache.bcel.internal.Const;
  28 
  29 /**
  30  * This class is derived from <em>Attribute</em> and denotes that this is a
  31  * deprecated method.
  32  * It is instantiated from the <em>Attribute.readAttribute()</em> method.
  33  *
  34  * @version $Id$
  35  * @see     Attribute
  36  */
  37 public final class Deprecated extends Attribute {
  38 
  39     private byte[] bytes;
  40 
  41 
  42     /**
  43      * Initialize from another object. Note that both objects use the same
  44      * references (shallow copy). Use clone() for a physical copy.
  45      */
  46     public Deprecated(final Deprecated c) {
  47         this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
  48     }
  49 
  50 
  51     /**
  52      * @param name_index Index in constant pool to CONSTANT_Utf8
  53      * @param length Content length in bytes
  54      * @param bytes Attribute contents


  58         super(Const.ATTR_DEPRECATED, name_index, length, constant_pool);
  59         this.bytes = bytes;
  60     }
  61 
  62 
  63     /**
  64      * Construct object from input stream.
  65      *
  66      * @param name_index Index in constant pool to CONSTANT_Utf8
  67      * @param length Content length in bytes
  68      * @param input Input stream
  69      * @param constant_pool Array of constants
  70      * @throws IOException
  71      */
  72     Deprecated(final int name_index, final int length, final DataInput input, final ConstantPool constant_pool)
  73             throws IOException {
  74         this(name_index, length, (byte[]) null, constant_pool);
  75         if (length > 0) {
  76             bytes = new byte[length];
  77             input.readFully(bytes);
  78             System.err.println("Deprecated attribute with length > 0");
  79         }
  80     }
  81 
  82 
  83     /**
  84      * Called by objects that are traversing the nodes of the tree implicitely
  85      * defined by the contents of a Java class. I.e., the hierarchy of methods,
  86      * fields, attributes, etc. spawns a tree of objects.
  87      *
  88      * @param v Visitor object
  89      */
  90     @Override
  91     public void accept( final Visitor v ) {
  92         v.visitDeprecated(this);
  93     }
  94 
  95 
  96     /**
  97      * Dump source file attribute to file stream in binary format.
  98      *
  99      * @param file Output file stream
 100      * @throws IOException
 101      */
 102     @Override
 103     public final void dump( final DataOutputStream file ) throws IOException {
 104         super.dump(file);
 105         if (super.getLength() > 0) {
 106             file.write(bytes, 0, super.getLength());
 107         }
 108     }
 109 
 110 
 111     /**
 112      * @return data bytes.
 113      */
 114     public final byte[] getBytes() {
 115         return bytes;
 116     }
 117 
 118 
 119     /**
 120      * @param bytes the raw bytes that represents this byte array
 121      */
 122     public final void setBytes( final byte[] bytes ) {
 123         this.bytes = bytes;
 124     }
 125 
 126 
 127     /**
 128      * @return attribute name
 129      */
 130     @Override
 131     public final String toString() {
 132         return Const.getAttributeName(Const.ATTR_DEPRECATED);
 133     }
 134 
 135 
 136     /**
 137      * @return deep copy of this attribute
 138      */
 139     @Override
 140     public Attribute copy( final ConstantPool _constant_pool ) {
 141         final Deprecated c = (Deprecated) clone();
 142         if (bytes != null) {
 143             c.bytes = new byte[bytes.length];
 144             System.arraycopy(bytes, 0, c.bytes, 0, bytes.length);
 145         }
 146         c.setConstantPool(_constant_pool);
 147         return c;
 148     }
 149 }


  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 package com.sun.org.apache.bcel.internal.classfile;
  22 
  23 import java.io.DataInput;
  24 import java.io.DataOutputStream;
  25 import java.io.IOException;
  26 
  27 import com.sun.org.apache.bcel.internal.Const;
  28 
  29 /**
  30  * This class is derived from <em>Attribute</em> and denotes that this is a
  31  * deprecated method.
  32  * It is instantiated from the <em>Attribute.readAttribute()</em> method.
  33  *

  34  * @see     Attribute
  35  */
  36 public final class Deprecated extends Attribute {
  37 
  38     private byte[] bytes;
  39 
  40 
  41     /**
  42      * Initialize from another object. Note that both objects use the same
  43      * references (shallow copy). Use clone() for a physical copy.
  44      */
  45     public Deprecated(final Deprecated c) {
  46         this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
  47     }
  48 
  49 
  50     /**
  51      * @param name_index Index in constant pool to CONSTANT_Utf8
  52      * @param length Content length in bytes
  53      * @param bytes Attribute contents


  57         super(Const.ATTR_DEPRECATED, name_index, length, constant_pool);
  58         this.bytes = bytes;
  59     }
  60 
  61 
  62     /**
  63      * Construct object from input stream.
  64      *
  65      * @param name_index Index in constant pool to CONSTANT_Utf8
  66      * @param length Content length in bytes
  67      * @param input Input stream
  68      * @param constant_pool Array of constants
  69      * @throws IOException
  70      */
  71     Deprecated(final int name_index, final int length, final DataInput input, final ConstantPool constant_pool)
  72             throws IOException {
  73         this(name_index, length, (byte[]) null, constant_pool);
  74         if (length > 0) {
  75             bytes = new byte[length];
  76             input.readFully(bytes);
  77             println("Deprecated attribute with length > 0");
  78         }
  79     }
  80 
  81 
  82     /**
  83      * Called by objects that are traversing the nodes of the tree implicitely
  84      * defined by the contents of a Java class. I.e., the hierarchy of methods,
  85      * fields, attributes, etc. spawns a tree of objects.
  86      *
  87      * @param v Visitor object
  88      */
  89     @Override
  90     public void accept( final Visitor v ) {
  91         v.visitDeprecated(this);
  92     }
  93 
  94 
  95     /**
  96      * Dump source file attribute to file stream in binary format.
  97      *
  98      * @param file Output file stream
  99      * @throws IOException
 100      */
 101     @Override
 102     public void dump( final DataOutputStream file ) throws IOException {
 103         super.dump(file);
 104         if (super.getLength() > 0) {
 105             file.write(bytes, 0, super.getLength());
 106         }
 107     }
 108 
 109 
 110     /**
 111      * @return data bytes.
 112      */
 113     public byte[] getBytes() {
 114         return bytes;
 115     }
 116 
 117 
 118     /**
 119      * @param bytes the raw bytes that represents this byte array
 120      */
 121     public void setBytes( final byte[] bytes ) {
 122         this.bytes = bytes;
 123     }
 124 
 125 
 126     /**
 127      * @return attribute name
 128      */
 129     @Override
 130     public String toString() {
 131         return Const.getAttributeName(Const.ATTR_DEPRECATED);
 132     }
 133 
 134 
 135     /**
 136      * @return deep copy of this attribute
 137      */
 138     @Override
 139     public Attribute copy( final ConstantPool _constant_pool ) {
 140         final Deprecated c = (Deprecated) clone();
 141         if (bytes != null) {
 142             c.bytes = new byte[bytes.length];
 143             System.arraycopy(bytes, 0, c.bytes, 0, bytes.length);
 144         }
 145         c.setConstantPool(_constant_pool);
 146         return c;
 147     }
 148 }
< prev index next >