Coverage Report - org.dozer.loader.xml.MappingStreamReader
 
Classes in this File Line Coverage Branch Coverage Complexity
MappingStreamReader
92%
13/14
N/A
1.5
 
 1  
 /**
 2  
  * Copyright 2005-2013 Dozer Project
 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.dozer.loader.xml;
 17  
 
 18  
 import org.dozer.classmap.MappingFileData;
 19  
 import org.dozer.loader.MappingsSource;
 20  
 import org.dozer.util.MappingUtils;
 21  
 import org.slf4j.Logger;
 22  
 import org.slf4j.LoggerFactory;
 23  
 import org.w3c.dom.Document;
 24  
 
 25  
 import javax.xml.parsers.DocumentBuilder;
 26  
 import java.io.InputStream;
 27  
 
 28  
 /**
 29  
  * Internal class that reads and parses a single custom mapping XML stream into
 30  
  * raw ClassMap objects. Only intended for internal use.
 31  
  * 
 32  
  * @author suwarnaratana.arm
 33  
  */
 34  0
 public class MappingStreamReader implements MappingsSource<InputStream> {
 35  
 
 36  1
         private static final Logger log = LoggerFactory
 37  
                         .getLogger(MappingStreamReader.class);
 38  
 
 39  
         private final DocumentBuilder documentBuilder;
 40  
   private final MappingsSource<Document> parser;
 41  
 
 42  703
         public MappingStreamReader(XMLParserFactory parserFactory) {
 43  703
     this.documentBuilder = parserFactory.createParser();
 44  703
     this.parser = new XMLParser();
 45  703
         }
 46  
 
 47  
         public MappingFileData read(InputStream xmlStream) {
 48  605
                 MappingFileData result = null;
 49  
                 try {
 50  605
                         Document document = documentBuilder.parse(xmlStream);
 51  600
                         result = parser.read(document);
 52  9
                 } catch (Throwable e) {
 53  9
                         log.error("Error while loading dozer mapping InputStream: ["
 54  
                                         + xmlStream + "]", e);
 55  9
                         MappingUtils.throwMappingException(e);
 56  596
                 }
 57  596
                 return result;
 58  
         }
 59  
 
 60  
 }