1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.filter.xml.internal.parameter

File XMLTreeMarshaller.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
15
3
1
89
45
8
0.53
5
3
2.67

Classes

Class Line # Actions
XMLTreeMarshaller 41 15 0% 8 3
0.8928571389.3%
 

Contributing tests

This file is covered by 301 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.filter.xml.internal.parameter;
21   
22    import java.lang.reflect.Type;
23   
24    import org.xwiki.component.util.ReflectionUtils;
25   
26    import com.thoughtworks.xstream.converters.ConversionException;
27    import com.thoughtworks.xstream.converters.Converter;
28    import com.thoughtworks.xstream.converters.ConverterLookup;
29    import com.thoughtworks.xstream.converters.DataHolder;
30    import com.thoughtworks.xstream.converters.reflection.ReflectionConverter;
31    import com.thoughtworks.xstream.core.TreeMarshaller;
32    import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
33    import com.thoughtworks.xstream.mapper.Mapper;
34   
35    /**
36    * Customize {@link TreeMarshaller}.
37    *
38    * @version $Id: 98203bf3a6ee667f3eb79594ff8b6b26697f4780 $
39    * @since 5.2M1
40    */
 
41    public class XMLTreeMarshaller extends TreeMarshaller
42    {
43    /**
44    * @param writer the writer
45    * @param converterLookup the converter provider
46    * @param mapper the mapper
47    */
 
48  1418 toggle public XMLTreeMarshaller(HierarchicalStreamWriter writer, ConverterLookup converterLookup, Mapper mapper)
49    {
50  1418 super(writer, converterLookup, mapper);
51    }
52   
 
53  1418 toggle @Override
54    public void start(Object item, DataHolder dataHolder)
55    {
56  1418 Type type = (Type) dataHolder.get(XStreamParameterManager.DDEFAULTTYPE_NAME);
57  1418 if (item != null) {
58  1418 Converter converter = getConverter(type);
59   
60  1418 if (converter == null) {
61  1079 convertAnother(item);
62    } else {
63  339 convert(item, converter);
64    }
65    }
66    }
67   
68    /**
69    * @param type the type
70    * @return the converter corresponding to the passed type
71    */
 
72  1418 toggle private Converter getConverter(Type type)
73    {
74  1418 if (type != null) {
75  1408 Class<?> typeClass = ReflectionUtils.getTypeClass(type);
76  1408 if (typeClass == null) {
77  0 throw new ConversionException("Can't find any converter for the type [" + type + "]");
78    }
79   
80  1408 Converter converter = this.converterLookup.lookupConverterForType(typeClass);
81   
82  1408 if (converter.getClass() != ReflectionConverter.class) {
83  339 return converter;
84    }
85    }
86   
87  1079 return null;
88    }
89    }