Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
12   79   3   4
0   41   0.25   3
3     1  
1    
 
  XStreamParameterManager       Line # 42 12 0% 3 0 100% 1.0
 
  (12)
 
1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.xdomxml.internal.current.parameter;
21   
22    import java.lang.reflect.Type;
23   
24    import org.dom4j.Element;
25    import org.xml.sax.ContentHandler;
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.component.phase.Initializable;
28    import org.xwiki.component.phase.InitializationException;
29   
30    import com.thoughtworks.xstream.XStream;
31    import com.thoughtworks.xstream.converters.DataHolder;
32    import com.thoughtworks.xstream.core.MapBackedDataHolder;
33    import com.thoughtworks.xstream.io.xml.Dom4JReader;
34    import com.thoughtworks.xstream.io.xml.SaxWriter;
35   
36    /**
37    * XStream based implementation of {@link ParameterManager}.
38    *
39    * @version $Id: 312392ad4f67f40d10fb744182d4071e817e9b0f $
40    */
41    @Component
 
42    public class XStreamParameterManager implements ParameterManager, Initializable
43    {
44    private XStream xstream;
45   
 
46  12 toggle @Override
47    public void initialize() throws InitializationException
48    {
49  12 this.xstream = new XStream();
50   
51  12 this.xstream.setMarshallingStrategy(new XDOMXMLTreeMarshallingStrategy());
52   
53  12 this.xstream.registerConverter(new XDOMXMLCollectionConverter(this.xstream.getMapper()));
54  12 this.xstream.registerConverter(new XDOMXMLMapConverter(this.xstream.getMapper()));
55    }
56   
 
57  106 toggle @Override
58    public void serialize(Type type, Object object, ContentHandler xmlContent)
59    {
60  106 SaxWriter saxWriter = new SaxWriter(false);
61  106 saxWriter.setContentHandler(xmlContent);
62   
63  106 DataHolder dataHolder = new MapBackedDataHolder();
64   
65  106 dataHolder.put("type", type);
66   
67  106 this.xstream.marshal(object, saxWriter, dataHolder);
68    }
69   
 
70  104 toggle @Override
71    public Object unSerialize(Type type, Element rootElement)
72    {
73  104 DataHolder dataHolder = new MapBackedDataHolder();
74   
75  104 dataHolder.put("type", type);
76   
77  104 return this.xstream.unmarshal(new Dom4JReader(rootElement), null, dataHolder);
78    }
79    }