1 22 package org.jboss.xb.binding.sunday.unmarshalling; 23 24 import javax.xml.namespace.QName ; 25 import javax.xml.namespace.NamespaceContext ; 26 import org.xml.sax.Attributes ; 27 import org.jboss.logging.Logger; 28 import org.jboss.xb.binding.Constants; 29 import org.jboss.xb.binding.JBossXBRuntimeException; 30 31 35 public class AttributesHandler 36 { 37 private static final Logger log = Logger.getLogger(AttributesHandler.class); 38 39 public static final AttributesHandler INSTANCE = new AttributesHandler(); 40 41 public void attributes(Object o, QName elementName, TypeBinding type, Attributes attrs, NamespaceContext nsCtx) 42 { 43 for(int i = 0; i < attrs.getLength(); ++i) 44 { 45 QName qName = new QName (attrs.getURI(i), attrs.getLocalName(i)); 46 AttributeBinding binding = type.getAttribute(qName); 47 if(binding != null) 48 { 49 AttributeHandler handler = binding.getHandler(); 50 Object value = handler.unmarshal(elementName, qName, binding, nsCtx, attrs.getValue(i)); 51 handler.attribute(elementName, qName, binding, o, value); 52 } 53 else if(!Constants.NS_XML_SCHEMA_INSTANCE.equals(qName.getNamespaceURI())) 54 { 55 SchemaBinding schemaBinding = type.getSchemaBinding(); 56 if(schemaBinding != null && schemaBinding.isStrictSchema()) 57 { 58 throw new JBossXBRuntimeException( 59 "Attribute is not bound: element owner " + elementName + ", attribute " + qName 60 ); 61 } 62 else if(log.isTraceEnabled()) 63 { 64 log.trace("Attribute is not bound: element owner " + elementName + ", attribute " + qName); 65 } 66 } 67 } 68 } 69 } 70 | Popular Tags |