Coverage Report - org.simpleframework.xml.stream.NodeBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
NodeBuilder
87%
7/8
N/A
1
 
 1  
 /*
 2  
  * NodeBuilder.java July 2006
 3  
  *
 4  
  * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.stream;
 20  
 
 21  
 import java.io.InputStream;
 22  
 import java.io.Reader;
 23  
 import java.io.Writer;
 24  
 
 25  
 /**
 26  
  * The <code>NodeBuilder</code> object is used to create either an
 27  
  * input node or an output node for a given source or destination. 
 28  
  * If an <code>InputNode</code> is required for reading an XML
 29  
  * document then a reader must be provided to read the content from.
 30  
  * <p>
 31  
  * If an <code>OutputNode</code> is required then a destination is
 32  
  * required. The provided output node can be used to generate well
 33  
  * formed XML to the specified writer. 
 34  
  * 
 35  
  * @author Niall Gallagher
 36  
  */ 
 37  0
 public final class NodeBuilder {
 38  
  
 39  
    /**
 40  
     * This is the XML provider implementation that creates readers.
 41  
     */         
 42  
    private static Provider PROVIDER;
 43  
 
 44  
    static {
 45  1
       PROVIDER = ProviderFactory.getInstance();                    
 46  1
    }
 47  
 
 48  
    /**
 49  
     * This is used to create an <code>InputNode</code> that can be 
 50  
     * used to read XML from the specified stream. The stream will
 51  
     * be positioned at the root element in the XML document.
 52  
     *
 53  
     * @param source this contains the contents of the XML source
 54  
     *
 55  
     * @throws Exception thrown if there is an I/O exception
 56  
     */   
 57  
    public static InputNode read(InputStream source) throws Exception {
 58  10007
       return read(PROVIDER.provide(source));   
 59  
    }
 60  
         
 61  
    /**
 62  
     * This is used to create an <code>InputNode</code> that can be 
 63  
     * used to read XML from the specified reader. The reader will
 64  
     * be positioned at the root element in the XML document.
 65  
     *
 66  
     * @param source this contains the contents of the XML source
 67  
     *
 68  
     * @throws Exception thrown if there is an I/O exception
 69  
     */   
 70  
    public static InputNode read(Reader source) throws Exception {
 71  64070
       return read(PROVIDER.provide(source));   
 72  
    }
 73  
 
 74  
    /**
 75  
     * This is used to create an <code>InputNode</code> that can be 
 76  
     * used to read XML from the specified reader. The reader will
 77  
     * be positioned at the root element in the XML document.
 78  
     *
 79  
     * @param source this contains the contents of the XML source
 80  
     *
 81  
     * @throws Exception thrown if there is an I/O exception
 82  
     */     
 83  
    private static InputNode read(EventReader source) throws Exception {
 84  74073
       return new NodeReader(source).readRoot();           
 85  
    }
 86  
    
 87  
    /**
 88  
     * This is used to create an <code>OutputNode</code> that can be
 89  
     * used to write a well formed XML document. The writer specified
 90  
     * will have XML elements, attributes, and text written to it as
 91  
     * output nodes are created and populated.
 92  
     * 
 93  
     * @param result this contains the result of the generated XML
 94  
     *
 95  
     * @throws Exception this is thrown if there is an I/O error
 96  
     */ 
 97  
    public static OutputNode write(Writer result) throws Exception {
 98  22
       return write(result, new Format());
 99  
    }
 100  
 
 101  
    /**
 102  
     * This is used to create an <code>OutputNode</code> that can be
 103  
     * used to write a well formed XML document. The writer specified
 104  
     * will have XML elements, attributes, and text written to it as
 105  
     * output nodes are created and populated.
 106  
     * 
 107  
     * @param result this contains the result of the generated XML
 108  
     * @param format this is the format to use for the document
 109  
     *
 110  
     * @throws Exception this is thrown if there is an I/O error
 111  
     */ 
 112  
    public static OutputNode write(Writer result, Format format) throws Exception {
 113  24420
       return new NodeWriter(result, format).writeRoot();
 114  
    }   
 115  
 }