KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > encoding > DataDeser


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 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     public static final String JavaDoc DATAMEMBER = "dataMember";
20     public static final QName JavaDoc myTypeQName = new QName JavaDoc("typeNS", "Data");
21     
22     private Hashtable JavaDoc typesByMemberName = new Hashtable JavaDoc();
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 JavaDoc namespace,
44                                     String JavaDoc localName,
45                                     String JavaDoc prefix,
46                                     Attributes JavaDoc attributes,
47                                     DeserializationContext context)
48         throws SAXException JavaDoc
49     {
50         QName JavaDoc typeQName = (QName JavaDoc)typesByMemberName.get(localName);
51         if (typeQName == null)
52             throw new SAXException JavaDoc("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 JavaDoc e) {
59             throw new SAXException JavaDoc(e);
60         }
61         
62         if (dSer == null)
63             throw new SAXException JavaDoc("No deserializer for a " + typeQName + "???");
64         
65         return (SOAPHandler)dSer;
66     }
67 }
68
Popular Tags