KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > encoding > DataDeser


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 JavaDoc;
10 import org.xml.sax.SAXException JavaDoc;
11
12 import javax.xml.namespace.QName JavaDoc;
13 import java.util.Hashtable JavaDoc;
14
15 public class DataDeser extends DeserializerImpl
16 {
17     public static final String JavaDoc STRINGMEMBER = "stringMember";
18     public static final String JavaDoc FLOATMEMBER = "floatMember";
19     
20     private Hashtable JavaDoc typesByMemberName = new Hashtable JavaDoc();
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 JavaDoc namespace,
41                                     String JavaDoc localName,
42                                     String JavaDoc prefix,
43                                     Attributes JavaDoc attributes,
44                                     DeserializationContext context)
45         throws SAXException JavaDoc
46     {
47         QName JavaDoc typeQName = (QName JavaDoc)typesByMemberName.get(localName);
48         if (typeQName == null)
49             throw new SAXException JavaDoc("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 JavaDoc e) {
56             throw new SAXException JavaDoc(e);
57         }
58         
59         if (dSer == null)
60             throw new SAXException JavaDoc("No deserializer for a " + typeQName + "???");
61         
62         return (SOAPHandler)dSer;
63     }
64 }
65
Popular Tags