org.objectweb.asm.xml

Class ASMContentHandler

public class ASMContentHandler extends DefaultHandler implements Opcodes

A org.xml.sax.ContentHandler ContentHandler that transforms XML document into Java class file. This class can be feeded by any kind of SAX 2.0 event producers, e.g. XML parser, XSLT or XPath engines, or custom code.

Author: Eugene Kuleshov

See Also: SAXClassAdapter

Nested Class Summary
protected abstract classASMContentHandler.Rule
Rule
Field Summary
protected booleancomputeMax
true if the maximum stack size and number of local variables must be automatically computed.
protected ClassWritercw
Current instance of the ClassWriter used to write class bytecode.
protected Maplabels
Map of the active Label instances for current method.
protected OutputStreamos
Output stream to write result bytecode.
Constructor Summary
ASMContentHandler(OutputStream os, boolean computeMax)
Constructs a new ASMContentHandler object.
Method Summary
voidendDocument()
Process notification of the end of a document and write generated bytecode into output stream.
voidendElement(String ns, String lName, String qName)
Process notification of the end of an XML element being reached.
voidstartElement(String ns, String lName, String qName, Attributes list)
Process notification of the start of an XML element being reached.
byte[]toByteArray()
Returns the bytecode of the class that was build with underneath class writer.

Field Detail

computeMax

protected boolean computeMax
true if the maximum stack size and number of local variables must be automatically computed.

cw

protected ClassWriter cw
Current instance of the ClassWriter used to write class bytecode.

labels

protected Map labels
Map of the active Label instances for current method.

os

protected OutputStream os
Output stream to write result bytecode.

Constructor Detail

ASMContentHandler

public ASMContentHandler(OutputStream os, boolean computeMax)
Constructs a new ASMContentHandler object.

Parameters: os output stream to write generated class. computeMax true if the maximum stack size and the maximum number of local variables must be automatically computed. This value is passed to ClassWriter instance.

Method Detail

endDocument

public final void endDocument()
Process notification of the end of a document and write generated bytecode into output stream.

Throws: SAXException if parsing or writing error is to be reported.

endElement

public final void endElement(String ns, String lName, String qName)
Process notification of the end of an XML element being reached.

Parameters: ns - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed. lName - The local name (without prefix), or the empty string if Namespace processing is not being performed. qName - The qualified XML 1.0 name (with prefix), or the empty string if qualified names are not available.

Throws: SAXException if a parsing error is to be reported

startElement

public final void startElement(String ns, String lName, String qName, Attributes list)
Process notification of the start of an XML element being reached.

Parameters: ns - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed. lName - The local name (without prefix), or the empty string if Namespace processing is not being performed. qName - The qualified name (with prefix), or the empty string if qualified names are not available. list - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.

Throws: SAXException if a parsing error is to be reported

toByteArray

public byte[] toByteArray()
Returns the bytecode of the class that was build with underneath class writer.

Returns: the bytecode of the class that was build with underneath class writer or null if there are no classwriter created.