FileDocCategorySizeDatePackage
AttributeVector.javaAPI DocGlassfish v2 API5447Fri May 04 22:34:28 BST 2007com.sun.jdo.api.persistence.enhancer.classfile

AttributeVector

public class AttributeVector extends Object
A list of attributes within a class file. These lists occur in several places within a class file - at class level - at method level - at field level - at attribute level

Fields Summary
private ClassAttribute[]
attributes
Constructors Summary
public AttributeVector()
Construct an empty AttributeVector

 
Methods Summary
public voidaddElement(ClassAttribute attr)
Add an element to the vector

    if (attributes == null)
      attributes = new ClassAttribute[1];
    else {
      ClassAttribute newAttributes[] = new ClassAttribute[attributes.length+1];
      System.arraycopy(attributes, 0, newAttributes, 0, attributes.length);
      attributes = newAttributes;
    }
    attributes[attributes.length-1] = attr;
  
private ClassAttributeattrAt(int i)
Returns the i'th attribute in the array


            
      
    return attributes[i];
  
public java.util.Enumerationelements()

    class AttributeVectorEnumeration implements Enumeration {
      private ClassAttribute[] attributes;
      private int current = 0;

      AttributeVectorEnumeration(ClassAttribute attrs[]) {
	attributes = attrs;
      }

      public boolean hasMoreElements() {
	return attributes != null && current < attributes.length;
      }
      public Object nextElement() {
	if (!hasMoreElements())
	  throw new NoSuchElementException();
	return attributes[current++];
      }
    }

    return new AttributeVectorEnumeration(attributes);
  
public ClassAttributefindAttribute(java.lang.String attrName)
Look for an attribute of a specific name

    Enumeration e = elements();
    while (e.hasMoreElements()) {
      ClassAttribute attr = (ClassAttribute) e.nextElement();
      if (attr.attrName().asString().equals(attrName))
	return attr;
    }
    return null;
  
voidprint(java.io.PrintStream out, int indent)
Print a description of the attributes

    if (attributes != null) {
      for (int i=0; i<attributes.length; i++)
	attributes[i].print(out, indent);
    }
  
static com.sun.jdo.api.persistence.enhancer.classfile.AttributeVectorreadAttributes(java.io.DataInputStream data, ConstantPool constantPool)
General attribute reader

    AttributeVector attribs = new AttributeVector();
    int n_attrs = data.readUnsignedShort();
    while (n_attrs-- > 0) {
      attribs.addElement(ClassAttribute.read(data, constantPool));
    }
    return attribs;
  
static com.sun.jdo.api.persistence.enhancer.classfile.AttributeVectorreadAttributes(java.io.DataInputStream data, CodeEnv codeEnv)
ClassMethod attribute reader

    AttributeVector attribs = new AttributeVector();
    int n_attrs = data.readUnsignedShort();
    while (n_attrs-- > 0) {
      attribs.addElement(ClassAttribute.read(data, codeEnv));
    }
    return attribs;
  
voidsummarize()
Print a brief summary of the attributes

    System.out.println((attributes == null ? 0 : attributes.length) +
		       " attributes");//NOI18N
  
voidwrite(java.io.DataOutputStream out)
Write the attributes to the output stream

    if (attributes == null) {
      out.writeShort(0);
    } else {
      out.writeShort(attributes.length);
      for (int i=0; i<attributes.length; i++)
	attributes[i].write(out);
    }