KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > ksoap > marshal > MarshalBase64


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2003 - ScalAgent Distributed Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * The present code contributor is ScalAgent Distributed Technologies.
21  *
22  * Initial developer(s): Nicolas Tachker (ScalAgent)
23  * Contributor(s):
24  */

25 package com.scalagent.ksoap.marshal;
26
27 import java.io.*;
28 import com.scalagent.ksoap.*;
29
30 public class MarshalBase64 implements Marshal {
31
32   static byte [] BA_WORKAROUND = new byte[0];
33   public static Class JavaDoc BYTE_ARRAY_CLASS = BA_WORKAROUND.getClass();
34     
35   public Object JavaDoc readInstance(SoapReader reader,
36                              String JavaDoc namespace,
37                              String JavaDoc name,
38                              PropertyInfo expected) throws IOException {
39     
40     reader.parser.read();
41     Object JavaDoc result = Base64.decode(reader.parser.readText());
42     reader.parser.read();
43     return result;
44   }
45   
46
47   public void writeInstance(SoapWriter writer,
48                             Object JavaDoc obj) throws IOException {
49     writer.writer.write(Base64.encode((byte[]) obj));
50   }
51
52   public void register(ClassMap cm) {
53     cm.addMapping(cm.xsd,"base64Binary",
54                   MarshalBase64.BYTE_ARRAY_CLASS,this);
55     cm.addMapping(ClassMap.enc,"base64",
56                   MarshalBase64.BYTE_ARRAY_CLASS,this);
57   }
58 }
59
Popular Tags