1 30 package org.objectweb.asm.xml; 31 32 import org.xml.sax.Attributes ; 33 import org.xml.sax.ContentHandler ; 34 import org.xml.sax.SAXException ; 35 36 41 public abstract class SAXAdapter { 42 private final ContentHandler h; 43 44 public SAXAdapter(ContentHandler h) { 45 this.h = h; 46 } 47 48 protected ContentHandler getContentHandler() { 49 return h; 50 } 51 52 protected final void addEnd(String name) { 53 try { 54 h.endElement("", name, name); 55 } catch (SAXException ex) { 56 throw new RuntimeException (ex.toString()); 57 } 58 } 59 60 protected final void addStart(String name, Attributes attrs) { 61 try { 62 h.startElement("", name, name, attrs); 63 } catch (SAXException ex) { 64 throw new RuntimeException (ex.toString()); 65 } 66 } 67 68 protected final void addElement(String name, Attributes attrs) { 69 addStart(name, attrs); 70 addEnd(name); 71 } 72 73 protected void addDocumentStart() { 74 try { 75 h.startDocument(); 76 } catch (SAXException ex) { 77 throw new RuntimeException (ex.getException()); 78 } 79 } 80 81 protected void addDocumentEnd() { 82 try { 83 h.endDocument(); 84 } catch (SAXException ex) { 85 throw new RuntimeException (ex.toString()); 88 } 89 } 90 91 } 92 | Popular Tags |