1 22 package org.jboss.xb.binding.sunday.unmarshalling; 23 24 import javax.xml.namespace.QName ; 25 import javax.xml.namespace.NamespaceContext ; 26 27 import org.jboss.logging.Logger; 28 import org.xml.sax.Attributes ; 29 30 36 public class DefaultElementHandler 37 implements ElementHandler, ParticleHandler 38 { 39 40 private static final Logger log = Logger.getLogger(DefaultElementHandler.class); 41 42 public static final DefaultElementHandler INSTANCE = new DefaultElementHandler(); 43 44 private AttributesHandler attrsHandler; 45 46 public DefaultElementHandler() 47 { 48 this(AttributesHandler.INSTANCE); 49 } 50 51 public DefaultElementHandler(AttributesHandler attrsHandler) 52 { 53 this.attrsHandler = attrsHandler; 54 } 55 56 public Object startElement(Object parent, QName qName, ElementBinding element) 57 { 58 return parent; 59 } 60 61 public void attributes(Object o, QName elementName, ElementBinding element, Attributes attrs, NamespaceContext nsCtx) 62 { 63 if(attrsHandler != null) 64 { 65 attrsHandler.attributes(o, elementName, element.getType(), attrs, nsCtx); 66 } 67 } 68 69 public Object endElement(Object o, QName qName, ElementBinding element) 70 { 71 return o; 72 } 73 74 public void setParent(Object parent, Object o, QName qName, ElementBinding element, ElementBinding parentElement) 75 { 76 if (log.isTraceEnabled()) 77 log.trace("Not setting " + o + " on " + parent + " for " + qName); 78 } 79 80 82 public Object startParticle(Object parent, 83 QName elementName, 84 ParticleBinding particle, 85 Attributes attrs, 86 NamespaceContext nsCtx) 87 { 88 ElementBinding element = (ElementBinding)particle.getTerm(); 89 Object o = startElement(parent, elementName, element); 90 if(o != null) 91 { 92 attrs = element.getType().expandWithDefaultAttributes(attrs); 93 attributes(o, elementName, element, attrs, nsCtx); 94 } 95 return o; 96 } 97 98 public Object endParticle(Object o, QName elementName, ParticleBinding particle) 99 { 100 return endElement(o, elementName, (ElementBinding)particle.getTerm()); 101 } 102 103 public void setParent(Object parent, 104 Object o, 105 QName elementName, 106 ParticleBinding particle, 107 ParticleBinding parentParticle) 108 { 109 ElementBinding element = (ElementBinding)particle.getTerm(); 110 ElementBinding parentElement = (ElementBinding)parentParticle.getTerm(); 111 setParent(parent, o, elementName, element, parentElement); 112 } 113 } 114 | Popular Tags |