KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > tools > remote > soap > axis > ser > NotificationSer


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.tools.remote.soap.axis.ser;
10
11 import java.io.IOException JavaDoc;
12 import javax.management.Notification JavaDoc;
13 import javax.xml.namespace.QName JavaDoc;
14
15 import org.apache.axis.encoding.SerializationContext;
16 import org.apache.axis.encoding.XMLType;
17 import org.apache.axis.wsdl.fromJava.Types;
18 import org.w3c.dom.Element JavaDoc;
19 import org.xml.sax.Attributes JavaDoc;
20
21 /**
22  * @version $Revision: 1.4 $
23  */

24 public class NotificationSer extends AxisSerializer
25 {
26    static final String JavaDoc TYPE = "Notification";
27    static final String JavaDoc CLASS_NAME = "type";
28    static final String JavaDoc SOURCE = "source";
29    static final String JavaDoc SEQUENCE_NUMBER = "sequenceNumber";
30    static final String JavaDoc TIMESTAMP = "timeStamp";
31    static final String JavaDoc MESSAGE = "message";
32    static final String JavaDoc USER_DATA = "userData";
33    private static final QName JavaDoc CLASS_NAME_QNAME = new QName JavaDoc("", CLASS_NAME);
34    private static final QName JavaDoc SOURCE_QNAME = new QName JavaDoc("", SOURCE);
35    private static final QName JavaDoc SEQUENCE_NUMBER_QNAME = new QName JavaDoc("", SEQUENCE_NUMBER);
36    private static final QName JavaDoc TIMESTAMP_QNAME = new QName JavaDoc("", TIMESTAMP);
37    private static final QName JavaDoc MESSAGE_QNAME = new QName JavaDoc("", MESSAGE);
38    private static final QName JavaDoc USER_DATA_QNAME = new QName JavaDoc("", USER_DATA);
39
40    public void serialize(QName JavaDoc name, Attributes JavaDoc attributes, Object JavaDoc value, SerializationContext context) throws IOException JavaDoc
41    {
42       Notification JavaDoc notification = (Notification JavaDoc)value;
43       context.startElement(name, attributes);
44       onSerialize(context, notification);
45       context.endElement();
46    }
47
48    protected void onSerialize(SerializationContext context, Notification JavaDoc notification) throws IOException JavaDoc
49    {
50       context.serialize(CLASS_NAME_QNAME, null, notification.getType());
51       context.serialize(SOURCE_QNAME, null, notification.getSource());
52       context.serialize(SEQUENCE_NUMBER_QNAME, null, new Long JavaDoc(notification.getSequenceNumber()));
53       context.serialize(TIMESTAMP_QNAME, null, new Long JavaDoc(notification.getTimeStamp()));
54       context.serialize(MESSAGE_QNAME, null, notification.getMessage());
55       context.serialize(USER_DATA_QNAME, null, notification.getUserData());
56    }
57
58    public Element JavaDoc writeSchema(Class JavaDoc aClass, Types types) throws Exception JavaDoc
59    {
60       Element JavaDoc complexType = types.createElement(SCHEMA_COMPLEX_TYPE);
61       complexType.setAttribute("name", TYPE);
62       Element JavaDoc allElement = types.createElement(SCHEMA_ALL);
63       complexType.appendChild(allElement);
64
65       Element JavaDoc typeElement = types.createElement(SCHEMA_ELEMENT);
66       typeElement.setAttribute("name", CLASS_NAME);
67       typeElement.setAttribute("type", XMLType.XSD_STRING.getLocalPart());
68       allElement.appendChild(typeElement);
69
70       Element JavaDoc sourceElement = types.createElement(SCHEMA_ELEMENT);
71       sourceElement.setAttribute("name", SOURCE);
72       sourceElement.setAttribute("type", XMLType.XSD_ANYTYPE.getLocalPart());
73       allElement.appendChild(sourceElement);
74
75       Element JavaDoc sequenceNumberElement = types.createElement(SCHEMA_ELEMENT);
76       sequenceNumberElement.setAttribute("name", SEQUENCE_NUMBER);
77       sequenceNumberElement.setAttribute("type", XMLType.XSD_LONG.getLocalPart());
78       allElement.appendChild(sequenceNumberElement);
79
80       Element JavaDoc timeStampElement = types.createElement(SCHEMA_ELEMENT);
81       timeStampElement.setAttribute("name", TIMESTAMP);
82       timeStampElement.setAttribute("type", XMLType.XSD_LONG.getLocalPart());
83       allElement.appendChild(timeStampElement);
84
85       Element JavaDoc messageElement = types.createElement(SCHEMA_ELEMENT);
86       messageElement.setAttribute("name", MESSAGE);
87       messageElement.setAttribute("type", XMLType.XSD_STRING.getLocalPart());
88       allElement.appendChild(messageElement);
89
90       Element JavaDoc userDataElement = types.createElement(SCHEMA_ELEMENT);
91       userDataElement.setAttribute("name", USER_DATA);
92       userDataElement.setAttribute("type", XMLType.XSD_ANYTYPE.getLocalPart());
93       allElement.appendChild(userDataElement);
94
95       return complexType;
96    }
97 }
98
Popular Tags