mjc

org.multijava.util.classfile
Class AttributeList

java.lang.Object
  extended byorg.multijava.util.classfile.AttributeList

public class AttributeList
extends Object

This class represents a list of attributes within a ClassInfo structure (see JVM2, 4.7). This class also includes static helper methods for parsing attributes from .class files. This parsing is done using the chain-of-responsibility pattern. See the Attribute class for a sample member of the chain.


Nested Class Summary
static class AttributeList.ParserIterator
          This nested class implements a specialized iterator that returns successive parsers from the chain-of-responsibility and keeps clients from having to perform casts.
 
Field Summary
private  Attribute[] attributes
           
private static LinkedList attrParsers
           
static Attribute[] EMPTY
           
 
Constructor Summary
  AttributeList()
          Constructs an empty attribute list
(package private) AttributeList(DataInput in, ConstantPool cp, boolean noCode)
          Constructs an attribute list from a class file stream
(package private) AttributeList(DataInput in, ConstantPool cp, Instruction[] insns)
          Constructs an sub-attribute list of CodeInfo from a class file stream
  AttributeList(Attribute att1)
          Constructs a one element attribute list
  AttributeList(Attribute att1, Attribute att2)
          Constructs a two elements attribute list
  AttributeList(Attribute att1, Attribute att2, Attribute att3)
          Constructs a three elements attribute list
  AttributeList(Attribute att1, Attribute att2, Attribute att3, Attribute att4)
          Constructs a four elements attribute list
 
Method Summary
 void add(Attribute attr)
          Adds an attribute to the list of attributes
static void addParser(AttributeParser prsr)
          Adds the given AttributeParser to the head of the chain-of-responsibility.
 Attribute get(int tag)
          Return the first attribute for this tag
(package private)  int getSize()
          Returns the space in bytes used by this attribute in the classfile
 boolean isEmpty()
           
static AttributeList.ParserIterator parserIterator()
          Returns a specialized iterator that returns successive parsers from the chain-of-responsibility.
(package private) static Attribute read(DataInput in, ConstantPool cp)
          This method calls each member of the attribute parsing chain-of-responsibility in order to read the next attribute in the given input stream.
(package private) static Attribute readCodeInfoAttribute(DataInput in, ConstantPool cp, Instruction[] insns)
          This method calls each member of the attribute parsing chain-of-responsibility, in order, to read the next CodeInfo attribute in the given input stream.
(package private) static Attribute readInterfaceOnly(DataInput in, ConstantPool cp)
          This method calls each member of the attribute parsing chain-of-responsibility in order to read the next attribute in the given input stream.
(package private)  boolean remove(int tag)
          Removes an attribute from the list of attributes
static void removeAllParsers()
          Removes all parsers, including the default tail element BaseAttributeParser, from the chain-of-responsibility.
static void removeParser(AttributeParser prsr)
          Removes the given parser from the chain-of-responsibility.
static void resetParsers()
          Resets the chain-of-responsibility to just include the default tail element BaseAttributeParser.
(package private)  void resolveConstants(ConstantPool cp)
          Insert or check location of constant values in constant pool
(package private)  void write(ConstantPool cp, DataOutput out)
          Write this class into the the file (out) getting data position from the constant pool
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributes

private Attribute[] attributes

attrParsers

private static final LinkedList attrParsers

EMPTY

public static final Attribute[] EMPTY
Constructor Detail

AttributeList

public AttributeList()
Constructs an empty attribute list


AttributeList

public AttributeList(Attribute att1)
Constructs a one element attribute list


AttributeList

public AttributeList(Attribute att1,
                     Attribute att2)
Constructs a two elements attribute list


AttributeList

public AttributeList(Attribute att1,
                     Attribute att2,
                     Attribute att3)
Constructs a three elements attribute list


AttributeList

public AttributeList(Attribute att1,
                     Attribute att2,
                     Attribute att3,
                     Attribute att4)
Constructs a four elements attribute list


AttributeList

AttributeList(DataInput in,
              ConstantPool cp,
              boolean noCode)
        throws IOException,
               ClassFileFormatException
Constructs an attribute list from a class file stream

Parameters:
in - the stream to read from
cp - the constant pool
noCode - do not read code attribute
Throws:
IOException - an io problem has occured
ClassFileFormatException - attempt to write a bad classfile info

AttributeList

AttributeList(DataInput in,
              ConstantPool cp,
              Instruction[] insns)
        throws IOException,
               ClassFileFormatException
Constructs an sub-attribute list of CodeInfo from a class file stream

Parameters:
in - the stream to read from
cp - the constant pool
insns - (sparse) array of instructions
Throws:
IOException - an io problem has occured
ClassFileFormatException - attempt to write a bad classfile info
Method Detail

read

static Attribute read(DataInput in,
                      ConstantPool cp)
               throws IOException,
                      ClassFileFormatException
This method calls each member of the attribute parsing chain-of-responsibility in order to read the next attribute in the given input stream. Once a member of the chain matches no additional members are called. If no member matches then returns a GenericAttribute.

Throws:
IOException
ClassFileFormatException

readInterfaceOnly

static Attribute readInterfaceOnly(DataInput in,
                                   ConstantPool cp)
                            throws IOException,
                                   ClassFileFormatException
This method calls each member of the attribute parsing chain-of-responsibility in order to read the next attribute in the given input stream. Once a member of the chain matches no additional members are called. If no member matches then returns a GenericAttribute.

Throws:
IOException
ClassFileFormatException

readCodeInfoAttribute

static Attribute readCodeInfoAttribute(DataInput in,
                                       ConstantPool cp,
                                       Instruction[] insns)
                                throws IOException,
                                       ClassFileFormatException
This method calls each member of the attribute parsing chain-of-responsibility, in order, to read the next CodeInfo attribute in the given input stream. Once a member of the chain matches no additional members are called. If no member matches then returns a GenericAttribute.

Throws:
IOException
ClassFileFormatException

addParser

public static void addParser(AttributeParser prsr)
Adds the given AttributeParser to the head of the chain-of-responsibility.


removeParser

public static void removeParser(AttributeParser prsr)
Removes the given parser from the chain-of-responsibility.


removeAllParsers

public static void removeAllParsers()
Removes all parsers, including the default tail element BaseAttributeParser, from the chain-of-responsibility.


resetParsers

public static void resetParsers()
Resets the chain-of-responsibility to just include the default tail element BaseAttributeParser.


parserIterator

public static AttributeList.ParserIterator parserIterator()
Returns a specialized iterator that returns successive parsers from the chain-of-responsibility.


isEmpty

public boolean isEmpty()

get

public final Attribute get(int tag)
Return the first attribute for this tag

Parameters:
tag - the tag that identifies the attribute

add

public final void add(Attribute attr)
Adds an attribute to the list of attributes

Parameters:
attr - the attribute to add to the list, for convenience the argument may be null in which case this does nothing

remove

final boolean remove(int tag)
Removes an attribute from the list of attributes

Parameters:
tag - the tag that identifies the attribute
Returns:
true iff an attribute with given tag was in the list

getSize

int getSize()
Returns the space in bytes used by this attribute in the classfile


resolveConstants

void resolveConstants(ConstantPool cp)
                throws ClassFileFormatException
Insert or check location of constant values in constant pool

Parameters:
cp - the constant pool for this class
Throws:
ClassFileFormatException

write

void write(ConstantPool cp,
           DataOutput out)
     throws IOException,
            ClassFileFormatException
Write this class into the the file (out) getting data position from the constant pool

Parameters:
cp - the constant pool that contain all data
out - the file where to write this object info
Throws:
IOException - an io problem has occured
ClassFileFormatException - attempt to write a bad classfile info

mjc

mjc is Copyright (C) 2000-2004 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. mjc is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.