1. Project Clover database Sat Feb 2 2019 06:45:20 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 40 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  21536 toggle public SafeTreeMarshaller(HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper, int mode)
52    {
53  21529 super(writer, converterLookup, mapper, mode);
54    }
55   
 
56  262376 toggle @Override
57    public void convert(Object item, Converter converter)
58    {
59  262415 if (XStreamUtils.isSerializable(item)) {
60  241231 HierarchicalStreamWriter currentWriter = this.writer;
61   
62  241234 try {
63  241247 this.safeWriter = new SafeWriter(this.writer);
64  241246 this.writer = this.safeWriter;
65   
66  241245 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  241256 this.writer = currentWriter;
75    }
76    }
77    }
78    }