1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.job.internal.xstream

File SafeTreeMarshaller.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
10
2
1
78
35
4
0.4
5
2
2

Classes

Class Line # Actions
SafeTreeMarshaller 37 10 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 34 tests. .

Source view

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.job.internal.xstream;
21   
22    import org.slf4j.Logger;
23    import org.slf4j.LoggerFactory;
24   
25    import com.thoughtworks.xstream.converters.Converter;
26    import com.thoughtworks.xstream.converters.ConverterLookup;
27    import com.thoughtworks.xstream.core.ReferenceByXPathMarshaller;
28    import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
29    import com.thoughtworks.xstream.mapper.Mapper;
30   
31    /**
32    * A {@link ReferenceByXPathMarshaller} which never fail whatever value is provided.
33    *
34    * @version $Id: 5cae5ea1b36c213e359d11cd3d4a3071cc58121b $
35    * @since 5.4M1
36    */
 
37    public class SafeTreeMarshaller extends ReferenceByXPathMarshaller
38    {
39    private static final Logger LOGGER = LoggerFactory.getLogger(SafeTreeMarshaller.class);
40   
41    protected SafeWriter safeWriter;
42   
43    /**
44    * @see ReferenceByXPathMarshaller#ReferenceByXPathMarshaller(HierarchicalStreamWriter, ConverterLookup, Mapper,
45    * int)
46    * @param writer the writer
47    * @param converterLookup the converter lookup
48    * @param mapper the mapper
49    * @param mode the marshalling mode
50    */
 
51  158 toggle public SafeTreeMarshaller(HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper, int mode)
52    {
53  158 super(writer, converterLookup, mapper, mode);
54    }
55   
 
56  36252 toggle @Override
57    public void convert(Object item, Converter converter)
58    {
59  36250 if (XStreamUtils.isSerializable(item)) {
60  36250 HierarchicalStreamWriter currentWriter = this.writer;
61   
62  36249 try {
63  36249 this.safeWriter = new SafeWriter(this.writer);
64  36249 this.writer = this.safeWriter;
65   
66  36249 super.convert(item, converter);
67    } catch (Throwable e) {
68  1 LOGGER.debug("Failed to serialize item [{}]",
69    item.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(item)), e);
70   
71    // Make sure to close any forgotten end tag
72  1 this.safeWriter.fix();
73    } finally {
74  36247 this.writer = currentWriter;
75    }
76    }
77    }
78    }