ObjectArraySerializer.java
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one
00003  * or more contributor license agreements.  See the NOTICE file
00004  * distributed with this work for additional information
00005  * regarding copyright ownership.  The ASF licenses this file
00006  * to you under the Apache License, Version 2.0 (the
00007  * "License"); you may not use this file except in compliance
00008  * with the License.  You may obtain a copy of the License at
00009  *
00010  *   http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing,
00013  * software distributed under the License is distributed on an
00014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00015  * KIND, either express or implied.  See the License for the
00016  * specific language governing permissions and limitations
00017  * under the License.    
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 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49