1 16 package net.sf.dozer.util.mapping.util; 17 18 import java.io.IOException ; 19 import java.io.InputStream ; 20 import java.net.URL ; 21 22 import net.sf.dozer.util.mapping.fieldmap.Mappings; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 31 public class MappingFileReader { 32 private static final Log log = LogFactory.getLog(MappingFileReader.class); 33 34 private final URL url; 35 private final MappingUtils mappingUtils = new MappingUtils(); 36 37 public MappingFileReader(URL url) { 38 this.url = url; 39 } 40 41 public MappingFileReader(String fileName) { 42 Loader loader = new Loader(); 43 url = loader.getResource(fileName); 44 } 45 46 public Mappings read() { 47 Mappings result = null; 48 InputStream stream = null; 49 try { 50 XMLParser parser = new XMLParser(); 51 stream = url.openStream(); 52 result = parser.parse(stream); 53 } catch (Throwable e) { 54 log.error("Error in loading dozer mapping file url: [" + url + "] : " + e); 55 mappingUtils.throwMappingException(e); 56 } finally { 57 try { 58 if (stream != null) { 59 stream.close(); 60 } 61 } catch (IOException e) { 62 mappingUtils.throwMappingException(e); 63 } 64 } 65 return result; 66 } 67 68 } | Popular Tags |