Coverage Report - org.apache.xmlrpc.serializer.ObjectArraySerializer
 
Classes in this File Line Coverage Branch Coverage Complexity
ObjectArraySerializer
95% 
100% 
1,75
 
 1  
 /*
 2  
  * Copyright 1999,2005 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
 /** A {@link TypeSerializer} for object arrays.
 25  
  */
 26  
 public class ObjectArraySerializer extends TypeSerializerImpl {
 27  
         /** Tag name of an array value.
 28  
          */
 29  
         public static final String ARRAY_TAG = "array";
 30  
         /** Tag name of an arrays data.
 31  
          */
 32  
         public static final String DATA_TAG = "data";
 33  
 
 34  
         private final XmlRpcStreamConfig config;
 35  
         private final TypeFactory typeFactory;
 36  
 
 37  
         /** Creates a new instance.
 38  
          * @param pTypeFactory The factory being used for creating serializers.
 39  
          * @param pConfig The configuration being used for creating serializers.
 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  
 }