KickJava   Java API By Example, From Geeks To Geeks.

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


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.security.auth.Subject 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 SubjectSer extends AxisSerializer
25 {
26    static final String JavaDoc TYPE = "Subject";
27    static final String JavaDoc READ_ONLY = "readOnly";
28    static final String JavaDoc PRINCIPALS = "principals";
29    static final String JavaDoc PUBLIC_CREDENTIALS = "publicCredentials";
30    static final String JavaDoc PRIVATE_CREDENTIALS = "privateCredentials";
31    private static final QName JavaDoc READ_ONLY_QNAME = new QName JavaDoc("", READ_ONLY);
32    private static final QName JavaDoc PRINCIPALS_QNAME = new QName JavaDoc("", PRINCIPALS);
33    private static final QName JavaDoc PUBLIC_CREDENTIALS_QNAME = new QName JavaDoc("", PUBLIC_CREDENTIALS);
34    private static final QName JavaDoc PRIVATE_CREDENTIALS_QNAME = new QName JavaDoc("", PRIVATE_CREDENTIALS);
35
36    public void serialize(QName JavaDoc name, Attributes JavaDoc attributes, Object JavaDoc value, SerializationContext context) throws IOException JavaDoc
37    {
38       Subject JavaDoc subject = (Subject JavaDoc)value;
39       context.startElement(name, attributes);
40       context.serialize(READ_ONLY_QNAME, null, new Boolean JavaDoc(subject.isReadOnly()));
41       context.serialize(PRINCIPALS_QNAME, null, subject.getPrincipals());
42       context.serialize(PUBLIC_CREDENTIALS_QNAME, null, subject.getPublicCredentials());
43       context.serialize(PRIVATE_CREDENTIALS_QNAME, null, subject.getPrivateCredentials());
44       context.endElement();
45    }
46
47    public Element JavaDoc writeSchema(Class JavaDoc aClass, Types types) throws Exception JavaDoc
48    {
49       Element JavaDoc complexType = types.createElement(SCHEMA_COMPLEX_TYPE);
50       complexType.setAttribute("name", TYPE);
51       Element JavaDoc allElement = types.createElement(SCHEMA_ALL);
52       complexType.appendChild(allElement);
53
54       Element JavaDoc readOnlyElement = types.createElement(SCHEMA_ELEMENT);
55       readOnlyElement.setAttribute("name", READ_ONLY);
56       readOnlyElement.setAttribute("type", XMLType.XSD_BOOLEAN.getLocalPart());
57       allElement.appendChild(readOnlyElement);
58
59       Element JavaDoc principalsElement = types.createElement(SCHEMA_ELEMENT);
60       principalsElement.setAttribute("name", PRINCIPALS);
61       principalsElement.setAttribute("type", SetSer.TYPE);
62       allElement.appendChild(principalsElement);
63
64       Element JavaDoc publicCredentialsElement = types.createElement(SCHEMA_ELEMENT);
65       publicCredentialsElement.setAttribute("name", PUBLIC_CREDENTIALS);
66       publicCredentialsElement.setAttribute("type", SetSer.TYPE);
67       allElement.appendChild(publicCredentialsElement);
68
69       Element JavaDoc privateCredentialsElement = types.createElement(SCHEMA_ELEMENT);
70       privateCredentialsElement.setAttribute("name", PRIVATE_CREDENTIALS);
71       privateCredentialsElement.setAttribute("type", SetSer.TYPE);
72       allElement.appendChild(privateCredentialsElement);
73
74       return complexType;
75    }
76 }
77
Popular Tags