Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 package org.apache.xmlrpc.serializer;
00020
00021 import java.io.IOException;
00022 import java.io.ObjectOutputStream;
00023 import java.io.OutputStream;
00024
00025 import org.apache.ws.commons.util.Base64;
00026 import org.apache.ws.commons.util.Base64.Encoder;
00027 import org.apache.ws.commons.util.Base64.EncoderOutputStream;
00028 import org.xml.sax.ContentHandler;
00029 import org.xml.sax.SAXException;
00030
00031
00035 public class SerializableSerializer extends TypeSerializerImpl {
00038 public static final String SERIALIZABLE_TAG = "serializable";
00039 private static final String EX_SERIALIZABLE_TAG = "ex:" + SERIALIZABLE_TAG;
00040
00041 public void write(final ContentHandler pHandler, Object pObject) throws SAXException {
00042 pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
00043 pHandler.startElement("", SERIALIZABLE_TAG, EX_SERIALIZABLE_TAG, ZERO_ATTRIBUTES);
00044 char[] buffer = new char[1024];
00045 Encoder encoder = new Base64.SAXEncoder(buffer, 0, null, pHandler);
00046 try {
00047 OutputStream ostream = new EncoderOutputStream(encoder);
00048 ObjectOutputStream oos = new ObjectOutputStream(ostream);
00049 oos.writeObject(pObject);
00050 oos.close();
00051 } catch (Base64.SAXIOException e) {
00052 throw e.getSAXException();
00053 } catch (IOException e) {
00054 throw new SAXException(e);
00055 }
00056 pHandler.endElement("", SERIALIZABLE_TAG, EX_SERIALIZABLE_TAG);
00057 pHandler.endElement("", VALUE_TAG, VALUE_TAG);
00058 }
00059 }