Debian Codegraph @

samples/encoding/DataDeser.java

raw
1 package samples.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 public static final String DATAMEMBER = "dataMember";
20 public static final QName myTypeQName = new QName("typeNS", "Data");
21
22 private Hashtable typesByMemberName = new Hashtable();
23
24 public DataDeser()
25 {
26 typesByMemberName.put(STRINGMEMBER, Constants.XSD_STRING);
27 typesByMemberName.put(FLOATMEMBER, Constants.XSD_FLOAT);
28 typesByMemberName.put(DATAMEMBER, myTypeQName);
29 value = new Data();
30 }
31
32 /** DESERIALIZER STUFF - event handlers
33 */
34
35 /**
36 * This method is invoked when an element start tag is encountered.
37 * @param namespace is the namespace of the element
38 * @param localName is the name of the element
39 * @param prefix is the element's prefix
40 * @param attributes are the attributes on the element...used to get the type
41 * @param context is the DeserializationContext
42 */
43 public SOAPHandler onStartChild(String namespace,
44 String localName,
45 String prefix,
46 Attributes attributes,
47 DeserializationContext context)
48 throws SAXException
49 {
50 QName typeQName = (QName)typesByMemberName.get(localName);
51 if (typeQName == null)
52 throw new SAXException("Invalid element in Data struct - " + localName);
53
54 // These can come in either order.
55 Deserializer dSer = context.getDeserializerForType(typeQName);
56 try {
57 dSer.registerValueTarget(new FieldTarget(value, localName));
58 } catch (NoSuchFieldException e) {
59 throw new SAXException(e);
60 }
61
62 if (dSer == null)
63 throw new SAXException("No deserializer for a " + typeQName + "???");
64
65 return (SOAPHandler)dSer;
66 }
67 }