Coverage Report - org.apache.xmlrpc.serializer.DefaultXMLWriterFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultXMLWriterFactory
71% 
N/A 
1,5
 
 1  
 /*
 2  
  * Copyright 2003, 2004  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.OutputStream;
 19  
 import java.io.StringWriter;
 20  
 
 21  
 import org.apache.ws.commons.serialize.CharSetXMLWriter;
 22  
 import org.apache.xmlrpc.XmlRpcException;
 23  
 import org.apache.xmlrpc.common.XmlRpcStreamConfig;
 24  
 import org.xml.sax.ContentHandler;
 25  
 import org.xml.sax.helpers.AttributesImpl;
 26  
 
 27  
 
 28  
 /** The default implementation of {@link org.apache.xmlrpc.serializer.XmlWriterFactory}
 29  
  * tests, whether the {@link org.apache.xmlrpc.serializer.CharSetXmlWriterFactory}
 30  
  * is usable. This is the case, when running in Java 1.4 or later. If so,
 31  
  * this factory is used. Otherwise, the
 32  
  * {@link org.apache.xmlrpc.serializer.BaseXmlWriterFactory} is used as a
 33  
  * fallback.
 34  
  */
 35  
 public class DefaultXMLWriterFactory implements XmlWriterFactory {
 36  
         private final XmlWriterFactory factory;
 37  
 
 38  
         /** Creates a new instance.
 39  
          */
 40  422
         public DefaultXMLWriterFactory() {
 41  
                 XmlWriterFactory xwf;
 42  
                 try {
 43  422
                         CharSetXMLWriter csw = new CharSetXMLWriter();
 44  422
                         StringWriter sw = new StringWriter();
 45  422
                         csw.setWriter(sw);
 46  422
                         csw.startDocument();
 47  0
                         csw.startElement("", "test", "test", new AttributesImpl());
 48  0
                         csw.endElement("", "test", "test");
 49  0
                         csw.endDocument();
 50  0
                         xwf = new CharSetXmlWriterFactory();
 51  422
                 } catch (Throwable t) {
 52  422
                         xwf = new BaseXmlWriterFactory();
 53  
                 }
 54  422
                 factory = xwf;
 55  422
         }
 56  
 
 57  
         public ContentHandler getXmlWriter(XmlRpcStreamConfig pConfig,
 58  
                                                                            OutputStream pStream) throws XmlRpcException {
 59  664
                 return factory.getXmlWriter(pConfig, pStream);
 60  
         }
 61  
 }