jakarta-bcel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From md...@apache.org
Subject cvs commit: jakarta-bcel/src/java/org/apache/bcel/classfile Attribute.java
Date Tue, 20 Nov 2001 11:41:05 GMT
mdahm       01/11/20 03:41:05

  Modified:    src/java/org/apache/bcel/classfile Attribute.java
  Log:
  Unknown (non-standard) attributes may be read via user-defined
  factory objects that can be registered with the Attribute.addAttributeReader
  method.
  
  Revision  Changes    Path
  1.2       +32 -5     jakarta-bcel/src/java/org/apache/bcel/classfile/Attribute.java
  
  Index: Attribute.java
  ===================================================================
  RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/classfile/Attribute.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Attribute.java	2001/10/29 19:59:57	1.1
  +++ Attribute.java	2001/11/20 11:41:05	1.2
  @@ -54,8 +54,9 @@
    * <http://www.apache.org/>.
    */
   
  -import  org.apache.bcel.Constants;
  -import  java.io.*;
  +import org.apache.bcel.Constants;
  +import java.io.*;
  +import java.util.HashMap;
   
   /**
    * Abstract super class for <em>Attribute</em> objects. Currently the
  @@ -65,7 +66,7 @@
    * <em>Synthetic</em> attributes are supported. The
    * <em>Unknown</em> attribute stands for non-standard-attributes.
    *
  - * @version $Id: Attribute.java,v 1.1 2001/10/29 19:59:57 jvanzyl Exp $
  + * @version $Id: Attribute.java,v 1.2 2001/11/20 11:41:05 mdahm Exp $
    * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
    * @see     ConstantValue
    * @see     SourceFile
  @@ -110,8 +111,29 @@
     {
       file.writeShort(name_index);
       file.writeInt(length);
  -  }    
  +  }
  +
  +  private static HashMap readers = new HashMap();
  +
  +  /** Add an Attribute reader capable of parsing (user-defined) attributes
  +   * named "name". You should not add readers for the standard attributes
  +   * such as "LineNumberTable", because those are handled internally.
  +   *
  +   * @param name the name of the attribute as stored in the class file
  +   * @param r the reader object
  +   */ 
  +  public static void addAttributeReader(String name, AttributeReader r) {
  +    readers.put(name, r);
  +  }
   
  +  /** Remove attribute reader
  +   *
  +   * @param name the name of the attribute as stored in the class file
  +   */
  +  public static void removeAttributeReader(String name) {
  +    readers.remove(name);
  +  }
  +
     /* Class method reads one attribute from the input data stream.
      * This method must not be accessible from the outside.  It is
      * called by the Field and Method constructor methods.
  @@ -155,7 +177,12 @@
       // Call proper constructor, depending on `tag'
       switch(tag) {
       case Constants.ATTR_UNKNOWN:
  -      return new Unknown(name_index, length, file, constant_pool);
  +      AttributeReader r = (AttributeReader)readers.get(name);
  +
  +      if(r != null)
  +	return r.createAttribute(name_index, length, file, constant_pool);
  +      else
  +	return new Unknown(name_index, length, file, constant_pool);
   
       case Constants.ATTR_CONSTANT_VALUE:
         return new ConstantValue(name_index, length, file, constant_pool);
  
  
  

--
To unsubscribe, e-mail:   <mailto:bcel-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:bcel-dev-help@jakarta.apache.org>


Mime
View raw message