1 4 package org.oddjob.designer.arooa; 5 6 import java.io.ByteArrayInputStream ; 7 8 import org.oddjob.arooa.ArooaHandler; 9 import org.oddjob.arooa.ArooaContext; 10 import org.oddjob.arooa.xml.XMLDefinitionHelper; 11 import org.xml.sax.Attributes ; 12 import org.xml.sax.InputSource ; 13 import org.xml.sax.SAXParseException ; 14 15 20 public class DesignParser { 21 22 private final ArooaContext context; 23 24 30 public DesignParser(ArooaContext context) { 31 this.context = context; 32 } 33 34 43 public void parse(String tag, 44 Object object, ArooaHandler handler) 45 throws SAXParseException { 46 parse(tag, object, handler, context); 47 } 48 49 void parse(String tag, 50 Object object, ArooaHandler handler, ArooaContext context) 51 throws SAXParseException { 52 DesignIH dih = DesignIH.getHelper(object.getClass()); 53 String unknown = dih.unknown(object); 54 if (unknown != null) { 56 XMLDefinitionHelper xdef = new XMLDefinitionHelper(new ArooaContext()); 57 InputSource in = new InputSource (new ByteArrayInputStream (unknown.getBytes())); 58 xdef.parse(in, handler); 59 } 60 else { 61 Attributes attrs = dih.attributes(object); 62 ArooaHandler nextHandler = handler.onStartChild("", 63 tag, tag, attrs, context); 64 context = new ArooaContext(context); 65 nextHandler.onStartElement("", tag, tag, attrs, context); 66 String text = dih.text(object); 67 if (text != null) { 68 nextHandler.characters(text.toCharArray(), 0, text.length(), context); 69 } 70 71 ElementWrapper[] elements = dih.elements(object); 72 for (int i = 0 ; i < elements.length; ++i ) { 73 parse(elements[i].getName(), elements[i].getElement(), nextHandler, context); 74 } 75 nextHandler.onEndElement("", tag, context); 76 context = context.getParent(); 77 handler.onEndChild("", tag, tag, context); 78 } 79 } 80 81 } 82 | Popular Tags |