Debian Codegraph @

test/encoding/DataDeser.java

raw
1 package test.encoding;
2
3 import org.apache.axis.Constants;
4 import org.apache.axis.encoding.DeserializationContext;
5 import org.apache.axis.encoding.Deserializer;
6 import org.apache.axis.encoding.DeserializerImpl;
7 import org.apache.axis.encoding.FieldTarget;
8 import org.apache.axis.message.SOAPHandler;
9 import org.xml.sax.Attributes;
10 import org.xml.sax.SAXException;
11
12 import javax.xml.namespace.QName;
13 import java.util.Hashtable;
14
15 public class DataDeser extends DeserializerImpl
16 {
17 public static final String STRINGMEMBER = "stringMember";
18 public static final String FLOATMEMBER = "floatMember";
19
20 private Hashtable typesByMemberName = new Hashtable();
21
22 public DataDeser()
23 {
24 typesByMemberName.put(STRINGMEMBER, Constants.XSD_STRING);
25 typesByMemberName.put(FLOATMEMBER, Constants.XSD_FLOAT);
26 value = new Data();
27 }
28
29 /** DESERIALIZER STUFF - event handlers
30 */
31
32 /**
33 * This method is invoked when an element start tag is encountered.
34 * @param namespace is the namespace of the element
35 * @param localName is the name of the element
36 * @param prefix is the prefix of the element
37 * @param attributes are the attributes on the element...used to get the type
38 * @param context is the DeserializationContext
39 */
40 public SOAPHandler onStartChild(String namespace,
41 String localName,
42 String prefix,
43 Attributes attributes,
44 DeserializationContext context)
45 throws SAXException
46 {
47 QName typeQName = (QName)typesByMemberName.get(localName);
48 if (typeQName == null)
49 throw new SAXException("Invalid element in Data struct - " + localName);
50
51 // These can come in either order.
52 Deserializer dSer = context.getDeserializerForType(typeQName);
53 try {
54 dSer.registerValueTarget(new FieldTarget(value, localName));
55 } catch (NoSuchFieldException e) {
56 throw new SAXException(e);
57 }
58
59 if (dSer == null)
60 throw new SAXException("No deserializer for a " + typeQName + "???");
61
62 return (SOAPHandler)dSer;
63 }
64 }