1 16 17 package org.apache.axis.encoding.ser; 18 19 import org.apache.axis.components.logger.LogFactory; 20 import org.apache.axis.encoding.DeserializationContext; 21 import org.apache.axis.encoding.Deserializer; 22 import org.apache.axis.encoding.DeserializerImpl; 23 import org.apache.axis.encoding.DeserializerTarget; 24 import org.apache.axis.message.SOAPHandler; 25 import org.apache.axis.utils.Messages; 26 import org.apache.commons.logging.Log; 27 import org.xml.sax.Attributes ; 28 import org.xml.sax.SAXException ; 29 30 import javax.xml.namespace.QName ; 31 import java.util.HashMap ; 32 import java.util.Map ; 33 34 42 public class MapDeserializer extends DeserializerImpl { 43 44 protected static Log log = 45 LogFactory.getLog(MapDeserializer.class.getName()); 46 47 public static final Object KEYHINT = new Object (); 49 public static final Object VALHINT = new Object (); 50 public static final Object NILHINT = new Object (); 51 52 53 64 public void onStartElement(String namespace, String localName, 65 String prefix, Attributes attributes, 66 DeserializationContext context) 67 throws SAXException { 68 if (log.isDebugEnabled()) { 69 log.debug("Enter MapDeserializer::startElement()"); 70 } 71 72 if (context.isNil(attributes)) { 73 return; 74 } 75 76 setValue(new HashMap ()); 78 79 if (log.isDebugEnabled()) { 80 log.debug("Exit: MapDeserializer::startElement()"); 81 } 82 } 83 84 96 public SOAPHandler onStartChild(String namespace, 97 String localName, 98 String prefix, 99 Attributes attributes, 100 DeserializationContext context) 101 throws SAXException { 102 103 if (log.isDebugEnabled()) { 104 log.debug("Enter: MapDeserializer::onStartChild()"); 105 } 106 107 if(localName.equals("item")) { 108 ItemHandler handler = new ItemHandler(this); 109 110 addChildDeserializer(handler); 112 113 if (log.isDebugEnabled()) { 114 log.debug("Exit: MapDeserializer::onStartChild()"); 115 } 116 117 return handler; 118 } 119 120 return this; 121 } 122 123 129 public void setChildValue(Object value, Object hint) throws SAXException 130 { 131 if (log.isDebugEnabled()) { 132 log.debug(Messages.getMessage("gotValue00", "MapDeserializer", "" + value)); 133 } 134 ((Map )this.value).put(hint, value); 135 } 136 137 143 class ItemHandler extends DeserializerImpl { 144 Object key; 145 Object myValue; 146 int numSet = 0; 147 MapDeserializer md = null; 148 149 ItemHandler(MapDeserializer md) { 150 this.md = md; 151 } 152 157 public void setChildValue(Object val, Object hint) throws SAXException 158 { 159 if (hint == KEYHINT) { 160 key = val; 161 } else if (hint == VALHINT) { 162 myValue = val; 163 } else if (hint != NILHINT) { 164 return; 165 } 166 numSet++; 167 if (numSet == 2) 168 md.setChildValue(myValue, key); 169 } 170 171 public SOAPHandler onStartChild(String namespace, 172 String localName, 173 String prefix, 174 Attributes attributes, 175 DeserializationContext context) 176 throws SAXException 177 { 178 QName typeQName = context.getTypeFromAttributes(namespace, 179 localName, 180 attributes); 181 Deserializer dser = context.getDeserializerForType(typeQName); 182 183 if (dser == null) 185 dser = new DeserializerImpl(); 186 187 DeserializerTarget dt = null; 192 if (context.isNil(attributes)) { 193 dt = new DeserializerTarget(this, NILHINT); 194 } else if (localName.equals("key")) { 195 dt = new DeserializerTarget(this, KEYHINT); 196 } else if (localName.equals("value")) { 197 dt = new DeserializerTarget(this, VALHINT); 198 } else { 199 } 201 if (dt != null) { 202 dser.registerValueTarget(dt); 203 } 204 205 addChildDeserializer(dser); 207 208 return (SOAPHandler)dser; 209 } 210 } 211 } 212 | Popular Tags |