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