Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Synthetic.java

00001 package de.fub.bytecode.classfile;
00002 
00003 import  de.fub.bytecode.Constants;
00004 import  java.io.*;
00005 
00006 /**
00007  * This class is derived from <em>Attribute</em> and declares this class
00008  * as `synthetic', i.e. it needs special handling.
00009  * It is instantiated from the <em>Attribute.readAttribute()</em> method.
00010  *
00011  * @version $Id: Synthetic.java,v 1.1.1.1 2002/01/24 03:44:00 pserver Exp $
00012  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00013  * @see     Attribute
00014  */
00015 public final class Synthetic extends Attribute {
00016   private byte[] bytes;
00017 
00018   /**
00019    * @param name_index Index in constant pool to CONSTANT_Utf8
00020    * @param length Content length in bytes
00021    * @param bytes Attribute contents
00022    * @param constant_pool Array of constants
00023    * @param sourcefile_index Index in constant pool to CONSTANT_Utf8
00024    */
00025   public Synthetic(int name_index, int length, byte[] bytes,
00026            ConstantPool constant_pool)
00027   {
00028     super(ATTR_SYNTHETIC, name_index, length, constant_pool);
00029     this.bytes         = bytes;
00030   }  
00031   /**
00032    * Construct object from file stream.
00033    * @param name_index Index in constant pool to CONSTANT_Utf8
00034    * @param length Content length in bytes
00035    * @param file Input stream
00036    * @param constant_pool Array of constants
00037    * @throw IOException
00038    */
00039   Synthetic(int name_index, int length, DataInputStream file,
00040         ConstantPool constant_pool) throws IOException
00041   {
00042     this(name_index, length, (byte [])null, constant_pool);
00043 
00044     if(length > 0) {
00045       bytes = new byte[length];
00046       file.readFully(bytes);
00047       System.err.println("Synthetic attribute with length > 0");
00048     }
00049   }  
00050   /**
00051    * Initialize from another object. Note that both objects use the same
00052    * references (shallow copy). Use clone() for a physical copy.
00053    */
00054   public Synthetic(Synthetic c) {
00055     this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
00056   }  
00057   /**
00058    * Called by objects that are traversing the nodes of the tree implicitely
00059    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00060    * fields, attributes, etc. spawns a tree of objects.
00061    *
00062    * @param v Visitor object
00063    */
00064   public void accept(Visitor v) {
00065     v.visitSynthetic(this);
00066   }  
00067   /**
00068    * @return deep copy of this attribute
00069    */
00070   public Attribute copy(ConstantPool constant_pool) {
00071     Synthetic c = (Synthetic)clone();
00072 
00073     if(bytes != null)
00074       c.bytes = (byte[])bytes.clone();
00075 
00076     c.constant_pool = constant_pool;
00077     return c;
00078   }  
00079   /**
00080    * Dump source file attribute to file stream in binary format.
00081    *
00082    * @param file Output file stream
00083    * @throw IOException
00084    */ 
00085   public final void dump(DataOutputStream file) throws IOException
00086   {
00087     super.dump(file);
00088     if(length > 0)
00089       file.write(bytes, 0, length);
00090   }  
00091   /**
00092    * @return data bytes.
00093    */  
00094   public final byte[] getBytes() { return bytes; }  
00095   /**
00096    * @param bytes.
00097    */
00098   public final void setBytes(byte[] bytes) {
00099     this.bytes = bytes;
00100   }  
00101   /**
00102    * @return String representation.
00103    */ 
00104   public final String toString() {
00105     StringBuffer buf = new StringBuffer("Synthetic");
00106 
00107     if(length > 0)
00108       buf.append(" " + Utility.toHexString(bytes));
00109 
00110     return buf.toString();
00111   }  
00112 }

Generated at Thu Feb 7 06:56:06 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001