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

File SafeArrayConverter.java

 

Coverage histogram

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

Code metrics

2
16
4
1
92
50
7
0.44
4
4
1.75

Classes

Class Line # Actions
SafeArrayConverter 37 16 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 189 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.MarshallingContext;
26    import com.thoughtworks.xstream.converters.UnmarshallingContext;
27    import com.thoughtworks.xstream.converters.collections.ArrayConverter;
28    import com.thoughtworks.xstream.io.HierarchicalStreamReader;
29    import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
30   
31    /**
32    * A {@link ArrayConverter} which never fail whatever value is provided.
33    *
34    * @version $Id: 348ca4681d132ef847eb6e3d061e14e7dedf7838 $
35    * @since 4.3M1
36    */
 
37    public class SafeArrayConverter extends ArrayConverter
38    {
39    /**
40    * The logger.
41    */
42    private static final Logger LOGGER = LoggerFactory.getLogger(SafeArrayConverter.class);
43   
44    /**
45    * @param xstream the {@link com.thoughtworks.xstream.XStream} instance to use to isolate array element marshaling
46    */
 
47  1389 toggle public SafeArrayConverter(SafeXStream xstream)
48    {
49  1389 super(xstream.getMapper());
50    }
51   
 
52  1763 toggle @Override
53    public boolean canConvert(Class type)
54    {
55  1763 return type == Object[].class;
56    }
57   
 
58  178 toggle @Override
59    protected Object readItem(HierarchicalStreamReader reader, UnmarshallingContext context, Object current)
60    {
61  178 Object value;
62  178 try {
63  178 value = super.readItem(reader, context, current);
64    } catch (Throwable e) {
65  8 LOGGER.debug("Failed to read field", e);
66   
67  8 value = null;
68    }
69   
70  178 return value;
71    }
72   
 
73  1862 toggle @Override
74    protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer)
75    {
76  1862 if (XStreamUtils.isSerializable(item)) {
77  1860 super.writeItem(item, context, writer);
78    } else {
79  2 String str;
80  2 try {
81  2 str = item.toString();
82    } catch (Throwable e) {
83  1 LOGGER.debug("Failed to convert item [{}] to String",
84    item.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(item)), e);
85   
86  1 str = null;
87    }
88   
89  2 super.writeItem(str, context, writer);
90    }
91    }
92    }