You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by ka...@apache.org on 2014/03/20 20:23:07 UTC

[02/23] FIXED - TAP5-2214: Make tapestry5 java8 compatible - apply source from AMS 5.0 final source release and change package name to org.apache.tapestry5.internal.plastic.asm. Also made a single change to ASM source, promoted visibility of AnnotationNo

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1acd9d22/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/Processor.java
----------------------------------------------------------------------
diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/Processor.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/Processor.java
new file mode 100644
index 0000000..6d5715c
--- /dev/null
+++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/Processor.java
@@ -0,0 +1,1044 @@
+/***
+ * ASM XML Adapter
+ * Copyright (c) 2004-2011, Eugene Kuleshov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.tapestry5.internal.plastic.asm.xml;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Templates;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.tapestry5.internal.plastic.asm.ClassReader;
+import org.apache.tapestry5.internal.plastic.asm.ClassWriter;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+/**
+ * Processor is a command line tool that can be used for bytecode waving
+ * directed by XSL transformation.
+ * <p>
+ * In order to use a concrete XSLT engine, system property
+ * <tt>javax.xml.transform.TransformerFactory</tt> must be set to one of the
+ * following values.
+ * 
+ * <blockquote>
+ * <table border="1" cellspacing="0" cellpadding="3">
+ * <tr>
+ * <td>jd.xslt</td>
+ * <td>jd.xml.xslt.trax.TransformerFactoryImpl</td>
+ * </tr>
+ * 
+ * <tr>
+ * <td>Saxon</td>
+ * <td>net.sf.saxon.TransformerFactoryImpl</td>
+ * </tr>
+ * 
+ * <tr>
+ * <td>Caucho</td>
+ * <td>com.caucho.xsl.Xsl</td>
+ * </tr>
+ * 
+ * <tr>
+ * <td>Xalan interpeter</td>
+ * <td>org.apache.xalan.processor.TransformerFactory</td>
+ * </tr>
+ * 
+ * <tr>
+ * <td>Xalan xsltc</td>
+ * <td>org.apache.xalan.xsltc.trax.TransformerFactoryImpl</td>
+ * </tr>
+ * </table>
+ * </blockquote>
+ * 
+ * @author Eugene Kuleshov
+ */
+public class Processor {
+
+    public static final int BYTECODE = 1;
+
+    public static final int MULTI_XML = 2;
+
+    public static final int SINGLE_XML = 3;
+
+    private static final String SINGLE_XML_NAME = "classes.xml";
+
+    private final int inRepresentation;
+
+    private final int outRepresentation;
+
+    private final InputStream input;
+
+    private final OutputStream output;
+
+    private final Source xslt;
+
+    private int n = 0;
+
+    public Processor(final int inRepresenation, final int outRepresentation,
+            final InputStream input, final OutputStream output,
+            final Source xslt) {
+        this.inRepresentation = inRepresenation;
+        this.outRepresentation = outRepresentation;
+        this.input = input;
+        this.output = output;
+        this.xslt = xslt;
+    }
+
+    public int process() throws TransformerException, IOException, SAXException {
+        ZipInputStream zis = new ZipInputStream(input);
+        final ZipOutputStream zos = new ZipOutputStream(output);
+        final OutputStreamWriter osw = new OutputStreamWriter(zos);
+
+        Thread.currentThread().setContextClassLoader(
+                getClass().getClassLoader());
+
+        TransformerFactory tf = TransformerFactory.newInstance();
+        if (!tf.getFeature(SAXSource.FEATURE)
+                || !tf.getFeature(SAXResult.FEATURE)) {
+            return 0;
+        }
+
+        SAXTransformerFactory saxtf = (SAXTransformerFactory) tf;
+        Templates templates = null;
+        if (xslt != null) {
+            templates = saxtf.newTemplates(xslt);
+        }
+
+        // configuring outHandlerFactory
+        // ///////////////////////////////////////////////////////
+
+        EntryElement entryElement = getEntryElement(zos);
+
+        ContentHandler outDocHandler = null;
+        switch (outRepresentation) {
+        case BYTECODE:
+            outDocHandler = new OutputSlicingHandler(
+                    new ASMContentHandlerFactory(zos), entryElement, false);
+            break;
+
+        case MULTI_XML:
+            outDocHandler = new OutputSlicingHandler(new SAXWriterFactory(osw,
+                    true), entryElement, true);
+            break;
+
+        case SINGLE_XML:
+            ZipEntry outputEntry = new ZipEntry(SINGLE_XML_NAME);
+            zos.putNextEntry(outputEntry);
+            outDocHandler = new SAXWriter(osw, false);
+            break;
+
+        }
+
+        // configuring inputDocHandlerFactory
+        // /////////////////////////////////////////////////
+        ContentHandler inDocHandler;
+        if (templates == null) {
+            inDocHandler = outDocHandler;
+        } else {
+            inDocHandler = new InputSlicingHandler("class", outDocHandler,
+                    new TransformerHandlerFactory(saxtf, templates,
+                            outDocHandler));
+        }
+        ContentHandlerFactory inDocHandlerFactory = new SubdocumentHandlerFactory(
+                inDocHandler);
+
+        if (inDocHandler != null && inRepresentation != SINGLE_XML) {
+            inDocHandler.startDocument();
+            inDocHandler.startElement("", "classes", "classes",
+                    new AttributesImpl());
+        }
+
+        int i = 0;
+        ZipEntry ze;
+        while ((ze = zis.getNextEntry()) != null) {
+            update(ze.getName(), n++);
+            if (isClassEntry(ze)) {
+                processEntry(zis, ze, inDocHandlerFactory);
+            } else {
+                OutputStream os = entryElement.openEntry(getName(ze));
+                copyEntry(zis, os);
+                entryElement.closeEntry();
+            }
+
+            i++;
+        }
+
+        if (inDocHandler != null && inRepresentation != SINGLE_XML) {
+            inDocHandler.endElement("", "classes", "classes");
+            inDocHandler.endDocument();
+        }
+
+        if (outRepresentation == SINGLE_XML) {
+            zos.closeEntry();
+        }
+        zos.flush();
+        zos.close();
+
+        return i;
+    }
+
+    private void copyEntry(final InputStream is, final OutputStream os)
+            throws IOException {
+        if (outRepresentation == SINGLE_XML) {
+            return;
+        }
+
+        byte[] buff = new byte[2048];
+        int i;
+        while ((i = is.read(buff)) != -1) {
+            os.write(buff, 0, i);
+        }
+    }
+
+    private boolean isClassEntry(final ZipEntry ze) {
+        String name = ze.getName();
+        return inRepresentation == SINGLE_XML && name.equals(SINGLE_XML_NAME)
+                || name.endsWith(".class") || name.endsWith(".class.xml");
+    }
+
+    private void processEntry(final ZipInputStream zis, final ZipEntry ze,
+            final ContentHandlerFactory handlerFactory) {
+        ContentHandler handler = handlerFactory.createContentHandler();
+        try {
+
+            // if (CODE2ASM.equals(command)) { // read bytecode and process it
+            // // with TraceClassVisitor
+            // ClassReader cr = new ClassReader(readEntry(zis, ze));
+            // cr.accept(new TraceClassVisitor(null, new PrintWriter(os)),
+            // false);
+            // }
+
+            boolean singleInputDocument = inRepresentation == SINGLE_XML;
+            if (inRepresentation == BYTECODE) { // read bytecode and process it
+                // with handler
+                ClassReader cr = new ClassReader(readEntry(zis, ze));
+                cr.accept(new SAXClassAdapter(handler, singleInputDocument), 0);
+
+            } else { // read XML and process it with handler
+                XMLReader reader = XMLReaderFactory.createXMLReader();
+                reader.setContentHandler(handler);
+                reader.parse(new InputSource(
+                        singleInputDocument ? (InputStream) new ProtectedInputStream(
+                                zis) : new ByteArrayInputStream(readEntry(zis,
+                                ze))));
+
+            }
+        } catch (Exception ex) {
+            update(ze.getName(), 0);
+            update(ex, 0);
+        }
+    }
+
+    private EntryElement getEntryElement(final ZipOutputStream zos) {
+        if (outRepresentation == SINGLE_XML) {
+            return new SingleDocElement(zos);
+        }
+        return new ZipEntryElement(zos);
+    }
+
+    // private ContentHandlerFactory getHandlerFactory(
+    // OutputStream os,
+    // SAXTransformerFactory saxtf,
+    // Templates templates)
+    // {
+    // ContentHandlerFactory factory = null;
+    // if (templates == null) {
+    // if (outputRepresentation == BYTECODE) { // factory used to write
+    // // bytecode
+    // factory = new ASMContentHandlerFactory(os, computeMax);
+    // } else { // factory used to write XML
+    // factory = new SAXWriterFactory(os, true);
+    // }
+    // } else {
+    // if (outputRepresentation == BYTECODE) { // factory used to transform
+    // // and then write bytecode
+    // factory = new ASMTransformerHandlerFactory(saxtf,
+    // templates,
+    // os,
+    // computeMax);
+    // } else { // factory used to transformand then write XML
+    // factory = new TransformerHandlerFactory(saxtf,
+    // templates,
+    // os,
+    // outputRepresentation == SINGLE_XML);
+    // }
+    // }
+    // return factory;
+    // }
+
+    private String getName(final ZipEntry ze) {
+        String name = ze.getName();
+        if (isClassEntry(ze)) {
+            if (inRepresentation != BYTECODE && outRepresentation == BYTECODE) {
+                name = name.substring(0, name.length() - 4); // .class.xml to
+                // .class
+            } else if (inRepresentation == BYTECODE
+                    && outRepresentation != BYTECODE) {
+                name += ".xml"; // .class to .class.xml
+            }
+            // } else if( CODE2ASM.equals( command)) {
+            // name = name.substring( 0, name.length()-6).concat( ".asm");
+        }
+        return name;
+    }
+
+    private static byte[] readEntry(final InputStream zis, final ZipEntry ze)
+            throws IOException {
+        long size = ze.getSize();
+        if (size > -1) {
+            byte[] buff = new byte[(int) size];
+            int k = 0;
+            int n;
+            while ((n = zis.read(buff, k, buff.length - k)) > 0) {
+                k += n;
+            }
+            return buff;
+        }
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        byte[] buff = new byte[4096];
+        int i;
+        while ((i = zis.read(buff)) != -1) {
+            bos.write(buff, 0, i);
+        }
+        return bos.toByteArray();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
+     */
+    protected void update(final Object arg, final int n) {
+        if (arg instanceof Throwable) {
+            ((Throwable) arg).printStackTrace();
+        } else {
+            if (n % 100 == 0) {
+                System.err.println(n + " " + arg);
+            }
+        }
+    }
+
+    public static void main(final String[] args) throws Exception {
+        if (args.length < 2) {
+            showUsage();
+            return;
+        }
+
+        int inRepresentation = getRepresentation(args[0]);
+        int outRepresentation = getRepresentation(args[1]);
+
+        InputStream is = System.in;
+        OutputStream os = new BufferedOutputStream(System.out);
+
+        Source xslt = null;
+        // boolean computeMax = true;
+
+        for (int i = 2; i < args.length; i++) {
+            if ("-in".equals(args[i])) {
+                is = new FileInputStream(args[++i]);
+
+            } else if ("-out".equals(args[i])) {
+                os = new BufferedOutputStream(new FileOutputStream(args[++i]));
+
+            } else if ("-xslt".equals(args[i])) {
+                xslt = new StreamSource(new FileInputStream(args[++i]));
+
+                // } else if( "-computemax".equals( args[ i].toLowerCase())) {
+                // computeMax = true;
+
+            } else {
+                showUsage();
+                return;
+
+            }
+        }
+
+        if (inRepresentation == 0 || outRepresentation == 0) {
+            showUsage();
+            return;
+        }
+
+        Processor m = new Processor(inRepresentation, outRepresentation, is,
+                os, xslt);
+
+        long l1 = System.currentTimeMillis();
+        int n = m.process();
+        long l2 = System.currentTimeMillis();
+        System.err.println(n);
+        System.err.println((l2 - l1) + "ms  " + 1000f * n / (l2 - l1)
+                + " resources/sec");
+    }
+
+    private static int getRepresentation(final String s) {
+        if ("code".equals(s)) {
+            return BYTECODE;
+        } else if ("xml".equals(s)) {
+            return MULTI_XML;
+        } else if ("singlexml".equals(s)) {
+            return SINGLE_XML;
+        }
+        return 0;
+    }
+
+    private static void showUsage() {
+        System.err
+                .println("Usage: Main <in format> <out format> [-in <input jar>] [-out <output jar>] [-xslt <xslt fiel>]");
+        System.err
+                .println("  when -in or -out is omitted sysin and sysout would be used");
+        System.err
+                .println("  <in format> and <out format> - code | xml | singlexml");
+    }
+
+    /**
+     * IputStream wrapper class used to protect input streams from being closed
+     * by some stupid XML parsers.
+     */
+    private static final class ProtectedInputStream extends InputStream {
+        private final InputStream is;
+
+        ProtectedInputStream(final InputStream is) {
+            this.is = is;
+        }
+
+        @Override
+        public final void close() throws IOException {
+        }
+
+        @Override
+        public final int read() throws IOException {
+            return is.read();
+        }
+
+        @Override
+        public final int read(final byte[] b, final int off, final int len)
+                throws IOException {
+            return is.read(b, off, len);
+        }
+
+        @Override
+        public final int available() throws IOException {
+            return is.available();
+        }
+    }
+
+    /**
+     * A {@link ContentHandlerFactory ContentHandlerFactory} is used to create
+     * {@link org.xml.sax.ContentHandler ContentHandler} instances for concrete
+     * context.
+     */
+    private static interface ContentHandlerFactory {
+
+        /**
+         * Creates an instance of the content handler.
+         * 
+         * @return content handler
+         */
+        ContentHandler createContentHandler();
+
+    }
+
+    /**
+     * SAXWriterFactory
+     */
+    private static final class SAXWriterFactory implements
+            ContentHandlerFactory {
+        private final Writer w;
+
+        private final boolean optimizeEmptyElements;
+
+        SAXWriterFactory(final Writer w, final boolean optimizeEmptyElements) {
+            this.w = w;
+            this.optimizeEmptyElements = optimizeEmptyElements;
+        }
+
+        public final ContentHandler createContentHandler() {
+            return new SAXWriter(w, optimizeEmptyElements);
+        }
+
+    }
+
+    /**
+     * ASMContentHandlerFactory
+     */
+    private static final class ASMContentHandlerFactory implements
+            ContentHandlerFactory {
+        final OutputStream os;
+
+        ASMContentHandlerFactory(final OutputStream os) {
+            this.os = os;
+        }
+
+        public final ContentHandler createContentHandler() {
+            final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
+            return new ASMContentHandler(cw) {
+                @Override
+                public void endDocument() throws SAXException {
+                    try {
+                        os.write(cw.toByteArray());
+                    } catch (IOException e) {
+                        throw new SAXException(e);
+                    }
+                }
+            };
+        }
+
+    }
+
+    /**
+     * TransformerHandlerFactory
+     */
+    private static final class TransformerHandlerFactory implements
+            ContentHandlerFactory {
+        private SAXTransformerFactory saxtf;
+
+        private final Templates templates;
+
+        private ContentHandler outputHandler;
+
+        TransformerHandlerFactory(final SAXTransformerFactory saxtf,
+                final Templates templates, final ContentHandler outputHandler) {
+            this.saxtf = saxtf;
+            this.templates = templates;
+            this.outputHandler = outputHandler;
+        }
+
+        public final ContentHandler createContentHandler() {
+            try {
+                TransformerHandler handler = saxtf
+                        .newTransformerHandler(templates);
+                handler.setResult(new SAXResult(outputHandler));
+                return handler;
+            } catch (TransformerConfigurationException ex) {
+                throw new RuntimeException(ex.toString());
+            }
+        }
+    }
+
+    /**
+     * SubdocumentHandlerFactory
+     */
+    private static final class SubdocumentHandlerFactory implements
+            ContentHandlerFactory {
+        private final ContentHandler subdocumentHandler;
+
+        SubdocumentHandlerFactory(final ContentHandler subdocumentHandler) {
+            this.subdocumentHandler = subdocumentHandler;
+        }
+
+        public final ContentHandler createContentHandler() {
+            return subdocumentHandler;
+        }
+
+    }
+
+    /**
+     * A {@link org.xml.sax.ContentHandler ContentHandler} and
+     * {@link org.xml.sax.ext.LexicalHandler LexicalHandler} that serializes XML
+     * from SAX 2.0 events into {@link java.io.Writer Writer}.
+     * 
+     * <i><blockquote> This implementation does not support namespaces, entity
+     * definitions (uncluding DTD), CDATA and text elements. </blockquote></i>
+     */
+    private static final class SAXWriter extends DefaultHandler implements
+            LexicalHandler {
+        private static final char[] OFF = "                                                                                                        "
+                .toCharArray();
+
+        private Writer w;
+
+        private final boolean optimizeEmptyElements;
+
+        private boolean openElement = false;
+
+        private int ident = 0;
+
+        /**
+         * Creates <code>SAXWriter</code>.
+         * 
+         * @param w
+         *            writer
+         * @param optimizeEmptyElements
+         *            if set to <code>true</code>, short XML syntax will be used
+         *            for empty elements
+         */
+        SAXWriter(final Writer w, final boolean optimizeEmptyElements) {
+            this.w = w;
+            this.optimizeEmptyElements = optimizeEmptyElements;
+        }
+
+        @Override
+        public final void startElement(final String ns, final String localName,
+                final String qName, final Attributes atts) throws SAXException {
+            try {
+                closeElement();
+
+                writeIdent();
+                w.write('<' + qName);
+                if (atts != null && atts.getLength() > 0) {
+                    writeAttributes(atts);
+                }
+
+                if (optimizeEmptyElements) {
+                    openElement = true;
+                } else {
+                    w.write(">\n");
+                }
+                ident += 2;
+
+            } catch (IOException ex) {
+                throw new SAXException(ex);
+
+            }
+        }
+
+        @Override
+        public final void endElement(final String ns, final String localName,
+                final String qName) throws SAXException {
+            ident -= 2;
+            try {
+                if (openElement) {
+                    w.write("/>\n");
+                    openElement = false;
+                } else {
+                    writeIdent();
+                    w.write("</" + qName + ">\n");
+                }
+
+            } catch (IOException ex) {
+                throw new SAXException(ex);
+
+            }
+        }
+
+        @Override
+        public final void endDocument() throws SAXException {
+            try {
+                w.flush();
+
+            } catch (IOException ex) {
+                throw new SAXException(ex);
+
+            }
+        }
+
+        public final void comment(final char[] ch, final int off, final int len)
+                throws SAXException {
+            try {
+                closeElement();
+
+                writeIdent();
+                w.write("<!-- ");
+                w.write(ch, off, len);
+                w.write(" -->\n");
+
+            } catch (IOException ex) {
+                throw new SAXException(ex);
+
+            }
+        }
+
+        public final void startDTD(final String arg0, final String arg1,
+                final String arg2) throws SAXException {
+        }
+
+        public final void endDTD() throws SAXException {
+        }
+
+        public final void startEntity(final String arg0) throws SAXException {
+        }
+
+        public final void endEntity(final String arg0) throws SAXException {
+        }
+
+        public final void startCDATA() throws SAXException {
+        }
+
+        public final void endCDATA() throws SAXException {
+        }
+
+        private final void writeAttributes(final Attributes atts)
+                throws IOException {
+            StringBuffer sb = new StringBuffer();
+            int len = atts.getLength();
+            for (int i = 0; i < len; i++) {
+                sb.append(' ').append(atts.getLocalName(i)).append("=\"")
+                        .append(esc(atts.getValue(i))).append('\"');
+            }
+            w.write(sb.toString());
+        }
+
+        /**
+         * Encode string with escaping.
+         * 
+         * @param str
+         *            string to encode.
+         * @return encoded string
+         */
+        private static final String esc(final String str) {
+            StringBuffer sb = new StringBuffer(str.length());
+            for (int i = 0; i < str.length(); i++) {
+                char ch = str.charAt(i);
+                switch (ch) {
+                case '&':
+                    sb.append("&amp;");
+                    break;
+
+                case '<':
+                    sb.append("&lt;");
+                    break;
+
+                case '>':
+                    sb.append("&gt;");
+                    break;
+
+                case '\"':
+                    sb.append("&quot;");
+                    break;
+
+                default:
+                    if (ch > 0x7f) {
+                        sb.append("&#").append(Integer.toString(ch))
+                                .append(';');
+                    } else {
+                        sb.append(ch);
+                    }
+
+                }
+            }
+            return sb.toString();
+        }
+
+        private final void writeIdent() throws IOException {
+            int n = ident;
+            while (n > 0) {
+                if (n > OFF.length) {
+                    w.write(OFF);
+                    n -= OFF.length;
+                } else {
+                    w.write(OFF, 0, n);
+                    n = 0;
+                }
+            }
+        }
+
+        private final void closeElement() throws IOException {
+            if (openElement) {
+                w.write(">\n");
+            }
+            openElement = false;
+        }
+
+    }
+
+    /**
+     * A {@link org.xml.sax.ContentHandler ContentHandler} that splits XML
+     * documents into smaller chunks. Each chunk is processed by the nested
+     * {@link org.xml.sax.ContentHandler ContentHandler} obtained from
+     * {@link java.net.ContentHandlerFactory ContentHandlerFactory}. This is
+     * useful for running XSLT engine against large XML document that will
+     * hardly fit into the memory all together.
+     * <p>
+     * TODO use complete path for subdocumentRoot
+     */
+    private static final class InputSlicingHandler extends DefaultHandler {
+        private String subdocumentRoot;
+
+        private final ContentHandler rootHandler;
+
+        private ContentHandlerFactory subdocumentHandlerFactory;
+
+        private boolean subdocument = false;
+
+        private ContentHandler subdocumentHandler;
+
+        /**
+         * Constructs a new {@link InputSlicingHandler SubdocumentHandler}
+         * object.
+         * 
+         * @param subdocumentRoot
+         *            name/path to the root element of the subdocument
+         * @param rootHandler
+         *            content handler for the entire document (subdocument
+         *            envelope).
+         * @param subdocumentHandlerFactory
+         *            a {@link ContentHandlerFactory ContentHandlerFactory} used
+         *            to create {@link ContentHandler ContentHandler} instances
+         *            for subdocuments.
+         */
+        InputSlicingHandler(final String subdocumentRoot,
+                final ContentHandler rootHandler,
+                final ContentHandlerFactory subdocumentHandlerFactory) {
+            this.subdocumentRoot = subdocumentRoot;
+            this.rootHandler = rootHandler;
+            this.subdocumentHandlerFactory = subdocumentHandlerFactory;
+        }
+
+        @Override
+        public final void startElement(final String namespaceURI,
+                final String localName, final String qName,
+                final Attributes list) throws SAXException {
+            if (subdocument) {
+                subdocumentHandler.startElement(namespaceURI, localName, qName,
+                        list);
+            } else if (localName.equals(subdocumentRoot)) {
+                subdocumentHandler = subdocumentHandlerFactory
+                        .createContentHandler();
+                subdocumentHandler.startDocument();
+                subdocumentHandler.startElement(namespaceURI, localName, qName,
+                        list);
+                subdocument = true;
+            } else if (rootHandler != null) {
+                rootHandler.startElement(namespaceURI, localName, qName, list);
+            }
+        }
+
+        @Override
+        public final void endElement(final String namespaceURI,
+                final String localName, final String qName) throws SAXException {
+            if (subdocument) {
+                subdocumentHandler.endElement(namespaceURI, localName, qName);
+                if (localName.equals(subdocumentRoot)) {
+                    subdocumentHandler.endDocument();
+                    subdocument = false;
+                }
+            } else if (rootHandler != null) {
+                rootHandler.endElement(namespaceURI, localName, qName);
+            }
+        }
+
+        @Override
+        public final void startDocument() throws SAXException {
+            if (rootHandler != null) {
+                rootHandler.startDocument();
+            }
+        }
+
+        @Override
+        public final void endDocument() throws SAXException {
+            if (rootHandler != null) {
+                rootHandler.endDocument();
+
+            }
+        }
+
+        @Override
+        public final void characters(final char[] buff, final int offset,
+                final int size) throws SAXException {
+            if (subdocument) {
+                subdocumentHandler.characters(buff, offset, size);
+            } else if (rootHandler != null) {
+                rootHandler.characters(buff, offset, size);
+            }
+        }
+
+    }
+
+    /**
+     * A {@link org.xml.sax.ContentHandler ContentHandler} that splits XML
+     * documents into smaller chunks. Each chunk is processed by the nested
+     * {@link org.xml.sax.ContentHandler ContentHandler} obtained from
+     * {@link java.net.ContentHandlerFactory ContentHandlerFactory}. This is
+     * useful for running XSLT engine against large XML document that will
+     * hardly fit into the memory all together.
+     * 
+     * <p>
+     * TODO use complete path for subdocumentRoot
+     */
+    private static final class OutputSlicingHandler extends DefaultHandler {
+        private final String subdocumentRoot;
+
+        private ContentHandlerFactory subdocumentHandlerFactory;
+
+        private final EntryElement entryElement;
+
+        private boolean isXml;
+
+        private boolean subdocument = false;
+
+        private ContentHandler subdocumentHandler;
+
+        /**
+         * Constructs a new {@link OutputSlicingHandler SubdocumentHandler}
+         * object.
+         * 
+         * @param subdocumentHandlerFactory
+         *            a {@link ContentHandlerFactory ContentHandlerFactory} used
+         *            to create {@link ContentHandler ContentHandler} instances
+         *            for subdocuments.
+         * @param entryElement
+         *            TODO.
+         * @param isXml
+         *            TODO.
+         */
+        OutputSlicingHandler(
+                final ContentHandlerFactory subdocumentHandlerFactory,
+                final EntryElement entryElement, final boolean isXml) {
+            this.subdocumentRoot = "class";
+            this.subdocumentHandlerFactory = subdocumentHandlerFactory;
+            this.entryElement = entryElement;
+            this.isXml = isXml;
+        }
+
+        @Override
+        public final void startElement(final String namespaceURI,
+                final String localName, final String qName,
+                final Attributes list) throws SAXException {
+            if (subdocument) {
+                subdocumentHandler.startElement(namespaceURI, localName, qName,
+                        list);
+            } else if (localName.equals(subdocumentRoot)) {
+                String name = list.getValue("name");
+                if (name == null || name.length() == 0) {
+                    throw new SAXException(
+                            "Class element without name attribute.");
+                }
+                try {
+                    entryElement.openEntry(isXml ? name + ".class.xml" : name
+                            + ".class");
+                } catch (IOException ex) {
+                    throw new SAXException(ex.toString(), ex);
+                }
+                subdocumentHandler = subdocumentHandlerFactory
+                        .createContentHandler();
+                subdocumentHandler.startDocument();
+                subdocumentHandler.startElement(namespaceURI, localName, qName,
+                        list);
+                subdocument = true;
+            }
+        }
+
+        @Override
+        public final void endElement(final String namespaceURI,
+                final String localName, final String qName) throws SAXException {
+            if (subdocument) {
+                subdocumentHandler.endElement(namespaceURI, localName, qName);
+                if (localName.equals(subdocumentRoot)) {
+                    subdocumentHandler.endDocument();
+                    subdocument = false;
+                    try {
+                        entryElement.closeEntry();
+                    } catch (IOException ex) {
+                        throw new SAXException(ex.toString(), ex);
+                    }
+                }
+            }
+        }
+
+        @Override
+        public final void startDocument() throws SAXException {
+        }
+
+        @Override
+        public final void endDocument() throws SAXException {
+        }
+
+        @Override
+        public final void characters(final char[] buff, final int offset,
+                final int size) throws SAXException {
+            if (subdocument) {
+                subdocumentHandler.characters(buff, offset, size);
+            }
+        }
+
+    }
+
+    private static interface EntryElement {
+
+        OutputStream openEntry(String name) throws IOException;
+
+        void closeEntry() throws IOException;
+
+    }
+
+    private static final class SingleDocElement implements EntryElement {
+        private final OutputStream os;
+
+        SingleDocElement(final OutputStream os) {
+            this.os = os;
+        }
+
+        public OutputStream openEntry(final String name) throws IOException {
+            return os;
+        }
+
+        public void closeEntry() throws IOException {
+            os.flush();
+        }
+
+    }
+
+    private static final class ZipEntryElement implements EntryElement {
+        private ZipOutputStream zos;
+
+        ZipEntryElement(final ZipOutputStream zos) {
+            this.zos = zos;
+        }
+
+        public OutputStream openEntry(final String name) throws IOException {
+            ZipEntry entry = new ZipEntry(name);
+            zos.putNextEntry(entry);
+            return zos;
+        }
+
+        public void closeEntry() throws IOException {
+            zos.flush();
+            zos.closeEntry();
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1acd9d22/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXAdapter.java
----------------------------------------------------------------------
diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXAdapter.java
new file mode 100644
index 0000000..2f49c24
--- /dev/null
+++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXAdapter.java
@@ -0,0 +1,89 @@
+/***
+ * ASM XML Adapter
+ * Copyright (c) 2004-2011, Eugene Kuleshov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.tapestry5.internal.plastic.asm.xml;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * SAXAdapter
+ * 
+ * @author Eugene Kuleshov
+ */
+public class SAXAdapter {
+
+    private final ContentHandler h;
+
+    protected SAXAdapter(final ContentHandler h) {
+        this.h = h;
+    }
+
+    protected ContentHandler getContentHandler() {
+        return h;
+    }
+
+    protected void addDocumentStart() {
+        try {
+            h.startDocument();
+        } catch (SAXException ex) {
+            throw new RuntimeException(ex.getMessage(), ex.getException());
+        }
+    }
+
+    protected void addDocumentEnd() {
+        try {
+            h.endDocument();
+        } catch (SAXException ex) {
+            throw new RuntimeException(ex.getMessage(), ex.getException());
+        }
+    }
+
+    protected final void addStart(final String name, final Attributes attrs) {
+        try {
+            h.startElement("", name, name, attrs);
+        } catch (SAXException ex) {
+            throw new RuntimeException(ex.getMessage(), ex.getException());
+        }
+    }
+
+    protected final void addEnd(final String name) {
+        try {
+            h.endElement("", name, name);
+        } catch (SAXException ex) {
+            throw new RuntimeException(ex.getMessage(), ex.getException());
+        }
+    }
+
+    protected final void addElement(final String name, final Attributes attrs) {
+        addStart(name, attrs);
+        addEnd(name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1acd9d22/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXAnnotationAdapter.java
----------------------------------------------------------------------
diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXAnnotationAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXAnnotationAdapter.java
new file mode 100644
index 0000000..491c57e
--- /dev/null
+++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXAnnotationAdapter.java
@@ -0,0 +1,242 @@
+/***
+ * ASM XML Adapter
+ * Copyright (c) 2004-2011, Eugene Kuleshov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.tapestry5.internal.plastic.asm.xml;
+
+import org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor;
+import org.apache.tapestry5.internal.plastic.asm.Opcodes;
+import org.apache.tapestry5.internal.plastic.asm.Type;
+import org.apache.tapestry5.internal.plastic.asm.TypePath;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * SAXAnnotationAdapter
+ * 
+ * @author Eugene Kuleshov
+ */
+public final class SAXAnnotationAdapter extends AnnotationVisitor {
+
+    SAXAdapter sa;
+
+    private final String elementName;
+
+    public SAXAnnotationAdapter(final SAXAdapter sa, final String elementName,
+            final int visible, final String name, final String desc) {
+        this(Opcodes.ASM5, sa, elementName, visible, desc, name, -1, -1, null,
+                null, null, null);
+    }
+
+    public SAXAnnotationAdapter(final SAXAdapter sa, final String elementName,
+            final int visible, final int parameter, final String desc) {
+        this(Opcodes.ASM5, sa, elementName, visible, desc, null, parameter, -1,
+                null, null, null, null);
+    }
+
+    public SAXAnnotationAdapter(final SAXAdapter sa, final String elementName,
+            final int visible, final String name, final String desc,
+            final int typeRef, final TypePath typePath) {
+        this(Opcodes.ASM5, sa, elementName, visible, desc, name, -1, typeRef,
+                typePath, null, null, null);
+    }
+
+    public SAXAnnotationAdapter(final SAXAdapter sa, final String elementName,
+            final int visible, final String name, final String desc,
+            int typeRef, TypePath typePath, final String[] start,
+            final String[] end, final int[] index) {
+        this(Opcodes.ASM5, sa, elementName, visible, desc, name, -1, typeRef,
+                typePath, start, end, index);
+    }
+
+    protected SAXAnnotationAdapter(final int api, final SAXAdapter sa,
+            final String elementName, final int visible, final String desc,
+            final String name, final int parameter) {
+        this(api, sa, elementName, visible, desc, name, parameter, -1, null,
+                null, null, null);
+    }
+
+    protected SAXAnnotationAdapter(final int api, final SAXAdapter sa,
+            final String elementName, final int visible, final String desc,
+            final String name, final int parameter, final int typeRef,
+            final TypePath typePath, final String[] start, final String[] end,
+            final int[] index) {
+        super(api);
+        this.sa = sa;
+        this.elementName = elementName;
+
+        AttributesImpl att = new AttributesImpl();
+        if (name != null) {
+            att.addAttribute("", "name", "name", "", name);
+        }
+        if (visible != 0) {
+            att.addAttribute("", "visible", "visible", "", visible > 0 ? "true"
+                    : "false");
+        }
+        if (parameter != -1) {
+            att.addAttribute("", "parameter", "parameter", "",
+                    Integer.toString(parameter));
+        }
+        if (desc != null) {
+            att.addAttribute("", "desc", "desc", "", desc);
+        }
+        if (typeRef != -1) {
+            att.addAttribute("", "typeRef", "typeRef", "",
+                    Integer.toString(typeRef));
+        }
+        if (typePath != null) {
+            att.addAttribute("", "typePath", "typePath", "",
+                    typePath.toString());
+        }
+        if (start != null) {
+            StringBuffer value = new StringBuffer(start[0]);
+            for (int i = 1; i < start.length; ++i) {
+                value.append(" ").append(start[i]);
+            }
+            att.addAttribute("", "start", "start", "", value.toString());
+        }
+        if (end != null) {
+            StringBuffer value = new StringBuffer(end[0]);
+            for (int i = 1; i < end.length; ++i) {
+                value.append(" ").append(end[i]);
+            }
+            att.addAttribute("", "end", "end", "", value.toString());
+        }
+        if (index != null) {
+            StringBuffer value = new StringBuffer();
+            value.append(index[0]);
+            for (int i = 1; i < index.length; ++i) {
+                value.append(" ").append(index[i]);
+            }
+            att.addAttribute("", "index", "index", "", value.toString());
+        }
+
+        sa.addStart(elementName, att);
+    }
+
+    @Override
+    public void visit(final String name, final Object value) {
+        Class<?> c = value.getClass();
+        if (c.isArray()) {
+            AnnotationVisitor av = visitArray(name);
+            if (value instanceof byte[]) {
+                byte[] b = (byte[]) value;
+                for (int i = 0; i < b.length; i++) {
+                    av.visit(null, new Byte(b[i]));
+                }
+
+            } else if (value instanceof char[]) {
+                char[] b = (char[]) value;
+                for (int i = 0; i < b.length; i++) {
+                    av.visit(null, new Character(b[i]));
+                }
+
+            } else if (value instanceof short[]) {
+                short[] b = (short[]) value;
+                for (int i = 0; i < b.length; i++) {
+                    av.visit(null, new Short(b[i]));
+                }
+
+            } else if (value instanceof boolean[]) {
+                boolean[] b = (boolean[]) value;
+                for (int i = 0; i < b.length; i++) {
+                    av.visit(null, Boolean.valueOf(b[i]));
+                }
+
+            } else if (value instanceof int[]) {
+                int[] b = (int[]) value;
+                for (int i = 0; i < b.length; i++) {
+                    av.visit(null, new Integer(b[i]));
+                }
+
+            } else if (value instanceof long[]) {
+                long[] b = (long[]) value;
+                for (int i = 0; i < b.length; i++) {
+                    av.visit(null, new Long(b[i]));
+                }
+
+            } else if (value instanceof float[]) {
+                float[] b = (float[]) value;
+                for (int i = 0; i < b.length; i++) {
+                    av.visit(null, new Float(b[i]));
+                }
+
+            } else if (value instanceof double[]) {
+                double[] b = (double[]) value;
+                for (int i = 0; i < b.length; i++) {
+                    av.visit(null, new Double(b[i]));
+                }
+
+            }
+            av.visitEnd();
+        } else {
+            addValueElement("annotationValue", name, Type.getDescriptor(c),
+                    value.toString());
+        }
+    }
+
+    @Override
+    public void visitEnum(final String name, final String desc,
+            final String value) {
+        addValueElement("annotationValueEnum", name, desc, value);
+    }
+
+    @Override
+    public AnnotationVisitor visitAnnotation(final String name,
+            final String desc) {
+        return new SAXAnnotationAdapter(sa, "annotationValueAnnotation", 0,
+                name, desc);
+    }
+
+    @Override
+    public AnnotationVisitor visitArray(final String name) {
+        return new SAXAnnotationAdapter(sa, "annotationValueArray", 0, name,
+                null);
+    }
+
+    @Override
+    public void visitEnd() {
+        sa.addEnd(elementName);
+    }
+
+    private void addValueElement(final String element, final String name,
+            final String desc, final String value) {
+        AttributesImpl att = new AttributesImpl();
+        if (name != null) {
+            att.addAttribute("", "name", "name", "", name);
+        }
+        if (desc != null) {
+            att.addAttribute("", "desc", "desc", "", desc);
+        }
+        if (value != null) {
+            att.addAttribute("", "value", "value", "",
+                    SAXClassAdapter.encode(value));
+        }
+
+        sa.addElement(element, att);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1acd9d22/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXClassAdapter.java
----------------------------------------------------------------------
diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXClassAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXClassAdapter.java
new file mode 100644
index 0000000..dc4cb66
--- /dev/null
+++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXClassAdapter.java
@@ -0,0 +1,335 @@
+/***
+ * ASM XML Adapter
+ * Copyright (c) 2004-2011, Eugene Kuleshov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.tapestry5.internal.plastic.asm.xml;
+
+import org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor;
+import org.apache.tapestry5.internal.plastic.asm.ClassVisitor;
+import org.apache.tapestry5.internal.plastic.asm.FieldVisitor;
+import org.apache.tapestry5.internal.plastic.asm.MethodVisitor;
+import org.apache.tapestry5.internal.plastic.asm.Opcodes;
+import org.apache.tapestry5.internal.plastic.asm.TypePath;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * A {@link org.apache.tapestry5.internal.plastic.asm.ClassVisitor ClassVisitor} that generates SAX 2.0
+ * events from the visited class. It can feed any kind of
+ * {@link org.xml.sax.ContentHandler ContentHandler}, e.g. XML serializer, XSLT
+ * or XQuery engines.
+ * 
+ * @see org.apache.tapestry5.internal.plastic.asm.xml.Processor
+ * @see org.apache.tapestry5.internal.plastic.asm.xml.ASMContentHandler
+ * 
+ * @author Eugene Kuleshov
+ */
+public final class SAXClassAdapter extends ClassVisitor {
+
+    SAXAdapter sa;
+
+    private final boolean singleDocument;
+
+    /**
+     * Pseudo access flag used to distinguish class access flags.
+     */
+    private static final int ACCESS_CLASS = 262144;
+
+    /**
+     * Pseudo access flag used to distinguish field access flags.
+     */
+    private static final int ACCESS_FIELD = 524288;
+
+    /**
+     * Pseudo access flag used to distinguish inner class flags.
+     */
+    private static final int ACCESS_INNER = 1048576;
+
+    /**
+     * Constructs a new {@link SAXClassAdapter SAXClassAdapter} object.
+     * 
+     * @param h
+     *            content handler that will be used to send SAX 2.0 events.
+     * @param singleDocument
+     *            if <tt>true</tt> adapter will not produce
+     *            {@link ContentHandler#startDocument() startDocument()} and
+     *            {@link ContentHandler#endDocument() endDocument()} events.
+     */
+    public SAXClassAdapter(final ContentHandler h, boolean singleDocument) {
+        super(Opcodes.ASM5);
+        this.sa = new SAXAdapter(h);
+        this.singleDocument = singleDocument;
+        if (!singleDocument) {
+            sa.addDocumentStart();
+        }
+    }
+
+    @Override
+    public void visitSource(final String source, final String debug) {
+        AttributesImpl att = new AttributesImpl();
+        if (source != null) {
+            att.addAttribute("", "file", "file", "", encode(source));
+        }
+        if (debug != null) {
+            att.addAttribute("", "debug", "debug", "", encode(debug));
+        }
+
+        sa.addElement("source", att);
+    }
+
+    @Override
+    public void visitOuterClass(final String owner, final String name,
+            final String desc) {
+        AttributesImpl att = new AttributesImpl();
+        att.addAttribute("", "owner", "owner", "", owner);
+        if (name != null) {
+            att.addAttribute("", "name", "name", "", name);
+        }
+        if (desc != null) {
+            att.addAttribute("", "desc", "desc", "", desc);
+        }
+
+        sa.addElement("outerclass", att);
+    }
+
+    @Override
+    public AnnotationVisitor visitAnnotation(final String desc,
+            final boolean visible) {
+        return new SAXAnnotationAdapter(sa, "annotation", visible ? 1 : -1,
+                null, desc);
+    }
+
+    @Override
+    public AnnotationVisitor visitTypeAnnotation(int typeRef,
+            TypePath typePath, String desc, boolean visible) {
+        return new SAXAnnotationAdapter(sa, "typeAnnotation", visible ? 1 : -1,
+                null, desc, typeRef, typePath);
+    }
+
+    @Override
+    public void visit(final int version, final int access, final String name,
+            final String signature, final String superName,
+            final String[] interfaces) {
+        StringBuffer sb = new StringBuffer();
+        appendAccess(access | ACCESS_CLASS, sb);
+
+        AttributesImpl att = new AttributesImpl();
+        att.addAttribute("", "access", "access", "", sb.toString());
+        if (name != null) {
+            att.addAttribute("", "name", "name", "", name);
+        }
+        if (signature != null) {
+            att.addAttribute("", "signature", "signature", "",
+                    encode(signature));
+        }
+        if (superName != null) {
+            att.addAttribute("", "parent", "parent", "", superName);
+        }
+        att.addAttribute("", "major", "major", "",
+                Integer.toString(version & 0xFFFF));
+        att.addAttribute("", "minor", "minor", "",
+                Integer.toString(version >>> 16));
+        sa.addStart("class", att);
+
+        sa.addStart("interfaces", new AttributesImpl());
+        if (interfaces != null && interfaces.length > 0) {
+            for (int i = 0; i < interfaces.length; i++) {
+                AttributesImpl att2 = new AttributesImpl();
+                att2.addAttribute("", "name", "name", "", interfaces[i]);
+                sa.addElement("interface", att2);
+            }
+        }
+        sa.addEnd("interfaces");
+    }
+
+    @Override
+    public FieldVisitor visitField(final int access, final String name,
+            final String desc, final String signature, final Object value) {
+        StringBuffer sb = new StringBuffer();
+        appendAccess(access | ACCESS_FIELD, sb);
+
+        AttributesImpl att = new AttributesImpl();
+        att.addAttribute("", "access", "access", "", sb.toString());
+        att.addAttribute("", "name", "name", "", name);
+        att.addAttribute("", "desc", "desc", "", desc);
+        if (signature != null) {
+            att.addAttribute("", "signature", "signature", "",
+                    encode(signature));
+        }
+        if (value != null) {
+            att.addAttribute("", "value", "value", "", encode(value.toString()));
+        }
+
+        return new SAXFieldAdapter(sa, att);
+    }
+
+    @Override
+    public MethodVisitor visitMethod(final int access, final String name,
+            final String desc, final String signature, final String[] exceptions) {
+        StringBuffer sb = new StringBuffer();
+        appendAccess(access, sb);
+
+        AttributesImpl att = new AttributesImpl();
+        att.addAttribute("", "access", "access", "", sb.toString());
+        att.addAttribute("", "name", "name", "", name);
+        att.addAttribute("", "desc", "desc", "", desc);
+        if (signature != null) {
+            att.addAttribute("", "signature", "signature", "", signature);
+        }
+        sa.addStart("method", att);
+
+        sa.addStart("exceptions", new AttributesImpl());
+        if (exceptions != null && exceptions.length > 0) {
+            for (int i = 0; i < exceptions.length; i++) {
+                AttributesImpl att2 = new AttributesImpl();
+                att2.addAttribute("", "name", "name", "", exceptions[i]);
+                sa.addElement("exception", att2);
+            }
+        }
+        sa.addEnd("exceptions");
+
+        return new SAXCodeAdapter(sa, access);
+    }
+
+    @Override
+    public final void visitInnerClass(final String name,
+            final String outerName, final String innerName, final int access) {
+        StringBuffer sb = new StringBuffer();
+        appendAccess(access | ACCESS_INNER, sb);
+
+        AttributesImpl att = new AttributesImpl();
+        att.addAttribute("", "access", "access", "", sb.toString());
+        if (name != null) {
+            att.addAttribute("", "name", "name", "", name);
+        }
+        if (outerName != null) {
+            att.addAttribute("", "outerName", "outerName", "", outerName);
+        }
+        if (innerName != null) {
+            att.addAttribute("", "innerName", "innerName", "", innerName);
+        }
+        sa.addElement("innerclass", att);
+    }
+
+    @Override
+    public final void visitEnd() {
+        sa.addEnd("class");
+        if (!singleDocument) {
+            sa.addDocumentEnd();
+        }
+    }
+
+    static final String encode(final String s) {
+        StringBuffer sb = new StringBuffer();
+        for (int i = 0; i < s.length(); i++) {
+            char c = s.charAt(i);
+            if (c == '\\') {
+                sb.append("\\\\");
+            } else if (c < 0x20 || c > 0x7f) {
+                sb.append("\\u");
+                if (c < 0x10) {
+                    sb.append("000");
+                } else if (c < 0x100) {
+                    sb.append("00");
+                } else if (c < 0x1000) {
+                    sb.append('0');
+                }
+                sb.append(Integer.toString(c, 16));
+            } else {
+                sb.append(c);
+            }
+        }
+        return sb.toString();
+    }
+
+    static void appendAccess(final int access, final StringBuffer sb) {
+        if ((access & Opcodes.ACC_PUBLIC) != 0) {
+            sb.append("public ");
+        }
+        if ((access & Opcodes.ACC_PRIVATE) != 0) {
+            sb.append("private ");
+        }
+        if ((access & Opcodes.ACC_PROTECTED) != 0) {
+            sb.append("protected ");
+        }
+        if ((access & Opcodes.ACC_FINAL) != 0) {
+            sb.append("final ");
+        }
+        if ((access & Opcodes.ACC_STATIC) != 0) {
+            sb.append("static ");
+        }
+        if ((access & Opcodes.ACC_SUPER) != 0) {
+            if ((access & ACCESS_CLASS) == 0) {
+                sb.append("synchronized ");
+            } else {
+                sb.append("super ");
+            }
+        }
+        if ((access & Opcodes.ACC_VOLATILE) != 0) {
+            if ((access & ACCESS_FIELD) == 0) {
+                sb.append("bridge ");
+            } else {
+                sb.append("volatile ");
+            }
+        }
+        if ((access & Opcodes.ACC_TRANSIENT) != 0) {
+            if ((access & ACCESS_FIELD) == 0) {
+                sb.append("varargs ");
+            } else {
+                sb.append("transient ");
+            }
+        }
+        if ((access & Opcodes.ACC_NATIVE) != 0) {
+            sb.append("native ");
+        }
+        if ((access & Opcodes.ACC_STRICT) != 0) {
+            sb.append("strict ");
+        }
+        if ((access & Opcodes.ACC_INTERFACE) != 0) {
+            sb.append("interface ");
+        }
+        if ((access & Opcodes.ACC_ABSTRACT) != 0) {
+            sb.append("abstract ");
+        }
+        if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+            sb.append("synthetic ");
+        }
+        if ((access & Opcodes.ACC_ANNOTATION) != 0) {
+            sb.append("annotation ");
+        }
+        if ((access & Opcodes.ACC_ENUM) != 0) {
+            sb.append("enum ");
+        }
+        if ((access & Opcodes.ACC_DEPRECATED) != 0) {
+            sb.append("deprecated ");
+        }
+        if ((access & Opcodes.ACC_MANDATED) != 0) {
+            sb.append("mandated ");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1acd9d22/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXCodeAdapter.java
----------------------------------------------------------------------
diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXCodeAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXCodeAdapter.java
new file mode 100644
index 0000000..3ed0a49
--- /dev/null
+++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXCodeAdapter.java
@@ -0,0 +1,415 @@
+/***
+ * ASM XML Adapter
+ * Copyright (c) 2004-2011, Eugene Kuleshov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.tapestry5.internal.plastic.asm.xml;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor;
+import org.apache.tapestry5.internal.plastic.asm.Handle;
+import org.apache.tapestry5.internal.plastic.asm.Label;
+import org.apache.tapestry5.internal.plastic.asm.MethodVisitor;
+import org.apache.tapestry5.internal.plastic.asm.Opcodes;
+import org.apache.tapestry5.internal.plastic.asm.Type;
+import org.apache.tapestry5.internal.plastic.asm.TypePath;
+import org.apache.tapestry5.internal.plastic.asm.util.Printer;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * A {@link MethodVisitor} that generates SAX 2.0 events from the visited
+ * method.
+ * 
+ * @see org.apache.tapestry5.internal.plastic.asm.xml.SAXClassAdapter
+ * @see org.apache.tapestry5.internal.plastic.asm.xml.Processor
+ * 
+ * @author Eugene Kuleshov
+ */
+public final class SAXCodeAdapter extends MethodVisitor {
+
+    static final String[] TYPES = { "top", "int", "float", "double", "long",
+            "null", "uninitializedThis" };
+
+    SAXAdapter sa;
+
+    int access;
+
+    private final Map<Label, String> labelNames;
+
+    /**
+     * Constructs a new {@link SAXCodeAdapter SAXCodeAdapter} object.
+     * 
+     * @param sa
+     *            content handler that will be used to send SAX 2.0 events.
+     */
+    public SAXCodeAdapter(final SAXAdapter sa, final int access) {
+        super(Opcodes.ASM5);
+        this.sa = sa;
+        this.access = access;
+        this.labelNames = new HashMap<Label, String>();
+    }
+
+    @Override
+    public void visitParameter(String name, int access) {
+        AttributesImpl attrs = new AttributesImpl();
+        if (name != null) {
+            attrs.addAttribute("", "name", "name", "", name);
+        }
+        StringBuffer sb = new StringBuffer();
+        SAXClassAdapter.appendAccess(access, sb);
+        attrs.addAttribute("", "access", "access", "", sb.toString());
+        sa.addElement("parameter", attrs);
+    }
+
+    @Override
+    public final void visitCode() {
+        if ((access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE | Opcodes.ACC_NATIVE)) == 0) {
+            sa.addStart("code", new AttributesImpl());
+        }
+    }
+
+    @Override
+    public void visitFrame(final int type, final int nLocal,
+            final Object[] local, final int nStack, final Object[] stack) {
+        AttributesImpl attrs = new AttributesImpl();
+        switch (type) {
+        case Opcodes.F_NEW:
+        case Opcodes.F_FULL:
+            if (type == Opcodes.F_NEW) {
+                attrs.addAttribute("", "type", "type", "", "NEW");
+            } else {
+                attrs.addAttribute("", "type", "type", "", "FULL");
+            }
+            sa.addStart("frame", attrs);
+            appendFrameTypes(true, nLocal, local);
+            appendFrameTypes(false, nStack, stack);
+            break;
+        case Opcodes.F_APPEND:
+            attrs.addAttribute("", "type", "type", "", "APPEND");
+            sa.addStart("frame", attrs);
+            appendFrameTypes(true, nLocal, local);
+            break;
+        case Opcodes.F_CHOP:
+            attrs.addAttribute("", "type", "type", "", "CHOP");
+            attrs.addAttribute("", "count", "count", "",
+                    Integer.toString(nLocal));
+            sa.addStart("frame", attrs);
+            break;
+        case Opcodes.F_SAME:
+            attrs.addAttribute("", "type", "type", "", "SAME");
+            sa.addStart("frame", attrs);
+            break;
+        case Opcodes.F_SAME1:
+            attrs.addAttribute("", "type", "type", "", "SAME1");
+            sa.addStart("frame", attrs);
+            appendFrameTypes(false, 1, stack);
+            break;
+        }
+        sa.addEnd("frame");
+    }
+
+    private void appendFrameTypes(final boolean local, final int n,
+            final Object[] types) {
+        for (int i = 0; i < n; ++i) {
+            Object type = types[i];
+            AttributesImpl attrs = new AttributesImpl();
+            if (type instanceof String) {
+                attrs.addAttribute("", "type", "type", "", (String) type);
+            } else if (type instanceof Integer) {
+                attrs.addAttribute("", "type", "type", "",
+                        TYPES[((Integer) type).intValue()]);
+            } else {
+                attrs.addAttribute("", "type", "type", "", "uninitialized");
+                attrs.addAttribute("", "label", "label", "",
+                        getLabel((Label) type));
+            }
+            sa.addElement(local ? "local" : "stack", attrs);
+        }
+    }
+
+    @Override
+    public final void visitInsn(final int opcode) {
+        sa.addElement(Printer.OPCODES[opcode], new AttributesImpl());
+    }
+
+    @Override
+    public final void visitIntInsn(final int opcode, final int operand) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "value", "value", "", Integer.toString(operand));
+        sa.addElement(Printer.OPCODES[opcode], attrs);
+    }
+
+    @Override
+    public final void visitVarInsn(final int opcode, final int var) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "var", "var", "", Integer.toString(var));
+        sa.addElement(Printer.OPCODES[opcode], attrs);
+    }
+
+    @Override
+    public final void visitTypeInsn(final int opcode, final String type) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "desc", "desc", "", type);
+        sa.addElement(Printer.OPCODES[opcode], attrs);
+    }
+
+    @Override
+    public final void visitFieldInsn(final int opcode, final String owner,
+            final String name, final String desc) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "owner", "owner", "", owner);
+        attrs.addAttribute("", "name", "name", "", name);
+        attrs.addAttribute("", "desc", "desc", "", desc);
+        sa.addElement(Printer.OPCODES[opcode], attrs);
+    }
+
+    @Override
+    public final void visitMethodInsn(final int opcode, final String owner,
+            final String name, final String desc, final boolean itf) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "owner", "owner", "", owner);
+        attrs.addAttribute("", "name", "name", "", name);
+        attrs.addAttribute("", "desc", "desc", "", desc);
+        attrs.addAttribute("", "itf", "itf", "", itf ? "true" : "false");
+        sa.addElement(Printer.OPCODES[opcode], attrs);
+    }
+
+    @Override
+    public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
+            Object... bsmArgs) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "name", "name", "", name);
+        attrs.addAttribute("", "desc", "desc", "", desc);
+        attrs.addAttribute("", "bsm", "bsm", "",
+                SAXClassAdapter.encode(bsm.toString()));
+        sa.addStart("INVOKEDYNAMIC", attrs);
+        for (int i = 0; i < bsmArgs.length; i++) {
+            sa.addElement("bsmArg", getConstantAttribute(bsmArgs[i]));
+        }
+        sa.addEnd("INVOKEDYNAMIC");
+    }
+
+    @Override
+    public final void visitJumpInsn(final int opcode, final Label label) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "label", "label", "", getLabel(label));
+        sa.addElement(Printer.OPCODES[opcode], attrs);
+    }
+
+    @Override
+    public final void visitLabel(final Label label) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "name", "name", "", getLabel(label));
+        sa.addElement("Label", attrs);
+    }
+
+    @Override
+    public final void visitLdcInsn(final Object cst) {
+        sa.addElement(Printer.OPCODES[Opcodes.LDC], getConstantAttribute(cst));
+    }
+
+    private static AttributesImpl getConstantAttribute(final Object cst) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "cst", "cst", "",
+                SAXClassAdapter.encode(cst.toString()));
+        attrs.addAttribute("", "desc", "desc", "",
+                Type.getDescriptor(cst.getClass()));
+        return attrs;
+    }
+
+    @Override
+    public final void visitIincInsn(final int var, final int increment) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "var", "var", "", Integer.toString(var));
+        attrs.addAttribute("", "inc", "inc", "", Integer.toString(increment));
+        sa.addElement(Printer.OPCODES[Opcodes.IINC], attrs);
+    }
+
+    @Override
+    public final void visitTableSwitchInsn(final int min, final int max,
+            final Label dflt, final 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 = Printer.OPCODES[Opcodes.TABLESWITCH];
+        sa.addStart(o, attrs);
+        for (int i = 0; i < labels.length; i++) {
+            AttributesImpl att2 = new AttributesImpl();
+            att2.addAttribute("", "name", "name", "", getLabel(labels[i]));
+            sa.addElement("label", att2);
+        }
+        sa.addEnd(o);
+    }
+
+    @Override
+    public final void visitLookupSwitchInsn(final Label dflt, final int[] keys,
+            final Label[] labels) {
+        AttributesImpl att = new AttributesImpl();
+        att.addAttribute("", "dflt", "dflt", "", getLabel(dflt));
+        String o = Printer.OPCODES[Opcodes.LOOKUPSWITCH];
+        sa.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]));
+            sa.addElement("label", att2);
+        }
+        sa.addEnd(o);
+    }
+
+    @Override
+    public final void visitMultiANewArrayInsn(final String desc, final int dims) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "desc", "desc", "", desc);
+        attrs.addAttribute("", "dims", "dims", "", Integer.toString(dims));
+        sa.addElement(Printer.OPCODES[Opcodes.MULTIANEWARRAY], attrs);
+    }
+
+    @Override
+    public final void visitTryCatchBlock(final Label start, final Label end,
+            final Label handler, final 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);
+        }
+        sa.addElement("TryCatch", attrs);
+    }
+
+    @Override
+    public final void visitMaxs(final int maxStack, final int maxLocals) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "maxStack", "maxStack", "",
+                Integer.toString(maxStack));
+        attrs.addAttribute("", "maxLocals", "maxLocals", "",
+                Integer.toString(maxLocals));
+        sa.addElement("Max", attrs);
+
+        sa.addEnd("code");
+    }
+
+    @Override
+    public void visitLocalVariable(final String name, final String desc,
+            final String signature, final Label start, final Label end,
+            final int index) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "name", "name", "", name);
+        attrs.addAttribute("", "desc", "desc", "", desc);
+        if (signature != null) {
+            attrs.addAttribute("", "signature", "signature", "",
+                    SAXClassAdapter.encode(signature));
+        }
+        attrs.addAttribute("", "start", "start", "", getLabel(start));
+        attrs.addAttribute("", "end", "end", "", getLabel(end));
+        attrs.addAttribute("", "var", "var", "", Integer.toString(index));
+        sa.addElement("LocalVar", attrs);
+    }
+
+    @Override
+    public final void visitLineNumber(final int line, final Label start) {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.addAttribute("", "line", "line", "", Integer.toString(line));
+        attrs.addAttribute("", "start", "start", "", getLabel(start));
+        sa.addElement("LineNumber", attrs);
+    }
+
+    @Override
+    public AnnotationVisitor visitAnnotationDefault() {
+        return new SAXAnnotationAdapter(sa, "annotationDefault", 0, null, null);
+    }
+
+    @Override
+    public AnnotationVisitor visitAnnotation(final String desc,
+            final boolean visible) {
+        return new SAXAnnotationAdapter(sa, "annotation", visible ? 1 : -1,
+                null, desc);
+    }
+
+    @Override
+    public AnnotationVisitor visitTypeAnnotation(int typeRef,
+            TypePath typePath, String desc, boolean visible) {
+        return new SAXAnnotationAdapter(sa, "typeAnnotation", visible ? 1 : -1,
+                null, desc, typeRef, typePath);
+    }
+
+    @Override
+    public AnnotationVisitor visitParameterAnnotation(final int parameter,
+            final String desc, final boolean visible) {
+        return new SAXAnnotationAdapter(sa, "parameterAnnotation", visible ? 1
+                : -1, parameter, desc);
+    }
+
+    @Override
+    public AnnotationVisitor visitInsnAnnotation(int typeRef,
+            TypePath typePath, String desc, boolean visible) {
+        return new SAXAnnotationAdapter(sa, "insnAnnotation", visible ? 1 : -1,
+                null, desc, typeRef, typePath);
+    }
+
+    @Override
+    public AnnotationVisitor visitTryCatchAnnotation(int typeRef,
+            TypePath typePath, String desc, boolean visible) {
+        return new SAXAnnotationAdapter(sa, "tryCatchAnnotation", visible ? 1
+                : -1, null, desc, typeRef, typePath);
+    }
+
+    @Override
+    public AnnotationVisitor visitLocalVariableAnnotation(int typeRef,
+            TypePath typePath, Label[] start, Label[] end, int[] index,
+            String desc, boolean visible) {
+        String[] s = new String[start.length];
+        String[] e = new String[end.length];
+        for (int i = 0; i < s.length; ++i) {
+            s[i] = getLabel(start[i]);
+        }
+        for (int i = 0; i < e.length; ++i) {
+            e[i] = getLabel(end[i]);
+        }
+        return new SAXAnnotationAdapter(sa, "localVariableAnnotation",
+                visible ? 1 : -1, null, desc, typeRef, typePath, s, e, index);
+    }
+
+    @Override
+    public void visitEnd() {
+        sa.addEnd("method");
+    }
+
+    private final String getLabel(final Label label) {
+        String name = labelNames.get(label);
+        if (name == null) {
+            name = Integer.toString(labelNames.size());
+            labelNames.put(label, name);
+        }
+        return name;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1acd9d22/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXFieldAdapter.java
----------------------------------------------------------------------
diff --git a/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXFieldAdapter.java b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXFieldAdapter.java
new file mode 100644
index 0000000..4fbc2a5
--- /dev/null
+++ b/plastic/src/external/java/org/apache/tapestry5/internal/plastic/asm/xml/SAXFieldAdapter.java
@@ -0,0 +1,71 @@
+/***
+ * ASM XML Adapter
+ * Copyright (c) 2004-2011, Eugene Kuleshov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.tapestry5.internal.plastic.asm.xml;
+
+import org.apache.tapestry5.internal.plastic.asm.AnnotationVisitor;
+import org.apache.tapestry5.internal.plastic.asm.FieldVisitor;
+import org.apache.tapestry5.internal.plastic.asm.Opcodes;
+import org.apache.tapestry5.internal.plastic.asm.TypePath;
+import org.xml.sax.Attributes;
+
+/**
+ * SAXFieldAdapter
+ * 
+ * @author Eugene Kuleshov
+ */
+public final class SAXFieldAdapter extends FieldVisitor {
+
+    SAXAdapter sa;
+
+    public SAXFieldAdapter(final SAXAdapter sa, final Attributes att) {
+        super(Opcodes.ASM5);
+        this.sa = sa;
+        sa.addStart("field", att);
+    }
+
+    @Override
+    public AnnotationVisitor visitAnnotation(final String desc,
+            final boolean visible) {
+        return new SAXAnnotationAdapter(sa, "annotation", visible ? 1 : -1,
+                null, desc);
+    }
+
+    @Override
+    public AnnotationVisitor visitTypeAnnotation(int typeRef,
+            TypePath typePath, String desc, boolean visible) {
+        return new SAXAnnotationAdapter(sa, "typeAnnotation", visible ? 1 : -1,
+                null, desc, typeRef, typePath);
+    }
+
+    @Override
+    public void visitEnd() {
+        sa.addEnd("field");
+    }
+}