1 55 56 package org.jboss.axis.encoding.ser; 57 58 import org.jboss.axis.encoding.DeserializationContext; 59 import org.jboss.axis.encoding.Deserializer; 60 import org.jboss.axis.encoding.DeserializerImpl; 61 import org.jboss.axis.encoding.DeserializerTarget; 62 import org.jboss.axis.message.SOAPHandler; 63 import org.jboss.axis.utils.Messages; 64 import org.jboss.logging.Logger; 65 import org.xml.sax.Attributes ; 66 import org.xml.sax.SAXException ; 67 68 import javax.xml.namespace.QName ; 69 import java.util.HashMap ; 70 import java.util.Map ; 71 72 80 81 public class MapDeserializer extends DeserializerImpl 82 { 83 84 private static Logger log = Logger.getLogger(MapDeserializer.class.getName()); 85 86 public static final Object KEYHINT = new Object (); 88 public static final Object VALHINT = new Object (); 89 public static final Object NILHINT = new Object (); 90 91 92 104 public void onStartElement(String namespace, String localName, 105 String prefix, Attributes attributes, 106 DeserializationContext context) 107 throws SAXException 108 { 109 if (log.isDebugEnabled()) 110 { 111 log.debug("Enter MapDeserializer::startElement()"); 112 } 113 114 if (context.isNil(attributes)) 115 { 116 return; 117 } 118 119 setValue(new HashMap ()); 121 122 if (log.isDebugEnabled()) 123 { 124 log.debug("Exit: MapDeserializer::startElement()"); 125 } 126 } 127 128 140 public SOAPHandler onStartChild(String namespace, 141 String localName, 142 String prefix, 143 Attributes attributes, 144 DeserializationContext context) 145 throws SAXException 146 { 147 148 if (log.isDebugEnabled()) 149 { 150 log.debug("Enter: MapDeserializer::onStartChild()"); 151 } 152 153 if (localName.equals("item")) 154 { 155 ItemHandler handler = new ItemHandler(this); 156 157 addChildDeserializer(handler); 159 160 if (log.isDebugEnabled()) 161 { 162 log.debug("Exit: MapDeserializer::onStartChild()"); 163 } 164 165 return handler; 166 } 167 168 return this; 169 } 170 171 178 public void setChildValue(Object value, Object hint) throws SAXException 179 { 180 if (log.isDebugEnabled()) 181 { 182 log.debug(Messages.getMessage("gotValue00", "MapDeserializer", "" + value)); 183 } 184 ((Map )this.value).put(hint, value); 185 } 186 187 192 class ItemHandler extends DeserializerImpl 193 { 194 Object key; 195 Object myValue; 196 int numSet = 0; 197 MapDeserializer md = null; 198 199 ItemHandler(MapDeserializer md) 200 { 201 this.md = md; 202 } 203 204 209 public void setChildValue(Object val, Object hint) throws SAXException 210 { 211 if (hint == KEYHINT) 212 { 213 key = val; 214 } 215 else if (hint == VALHINT) 216 { 217 myValue = val; 218 } 219 else if (hint != NILHINT) 220 { 221 return; 222 } 223 numSet++; 224 if (numSet == 2) 225 md.setChildValue(myValue, key); 226 } 227 228 public SOAPHandler onStartChild(String namespace, 229 String localName, 230 String prefix, 231 Attributes attributes, 232 DeserializationContext context) 233 throws SAXException 234 { 235 QName typeQName = context.getTypeFromAttributes(namespace, 236 localName, 237 attributes); 238 Deserializer dser = context.getDeserializerForType(typeQName); 239 240 if (dser == null) 242 dser = new DeserializerImpl(); 243 244 DeserializerTarget dt = null; 249 if (context.isNil(attributes)) 250 { 251 dt = new DeserializerTarget(this, NILHINT); 252 } 253 else if (localName.equals("key")) 254 { 255 dt = new DeserializerTarget(this, KEYHINT); 256 } 257 else if (localName.equals("value")) 258 { 259 dt = new DeserializerTarget(this, VALHINT); 260 } 261 else 262 { 263 } 265 if (dt != null) 266 { 267 dser.registerValueTarget(dt); 268 } 269 270 addChildDeserializer(dser); 272 273 return (SOAPHandler)dser; 274 } 275 } 276 } 277 | Popular Tags |