1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.apache.xmlrpc.serializer; |
17 |
|
|
18 |
|
import org.apache.xmlrpc.common.TypeFactory; |
19 |
|
import org.apache.xmlrpc.common.XmlRpcStreamConfig; |
20 |
|
import org.xml.sax.ContentHandler; |
21 |
|
import org.xml.sax.SAXException; |
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
public class ObjectArraySerializer extends TypeSerializerImpl { |
27 |
|
|
28 |
|
|
29 |
|
public static final String ARRAY_TAG = "array"; |
30 |
|
|
31 |
|
|
32 |
|
public static final String DATA_TAG = "data"; |
33 |
|
|
34 |
|
private final XmlRpcStreamConfig config; |
35 |
|
private final TypeFactory typeFactory; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
32 |
public ObjectArraySerializer(TypeFactory pTypeFactory, XmlRpcStreamConfig pConfig) { |
42 |
32 |
typeFactory = pTypeFactory; |
43 |
32 |
config = pConfig; |
44 |
32 |
} |
45 |
|
protected void writeObject(ContentHandler pHandler, Object pObject) throws SAXException { |
46 |
112 |
TypeSerializer ts = typeFactory.getSerializer(config, pObject); |
47 |
104 |
if (ts == null) { |
48 |
0 |
throw new SAXException("Unsupported Java type: " + pObject.getClass().getName()); |
49 |
|
} |
50 |
104 |
ts.write(pHandler, pObject); |
51 |
104 |
} |
52 |
|
protected void writeData(ContentHandler pHandler, Object pObject) throws SAXException { |
53 |
32 |
Object[] data = (Object[]) pObject; |
54 |
136 |
for (int i = 0; i < data.length; i++) { |
55 |
112 |
writeObject(pHandler, data[i]); |
56 |
|
} |
57 |
24 |
} |
58 |
|
public void write(final ContentHandler pHandler, Object pObject) throws SAXException { |
59 |
32 |
pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES); |
60 |
32 |
pHandler.startElement("", ARRAY_TAG, ARRAY_TAG, ZERO_ATTRIBUTES); |
61 |
32 |
pHandler.startElement("", DATA_TAG, DATA_TAG, ZERO_ATTRIBUTES); |
62 |
32 |
writeData(pHandler, pObject); |
63 |
24 |
pHandler.endElement("", DATA_TAG, DATA_TAG); |
64 |
24 |
pHandler.endElement("", ARRAY_TAG, ARRAY_TAG); |
65 |
24 |
pHandler.endElement("", VALUE_TAG, VALUE_TAG); |
66 |
24 |
} |
67 |
|
} |