1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.apache.xmlrpc.serializer; |
17 |
|
|
18 |
|
import java.io.IOException; |
19 |
|
import java.io.ObjectOutputStream; |
20 |
|
import java.io.OutputStream; |
21 |
|
|
22 |
|
import org.apache.ws.commons.util.Base64; |
23 |
|
import org.apache.ws.commons.util.Base64.Encoder; |
24 |
|
import org.apache.ws.commons.util.Base64.EncoderOutputStream; |
25 |
|
import org.xml.sax.ContentHandler; |
26 |
|
import org.xml.sax.SAXException; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
1 |
public class SerializableSerializer extends TypeSerializerImpl { |
33 |
|
|
34 |
|
|
35 |
|
public static final String SERIALIZABLE_TAG = "serializable"; |
36 |
|
private static final String EX_SERIALIZABLE_TAG = "ex:" + SERIALIZABLE_TAG; |
37 |
|
|
38 |
|
public void write(final ContentHandler pHandler, Object pObject) throws SAXException { |
39 |
8 |
pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES); |
40 |
8 |
pHandler.startElement("", SERIALIZABLE_TAG, EX_SERIALIZABLE_TAG, ZERO_ATTRIBUTES); |
41 |
8 |
char[] buffer = new char[1024]; |
42 |
8 |
Encoder encoder = new Base64.SAXEncoder(buffer, 0, null, pHandler); |
43 |
|
try { |
44 |
8 |
OutputStream ostream = new EncoderOutputStream(encoder); |
45 |
8 |
ObjectOutputStream oos = new ObjectOutputStream(ostream); |
46 |
8 |
oos.writeObject(pObject); |
47 |
8 |
oos.close(); |
48 |
0 |
} catch (Base64.SAXIOException e) { |
49 |
0 |
throw e.getSAXException(); |
50 |
0 |
} catch (IOException e) { |
51 |
0 |
throw new SAXException(e); |
52 |
|
} |
53 |
8 |
pHandler.endElement("", SERIALIZABLE_TAG, EX_SERIALIZABLE_TAG); |
54 |
8 |
pHandler.endElement("", VALUE_TAG, VALUE_TAG); |
55 |
8 |
} |
56 |
|
} |