Coverage details for net.sourceforge.demetrix.util.XmlSerializerDeserializer

LineHitsSource
1 /*******************************************************************************
2  
3  * Demetrix process modelling system
4  
5  *
6  
7  * Copyright (c) 2003, 2004 Dimitri A. Pissarenko
8  
9  *
10  
11  * This file is part of Demetrix.
12  
13  *
14  
15  * Demetrix is free software; you can redistribute it and/or modify
16  
17  * it under the terms of the GNU General Public License as published by
18  
19  * the Free Software Foundation; either version 2.1 of the License, or
20  
21  * (at your option) any later version.
22  
23  *
24  
25  * Demetrix is distributed in the hope that it will be useful,
26  
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  
31  * GNU General Public License for more details.
32  
33  *
34  
35  * You should have received a copy of the GNU General Public License
36  
37  * along with Demetrix; if not, write to the Free Software
38  
39  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40  
41  *
42  
43  * For further information you may
44  
45  *
46  
47  * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net
48  
49  * - look at http://sourceforge.net/projects/demetrix/
50  
51  * - look at http://demetrix.sourceforge.net/
52  
53  * - look at http://members.inode.at/d.pissarenko/
54  
55  *
56  
57  *****************************************************************************/
58  
59 package net.sourceforge.demetrix.util;
60  
61  
62  
63 import java.io.BufferedInputStream;
64  
65 import java.io.File;
66  
67 import java.io.FileInputStream;
68  
69 import java.io.FileNotFoundException;
70  
71 import java.io.FileOutputStream;
72  
73 import java.io.IOException;
74  
75  
76  
77 import javax.xml.transform.Transformer;
78  
79 import javax.xml.transform.TransformerConfigurationException;
80  
81 import javax.xml.transform.TransformerException;
82  
83 import javax.xml.transform.TransformerFactory;
84  
85 import javax.xml.transform.sax.SAXSource;
86  
87 import javax.xml.transform.stream.StreamResult;
88  
89  
90  
91 import org.apache.log4j.Logger;
92  
93 import org.jxv.config.JXVConfig;
94  
95 import org.jxv.document.reader.DocumentReader;
96  
97 import org.jxv.document.sax.DocumentSAXView;
98  
99 import org.jxv.reader.JXVReaderHelper;
100  
101 import org.xml.sax.InputSource;
102  
103  
104  
105 /**
106  
107  * @author Dimitri Pissarenko
108  
109  *
110  
111  */
112  
113 public class XmlSerializerDeserializer {
114  
115     private static XmlSerializerDeserializer instance;
116  
117     private Transformer transformer;
118  
119     private Logger logger;
120  
121     public final static String JXV_CONFIG_FILE_NAME="config/jxv-config.xml";
122  
123  
124  
125     
126  
127     protected XmlSerializerDeserializer()
128  
1290    {
130  
131         this.logger=Logger.getLogger(getClass());
132  
1330        JXVConfig.getSystemConfig().getBaseContext().importXMLConfig(XmlSerializerDeserializer.JXV_CONFIG_FILE_NAME);
134  
135         try
136  
137         {
138  
1390            this.transformer=TransformerFactory.newInstance().newTransformer();
140  
141         }
142  
1430        catch (TransformerConfigurationException exception)
144  
145         {
146  
147             this.logger.error("", exception);
148  
1490        }
150  
1510    }
152  
153     public static XmlSerializerDeserializer getInstance()
154  
155     {
156  
1570        if (instance==null)
158  
159         {
160  
1610            instance=new XmlSerializerDeserializer();
162  
163         }
164  
1650        return instance;
166  
167     }
168  
169     public void writeObject(Object object2Export, File targetFile, String configName)
170  
171     {
172  
1730        FileOutputStream fileOutputStream = null;
174  
1750        SAXSource src=null;
176  
177  
178  
179         try
180  
181         {
182  
1830            fileOutputStream = new FileOutputStream(targetFile);
184  
185  
186  
187  
188  
1890            src = DocumentSAXView.getInstance(object2Export.getClass(),
190  
191             configName).getSAXSource(object2Export);
192  
1930            transformer.transform(src, new StreamResult(fileOutputStream));
194  
195  
196  
1970            fileOutputStream.close();
198  
199         }
200  
2010        catch (FileNotFoundException exception)
202  
203         {
204  
205             this.logger.error("", exception);
206  
207         }
208  
2090        catch (TransformerException exception)
210  
211         {
212  
213             this.logger.error("", exception);
214  
215         }
216  
2170        catch (IOException exception)
218  
219         {
220  
221             this.logger.error("", exception);
222  
2230        }
224  
2250    }
226  
227     public Object readObject(File file, Class classToRead, String configName)
228  
229     {
230  
2310        Object returnValue=null;
232  
2330        DocumentReader reader=null;
234  
2350        BufferedInputStream bufferedInputStream=null;
236  
237         
238  
239         try
240  
241         {
242  
2430            bufferedInputStream=new BufferedInputStream(new FileInputStream(file));
244  
2450            reader=new DocumentReader(classToRead, configName);
246  
2470            returnValue=JXVReaderHelper.read(new InputSource(bufferedInputStream), reader);
248  
2490            bufferedInputStream.close();
250  
251         }
252  
2530        catch (Exception exception)
254  
255         {
256  
257             this.logger.error("", exception);
258  
2590        }
260  
2610        return returnValue;
262  
263     }
264  
265 }
266  

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.