KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
13 import javax.management.ObjectName JavaDoc;
14 import javax.management.relation.Role JavaDoc;
15 import javax.xml.namespace.QName JavaDoc;
16
17 import org.apache.axis.Constants;
18 import org.apache.axis.encoding.SerializationContext;
19 import org.apache.axis.encoding.XMLType;
20 import org.apache.axis.wsdl.fromJava.Types;
21 import org.w3c.dom.Element JavaDoc;
22 import org.xml.sax.Attributes JavaDoc;
23
24 /**
25  * @version $Revision: 1.3 $
26  */

27 public class RoleSer extends AxisSerializer
28 {
29    static final String JavaDoc TYPE = "Role";
30    static final String JavaDoc ROLE_NAME = "roleName";
31    static final String JavaDoc ROLE_VALUE = "roleValue";
32    protected static final QName JavaDoc ROLE_NAME_QNAME = new QName JavaDoc("", ROLE_NAME);
33    protected static final QName JavaDoc ROLE_VALUE_QNAME = new QName JavaDoc("", ROLE_VALUE);
34
35
36    public void serialize(QName JavaDoc name, Attributes JavaDoc attributes, Object JavaDoc value,
37                          SerializationContext context)
38            throws IOException JavaDoc
39    {
40       Role JavaDoc role = (Role JavaDoc)value;
41       context.startElement(name, attributes);
42       context.serialize(ROLE_NAME_QNAME, null, role.getRoleName());
43       for (Iterator JavaDoc i = role.getRoleValue().iterator(); i.hasNext();)
44       {
45          ObjectName JavaDoc on = (ObjectName JavaDoc)i.next();
46          context.serialize(Constants.QNAME_LITERAL_ITEM, null, on);
47       }
48       context.endElement();
49    }
50
51    public Element JavaDoc writeSchema(Class JavaDoc aClass, Types types) throws Exception JavaDoc
52    {
53       Element JavaDoc complexType = types.createElement(SCHEMA_COMPLEX_TYPE);
54       complexType.setAttribute("name", TYPE);
55
56       Element JavaDoc nameElement = types.createElement(SCHEMA_ELEMENT);
57       nameElement.setAttribute("name", ROLE_NAME);
58       nameElement.setAttribute("type", XMLType.XSD_STRING.getLocalPart());
59       complexType.appendChild(nameElement);
60
61       types.writeSchemaElement(Constants.SOAP_VECTOR, complexType);
62       Element JavaDoc sequence = types.createElement(SCHEMA_SEQUENCE);
63       complexType.appendChild(sequence);
64       Element JavaDoc element = types.createElement(SCHEMA_ELEMENT);
65       element.setAttribute("name", Constants.QNAME_LITERAL_ITEM.getLocalPart());
66       element.setAttribute("minOccurs", "0");
67       element.setAttribute("maxOccurs", "unbounded");
68       element.setAttribute("type", AttributeSer.TYPE);
69       sequence.appendChild(element);
70       return complexType;
71    }
72
73 }
74
Popular Tags