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 org.apache.xmlrpc.common.TypeFactory;
00022 import org.apache.xmlrpc.common.XmlRpcStreamConfig;
00023 import org.xml.sax.ContentHandler;
00024 import org.xml.sax.SAXException;
00025
00026
00029 public class ObjectArraySerializer extends TypeSerializerImpl {
00032 public static final String ARRAY_TAG = "array";
00035 public static final String DATA_TAG = "data";
00036
00037 private final XmlRpcStreamConfig config;
00038 private final TypeFactory typeFactory;
00039
00044 public ObjectArraySerializer(TypeFactory pTypeFactory, XmlRpcStreamConfig pConfig) {
00045 typeFactory = pTypeFactory;
00046 config = pConfig;
00047 }
00048 protected void writeObject(ContentHandler pHandler, Object pObject) throws SAXException {
00049 TypeSerializer ts = typeFactory.getSerializer(config, pObject);
00050 if (ts == null) {
00051 throw new SAXException("Unsupported Java type: " + pObject.getClass().getName());
00052 }
00053 ts.write(pHandler, pObject);
00054 }
00055 protected void writeData(ContentHandler pHandler, Object pObject) throws SAXException {
00056 Object[] data = (Object[]) pObject;
00057 for (int i = 0; i < data.length; i++) {
00058 writeObject(pHandler, data[i]);
00059 }
00060 }
00061 public void write(final ContentHandler pHandler, Object pObject) throws SAXException {
00062 pHandler.startElement("", VALUE_TAG, VALUE_TAG, ZERO_ATTRIBUTES);
00063 pHandler.startElement("", ARRAY_TAG, ARRAY_TAG, ZERO_ATTRIBUTES);
00064 pHandler.startElement("", DATA_TAG, DATA_TAG, ZERO_ATTRIBUTES);
00065 writeData(pHandler, pObject);
00066 pHandler.endElement("", DATA_TAG, DATA_TAG);
00067 pHandler.endElement("", ARRAY_TAG, ARRAY_TAG);
00068 pHandler.endElement("", VALUE_TAG, VALUE_TAG);
00069 }
00070 }