1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.gridsystems.innergrid.serializers;
18
19 import java.io.IOException;
20 import java.security.cert.Certificate;
21 import java.security.cert.CertificateEncodingException;
22
23 import javax.xml.namespace.QName;
24
25 import org.apache.axis.AxisFault;
26 import org.apache.axis.Constants;
27 import org.apache.axis.InternalException;
28 import org.apache.axis.encoding.Base64;
29 import org.apache.axis.encoding.SerializationContext;
30 import org.apache.axis.encoding.SimpleValueSerializer;
31 import org.apache.axis.wsdl.fromJava.Types;
32 import org.w3c.dom.Element;
33 import org.xml.sax.Attributes;
34
35
36
37
38
39
40
41 public class CertificateSerializer implements SimpleValueSerializer {
42
43
44
45 private static final long serialVersionUID = 1435657457424L;
46
47
48
49
50 private final QName xmlType;
51
52
53
54
55
56
57
58 public CertificateSerializer(Class javaType, QName xmlType) {
59 this.xmlType = xmlType;
60 }
61
62
63
64
65 public void serialize(QName name, Attributes attribs, Object value,
66 SerializationContext context) throws IOException {
67
68 context.startElement(name, attribs);
69 context.writeSafeString(getValueAsString(value, context));
70 context.endElement();
71 }
72
73
74
75
76 public String getValueAsString(Object value, SerializationContext context) {
77 try {
78 Certificate cert = (Certificate)value;
79 return Base64.encode(cert.getEncoded());
80 } catch (CertificateEncodingException e) {
81 throw new InternalException(e);
82 }
83 }
84
85
86
87
88 public String getMechanismType() {
89 return Constants.AXIS_SAX;
90 }
91
92
93
94
95 public Element writeSchema(Class javaType, Types types) throws AxisFault {
96
97
98 String base = types.writeType(byte[].class);
99
100 Element restr = types.createElement("restriction");
101 restr.setAttribute("base", base);
102
103 Element type = types.createElement("simpleType");
104 types.writeSchemaTypeDecl(xmlType, type);
105 type.setAttribute("name", xmlType.getLocalPart());
106 type.appendChild(restr);
107
108 return type;
109 }
110 }