KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > encoding > DataSer


1 package test.encoding;
2
3 import org.apache.axis.Constants;
4 import org.apache.axis.encoding.SerializationContext;
5 import org.apache.axis.encoding.Serializer;
6 import org.apache.axis.wsdl.fromJava.Types;
7 import org.w3c.dom.Element JavaDoc;
8 import org.xml.sax.Attributes JavaDoc;
9
10 import javax.xml.namespace.QName JavaDoc;
11 import java.io.IOException JavaDoc;
12
13 public class DataSer implements Serializer
14 {
15     public static final String JavaDoc STRINGMEMBER = "stringMember";
16     public static final String JavaDoc FLOATMEMBER = "floatMember";
17
18     /** SERIALIZER STUFF
19      */

20     /**
21      * Serialize an element named name, with the indicated attributes
22      * and value.
23      * @param name is the element name
24      * @param attributes are the attributes...serialize is free to add more.
25      * @param value is the value
26      * @param context is the SerializationContext
27      */

28     public void serialize(QName JavaDoc name, Attributes JavaDoc attributes,
29                           Object JavaDoc value, SerializationContext context)
30         throws IOException JavaDoc
31     {
32         if (!(value instanceof Data))
33             throw new IOException JavaDoc("Can't serialize a " + value.getClass().getName() + " with a DataSerializer.");
34         Data data = (Data)value;
35
36         context.startElement(name, attributes);
37         context.serialize(new QName JavaDoc("", STRINGMEMBER), null, data.stringMember);
38         context.serialize(new QName JavaDoc("", FLOATMEMBER), null, data.floatMember);
39         context.endElement();
40     }
41     public String JavaDoc getMechanismType() { return Constants.AXIS_SAX; }
42
43     public Element JavaDoc writeSchema(Class JavaDoc javaType, Types types) throws Exception JavaDoc {
44         return null;
45     }
46 }
47
Popular Tags