KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > soap > encoding > soapenc > Base64Serializer


1 package org.apache.soap.encoding.soapenc;
2
3 import java.io.*;
4 import org.w3c.dom.*;
5 import org.apache.soap.util.*;
6 import org.apache.soap.util.xml.*;
7 import org.apache.soap.*;
8 import org.apache.soap.rpc.*;
9
10 /**
11  * A <code>Base64Serializer</code> is used to serialize and deserialize
12  * byte arrays using the <code>SOAP-ENC</code> encoding style. The byte
13  * arrays are encoded using the SOAP-ENC:base64 subtype.
14  *
15  * @author Matthew J. Duftler (duftler@us.ibm.com)
16  */

17 public class Base64Serializer implements Serializer, Deserializer
18 {
19   public void marshall(String JavaDoc inScopeEncStyle, Class JavaDoc javaType, Object JavaDoc src,
20                        Object JavaDoc context, Writer sink, NSStack nsStack,
21                        XMLJavaMappingRegistry xjmr, SOAPContext ctx)
22     throws IllegalArgumentException JavaDoc, IOException
23   {
24     nsStack.pushScope();
25
26     byte[] bytes = (byte[])src;
27
28     if (bytes == null)
29     {
30       SoapEncUtils.generateNullStructure(inScopeEncStyle,
31                                      javaType,
32                                      context,
33                                      sink,
34                                      nsStack,
35                                      xjmr);
36     }
37     else
38     {
39       SoapEncUtils.generateStructureHeader(inScopeEncStyle,
40                                          javaType,
41                                          context,
42                                          sink,
43                                          nsStack,
44                                          xjmr);
45
46       sink.write(Base64.encode(bytes) + "</" + context + '>');
47     }
48
49     nsStack.popScope();
50   }
51
52   public Bean unmarshall(String JavaDoc inScopeEncStyle, QName elementType, Node src,
53                          XMLJavaMappingRegistry xjmr, SOAPContext ctx)
54     throws IllegalArgumentException JavaDoc
55   {
56     Element root = (Element)src;
57     String JavaDoc value = DOMUtils.getChildCharacterData(root);
58
59     return new Bean(byte[].class, Base64.decode(value));
60   }
61 }
62
Popular Tags