Coverage Report - org.apache.xmlrpc.serializer.SerializableSerializer
 
Classes in this File Line Coverage Branch Coverage Complexity
SerializableSerializer
75% 
N/A 
5
 
 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 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  
 /** A {@link org.apache.xmlrpc.serializer.TypeSerializer} for
 30  
  * instances of {@link java.io.Serializable}.
 31  
  */
 32  1
 public class SerializableSerializer extends TypeSerializerImpl {
 33  
         /** Tag name of a base64 value.
 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  
 }