01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package mx4j.tools.remote.soap.axis.ser;
10:
11: import java.io.IOException;
12: import java.security.Principal;
13: import javax.xml.namespace.QName;
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;
19: import org.xml.sax.Attributes;
20:
21: /**
22: * @version $Revision: 1.4 $
23: */
24: public class PrincipalSer extends AxisSerializer {
25: static final String TYPE = "Principal";
26: static final String CLASS_NAME = "className";
27: static final String NAME = "name";
28: private static final QName CLASS_NAME_QNAME = new QName("",
29: CLASS_NAME);
30: private static final QName NAME_QNAME = new QName("", NAME);
31:
32: public void serialize(QName name, Attributes attributes,
33: Object value, SerializationContext context)
34: throws IOException {
35: Principal principal = (Principal) value;
36: context.startElement(name, attributes);
37: context.serialize(CLASS_NAME_QNAME, null, principal.getClass()
38: .getName());
39: context.serialize(NAME_QNAME, null, principal.getName());
40: context.endElement();
41: }
42:
43: public Element writeSchema(Class javaType, Types types)
44: throws Exception {
45: Element complexType = types.createElement(SCHEMA_COMPLEX_TYPE);
46: complexType.setAttribute("name", TYPE);
47: Element allElement = types.createElement(SCHEMA_ALL);
48: complexType.appendChild(allElement);
49: Element classNameElement = types.createElement(SCHEMA_ELEMENT);
50: classNameElement.setAttribute("name", CLASS_NAME);
51: classNameElement.setAttribute("type", XMLType.XSD_STRING
52: .getLocalPart());
53: allElement.appendChild(classNameElement);
54: Element nameElement = types.createElement(SCHEMA_ELEMENT);
55: nameElement.setAttribute("name", NAME);
56: nameElement.setAttribute("type", XMLType.XSD_STRING
57: .getLocalPart());
58: allElement.appendChild(nameElement);
59: return complexType;
60: }
61: }
|