Coverage Report - org.apache.shindig.social.core.util.xstream.StackDriver
 
Classes in this File Line Coverage Branch Coverage Complexity
StackDriver
73%
8/11
N/A
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements. See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership. The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License. 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,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied. See the License for the
 16  
  * specific language governing permissions and limitations under the License.
 17  
  */
 18  
 package org.apache.shindig.social.core.util.xstream;
 19  
 
 20  
 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
 21  
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 22  
 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
 23  
 
 24  
 import java.io.InputStream;
 25  
 import java.io.OutputStream;
 26  
 import java.io.Reader;
 27  
 import java.io.Writer;
 28  
 import java.util.Map;
 29  
 
 30  
 /**
 31  
  * A StackDriver wraps other forms of Drivers and updates a WriterStack with the
 32  
  * path into the writer hierarchy.
 33  
  */
 34  
 public class StackDriver implements HierarchicalStreamDriver {
 35  
 
 36  
   /**
 37  
    * The parent Stream Driver that does the work.
 38  
    */
 39  
   private HierarchicalStreamDriver parent;
 40  
   /**
 41  
    * A Writer Stack implementation that records where the writer is.
 42  
    */
 43  
   private WriterStack writerStack;
 44  
   private Map<String, NamespaceSet> namespaces;
 45  
 
 46  
   /**
 47  
    * Create a {@link StackDriver}, wrapping a {@link HierarchicalStreamDriver}
 48  
    * and updating a {@link WriterStack}.
 49  
    * 
 50  
    * @param parent
 51  
    *          the driver to be wrapped
 52  
    * @param writerStack
 53  
    *          the thread safe writer stack that records where the writer is.
 54  
    * @param map
 55  
    */
 56  
   public StackDriver(HierarchicalStreamDriver parent, WriterStack writerStack,
 57  74
       Map<String, NamespaceSet> map) {
 58  74
     this.parent = parent;
 59  74
     this.writerStack = writerStack;
 60  74
     this.namespaces = map;
 61  74
   }
 62  
 
 63  
   /**
 64  
    * Create a {@link HierarchicalStreamReader}, using the wrapped
 65  
    * {@link HierarchicalStreamDriver}.
 66  
    * 
 67  
    * @param reader
 68  
    *          the Reader that will be used to read from the underlying stream
 69  
    * @return the reader
 70  
    * @see com.thoughtworks.xstream.io.HierarchicalStreamDriver#createReader(java.
 71  
    *      io.Reader)
 72  
    */
 73  
   public HierarchicalStreamReader createReader(Reader reader) {
 74  5
     return parent.createReader(reader);
 75  
   }
 76  
 
 77  
   /**
 78  
    * Create a {@link HierarchicalStreamReader}, using the wrapped
 79  
    * {@link HierarchicalStreamDriver}.
 80  
    * 
 81  
    * @param inputStream
 82  
    *          the input stream that will be used to read from the underlying
 83  
    *          stream
 84  
    * @return the reader
 85  
    * @see com.thoughtworks.xstream.io.HierarchicalStreamDriver#createReader(java.
 86  
    *      io.InputStream)
 87  
    */
 88  
   public HierarchicalStreamReader createReader(InputStream inputStream) {
 89  0
     return parent.createReader(inputStream);
 90  
   }
 91  
 
 92  
   /**
 93  
    * Create a {@link HierarchicalStreamWriter} that tracks the path to the
 94  
    * current element based on a {@link Writer}.
 95  
    * 
 96  
    * @param writer
 97  
    *          the underlying writer that will perform the writes.
 98  
    * @return the writer
 99  
    * @see com.thoughtworks.xstream.io.HierarchicalStreamDriver#createWriter(java.
 100  
    *      io.Writer)
 101  
    */
 102  
   public HierarchicalStreamWriter createWriter(Writer writer) {
 103  37
     HierarchicalStreamWriter parentWriter = parent.createWriter(writer);
 104  37
     return new StackWriterWrapper(parentWriter, writerStack, namespaces);
 105  
   }
 106  
 
 107  
   /**
 108  
    * Create a {@link HierarchicalStreamWriter} that tracks the path to the
 109  
    * current element based on a {@link OutputStream}.
 110  
    * 
 111  
    * @param outputStream
 112  
    *          the underlying output stream that will perform the writes.
 113  
    * @return the writer
 114  
    * @see com.thoughtworks.xstream.io.HierarchicalStreamDriver#createWriter(java.
 115  
    *      io.Writer)
 116  
    */
 117  
   public HierarchicalStreamWriter createWriter(OutputStream outputStream) {
 118  0
     HierarchicalStreamWriter parentWriter = parent.createWriter(outputStream);
 119  0
     return new StackWriterWrapper(parentWriter, writerStack, namespaces);
 120  
   }
 121  
 
 122  
 }