FileDocCategorySizeDatePackage
SAXCodeAdapter.javaAPI DocGlassfish v2 API9648Thu Mar 02 11:51:20 GMT 2006oracle.toplink.libraries.asm.xml

SAXCodeAdapter

public final class SAXCodeAdapter extends Object implements CodeVisitor
A {@link oracle.toplink.libraries.asm.CodeVisitor CodeVisitor} that generates SAX 2.0 events from the visited code.
see
oracle.toplink.libraries.asm.xml.SAXClassAdapter
see
oracle.toplink.libraries.asm.xml.Processor
author
Eugene Kuleshov

Fields Summary
private ContentHandler
h
private Map
labelNames
Constructors Summary
public SAXCodeAdapter(ContentHandler h)
Constructs a new {@link SAXCodeAdapter SAXCodeAdapter} object.

param
h content handler that will be used to send SAX 2.0 events.

    this.h = h;
    labelNames = new HashMap();
  
Methods Summary
private final voidaddElement(java.lang.String name, org.xml.sax.Attributes attrs)

    addStart( name, attrs);
    addEnd( name);
  
private final voidaddEnd(java.lang.String name)

    try {
      h.endElement( "", name, name);
    } catch( SAXException ex) {
      throw new RuntimeException( ex.toString());
    }
  
private final voidaddStart(java.lang.String name, org.xml.sax.Attributes attrs)

    try {
      h.startElement( "", name, name, attrs);
    } catch( SAXException ex) {
      throw new RuntimeException( ex.toString());
    }
  
private final java.lang.StringgetLabel(oracle.toplink.libraries.asm.Label label)

    String name = (String) labelNames.get( label);
    if( name==null) {
      name = Integer.toString( labelNames.size());
      labelNames.put( label, name);
    }
    return name;
  
public final voidvisitAttribute(oracle.toplink.libraries.asm.Attribute attr)

    // TODO Auto-generated SAXCodeAdapter.visitAttribute
  
public final voidvisitFieldInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "owner", "owner", "", owner);
    attrs.addAttribute( "", "name", "name", "", name);
    attrs.addAttribute( "", "desc", "desc", "", desc);
    addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
  
public final voidvisitIincInsn(int var, int increment)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "var", "var", "", Integer.toString( var));
    attrs.addAttribute( "", "inc", "inc", "", Integer.toString( increment));
    addElement( PrintCodeVisitor.OPCODES[ Constants.IINC], attrs);
  
public final voidvisitInsn(int opcode)

    addElement( PrintCodeVisitor.OPCODES[ opcode], new AttributesImpl());
  
public final voidvisitIntInsn(int opcode, int operand)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "value", "value", "", Integer.toString( operand));
    addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
  
public final voidvisitJumpInsn(int opcode, oracle.toplink.libraries.asm.Label label)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "label", "label", "", getLabel( label));
    addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
  
public final voidvisitLabel(oracle.toplink.libraries.asm.Label label)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "name", "name", "", getLabel( label));
    addElement( "Label", attrs);
  
public final voidvisitLdcInsn(java.lang.Object cst)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "cst", "cst", "", SAXClassAdapter.encode( cst.toString()));
    attrs.addAttribute( "", "desc", "desc", "", Type.getDescriptor( cst.getClass()));
    addElement( PrintCodeVisitor.OPCODES[ Constants.LDC], attrs);
  
public final voidvisitLineNumber(int line, oracle.toplink.libraries.asm.Label start)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "line", "line", "", Integer.toString( line));
    attrs.addAttribute( "", "start", "start", "", getLabel( start));
    addElement( "LineNumber", attrs);
  
public final voidvisitLocalVariable(java.lang.String name, java.lang.String desc, oracle.toplink.libraries.asm.Label start, oracle.toplink.libraries.asm.Label end, int index)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "name", "name", "", name);
    attrs.addAttribute( "", "desc", "desc", "", desc);
    attrs.addAttribute( "", "start", "start", "", getLabel( start));
    attrs.addAttribute( "", "end", "end", "", getLabel( end));
    attrs.addAttribute( "", "var", "var", "", Integer.toString( index));
    addElement( "LocalVar", attrs);
  
public final voidvisitLookupSwitchInsn(oracle.toplink.libraries.asm.Label dflt, int[] keys, oracle.toplink.libraries.asm.Label[] labels)

    AttributesImpl att = new AttributesImpl();
    att.addAttribute( "", "dflt", "dflt", "", getLabel( dflt));
    String o = PrintCodeVisitor.OPCODES[ Constants.LOOKUPSWITCH];
    addStart( o, att);
    for( int i = 0; i < labels.length; i++) {
      AttributesImpl att2 = new AttributesImpl();
      att2.addAttribute( "", "name", "name", "", getLabel( labels[ i]));
      att2.addAttribute( "", "key", "key", "", Integer.toString( keys[ i]));
      addElement( "label", att2);
    }
    addEnd( o);
  
public final voidvisitMaxs(int maxStack, int maxLocals)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "maxStack", "maxStack", "", Integer.toString( maxStack));
    attrs.addAttribute( "", "maxLocals", "maxLocals", "", Integer.toString( maxLocals));
    addElement( "Max", attrs);

    addEnd( "code");
    addEnd( "method");
    // TODO ensure it it is ok to close method element here
  
public final voidvisitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "owner", "owner", "", owner);
    attrs.addAttribute( "", "name", "name", "", name);
    attrs.addAttribute( "", "desc", "desc", "", desc);
    addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
  
public final voidvisitMultiANewArrayInsn(java.lang.String desc, int dims)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "desc", "desc", "", desc);
    attrs.addAttribute( "", "dims", "dims", "", Integer.toString( dims));
    addElement( PrintCodeVisitor.OPCODES[ Constants.MULTIANEWARRAY], attrs);
  
public final voidvisitTableSwitchInsn(int min, int max, oracle.toplink.libraries.asm.Label dflt, oracle.toplink.libraries.asm.Label[] labels)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "min", "min", "", Integer.toString( min));
    attrs.addAttribute( "", "max", "max", "", Integer.toString( max));
    attrs.addAttribute( "", "dflt", "dflt", "", getLabel( dflt));
    String o = PrintCodeVisitor.OPCODES[ Constants.TABLESWITCH];
    addStart( o, attrs);
    for( int i = 0; i < labels.length; i++) {
      AttributesImpl att2 = new AttributesImpl();
      att2.addAttribute( "", "name", "name", "", getLabel( labels[ i]));
      addElement( "label", att2);
    }
    addEnd( o);
  
public final voidvisitTryCatchBlock(oracle.toplink.libraries.asm.Label start, oracle.toplink.libraries.asm.Label end, oracle.toplink.libraries.asm.Label handler, java.lang.String type)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "start", "start", "", getLabel( start));
    attrs.addAttribute( "", "end", "end", "", getLabel( end));
    attrs.addAttribute( "", "handler", "handler", "", getLabel( handler));
    if( type!=null) attrs.addAttribute( "", "type", "type", "", type);
    addElement( "TryCatch", attrs);
  
public final voidvisitTypeInsn(int opcode, java.lang.String desc)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "desc", "desc", "", desc);
    addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);
  
public final voidvisitVarInsn(int opcode, int var)

    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute( "", "var", "var", "", Integer.toString( var));
    addElement( PrintCodeVisitor.OPCODES[ opcode], attrs);