1 22 package org.jboss.xb.binding.sunday.unmarshalling; 23 24 import java.util.List ; 25 import java.lang.reflect.Array ; 26 import javax.xml.namespace.QName ; 27 import javax.xml.namespace.NamespaceContext ; 28 29 import org.jboss.xb.binding.Constants; 30 import org.jboss.xb.binding.SimpleTypeBindings; 31 import org.jboss.xb.binding.JBossXBRuntimeException; 32 import org.jboss.xb.binding.metadata.ValueMetaData; 33 34 38 public abstract class CharactersHandler 39 { 40 public static CharactersHandler NOOP = new CharactersHandler() 41 { 42 public Object unmarshal(QName qName, 43 TypeBinding typeBinding, 44 NamespaceContext nsCtx, 45 ValueMetaData valueMetaData, 46 String value) 47 { 48 return value; 49 } 50 }; 51 52 public static CharactersHandler DEFAULT = new CharactersHandler() 53 { 54 }; 55 56 public Object unmarshalEmpty(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, ValueMetaData valueMetaData) 57 { 58 Object result = null; 59 QName typeQName = typeBinding.getQName(); 60 if(Constants.QNAME_STRING.equals(typeQName)) 61 { 62 result = ""; 63 } 64 else if(Constants.QNAME_BASE64BINARY.equals(typeQName)) 65 { 66 result = new byte[0]; 67 } 68 return result; 69 } 70 71 public Object unmarshal(QName qName, TypeBinding typeBinding, NamespaceContext nsCtx, ValueMetaData valueMetaData, String value) 72 { 73 Object o; 74 QName typeQName = typeBinding.getQName(); 75 TypeBinding itemType = typeBinding.getItemType(); 76 if(itemType != null) 77 { 78 QName itemTypeQName = itemType.getQName(); 79 if(itemTypeQName != null && Constants.NS_XML_SCHEMA.equals(itemTypeQName.getNamespaceURI())) 80 { 81 List list = SimpleTypeBindings.unmarshalList(itemTypeQName.getLocalPart(), value, nsCtx); 82 if(typeBinding.getSchemaBinding().isUnmarshalListsToArrays()) 83 { 84 if(list.isEmpty()) 85 { 86 Class compType = SimpleTypeBindings.classForType(itemTypeQName.getLocalPart(), true); 87 o = Array.newInstance(compType, 0); 88 } 89 else 90 { 91 Class compType = list.get(0).getClass(); 92 o = list.toArray((Object [])Array.newInstance(compType, list.size())); 93 } 94 } 95 else 96 { 97 o = list; 98 } 99 } 100 else 101 { 102 throw new JBossXBRuntimeException( 104 "Only list types with item type from " + Constants.NS_XML_SCHEMA + 105 " namespace are supported currently." 106 ); 107 } 108 } 109 else if(typeQName != null && Constants.NS_XML_SCHEMA.equals(typeQName.getNamespaceURI())) 110 { 111 o = SimpleTypeBindings.unmarshal(typeQName.getLocalPart(), value, nsCtx); 112 } 113 else 114 { 115 TypeBinding baseType = typeBinding.getBaseType(); 116 o = (baseType == null ? value : unmarshal(qName, baseType, nsCtx, valueMetaData, value)); 117 } 118 return o; 119 } 120 121 public void setValue(QName qName, ElementBinding element, Object owner, Object value) 122 { 123 } 124 } 125 | Popular Tags |