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

File AbstractBeanOutputFilterStreamFactory.java

 

Coverage histogram

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

Code metrics

0
12
5
1
99
61
6
0.5
2.4
5
1.2

Classes

Class Line # Actions
AbstractBeanOutputFilterStreamFactory 45 12 0% 6 3
0.823529482.4%
 

Contributing tests

This file is covered by 67 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.output;
21   
22    import java.lang.reflect.ParameterizedType;
23    import java.util.Arrays;
24    import java.util.Collection;
25    import java.util.List;
26    import java.util.Map;
27   
28    import javax.inject.Inject;
29   
30    import org.xwiki.component.manager.ComponentLookupException;
31    import org.xwiki.component.manager.ComponentManager;
32    import org.xwiki.component.phase.InitializationException;
33    import org.xwiki.component.util.DefaultParameterizedType;
34    import org.xwiki.component.util.ReflectionUtils;
35    import org.xwiki.filter.AbstractBeanFilterStreamFactory;
36    import org.xwiki.filter.FilterException;
37    import org.xwiki.filter.input.BeanInputFilterStream;
38    import org.xwiki.filter.type.FilterStreamType;
39   
40    /**
41    * @param <P> the type of the class containing the parameters of the filter
42    * @version $Id: feae1eb47345f3c9a976e4afcc65ff31ae30a7b9 $
43    * @since 6.2M1
44    */
 
45    public abstract class AbstractBeanOutputFilterStreamFactory<P, F> extends AbstractBeanFilterStreamFactory<P> implements
46    BeanOutputFilterStreamFactory<P>
47    {
48    @Inject
49    private ComponentManager componentManager;
50   
51    private List<Class<?>> filerInterfaces;
52   
 
53  188 toggle public AbstractBeanOutputFilterStreamFactory(FilterStreamType type)
54    {
55  188 super(type);
56    }
57   
 
58  188 toggle @Override
59    public void initialize() throws InitializationException
60    {
61  188 super.initialize();
62   
63    // Get bean properties type
64  188 ParameterizedType genericType =
65    (ParameterizedType) ReflectionUtils.resolveType(AbstractBeanOutputFilterStreamFactory.class, getClass());
66  188 this.filerInterfaces =
67    Arrays.<Class<?>>asList(ReflectionUtils.getTypeClass(genericType.getActualTypeArguments()[1]));
68    }
69   
 
70  0 toggle @Override
71    public Collection<Class<?>> getFilterInterfaces() throws FilterException
72    {
73  0 return this.filerInterfaces;
74    }
75   
 
76  63 toggle @Override
77    public OutputFilterStream createOutputFilterStream(Map<String, Object> properties) throws FilterException
78    {
79  63 return createOutputFilterStream(createPropertiesBean(properties));
80    }
81   
 
82  7650 toggle @Override
83    public BeanOutputFilterStream<P> createOutputFilterStream(P properties) throws FilterException
84    {
85  7650 BeanOutputFilterStream<P> inputFilter;
86  7650 try {
87  7650 inputFilter =
88    this.componentManager.getInstance(new DefaultParameterizedType(null, BeanOutputFilterStream.class,
89    getPropertiesBeanClass()), getType().serialize());
90    } catch (ComponentLookupException e) {
91  0 throw new FilterException(String.format("Failed to get instance of [%s] for type [%s]",
92    BeanInputFilterStream.class, getType()), e);
93    }
94   
95  7650 inputFilter.setProperties(properties);
96   
97  7650 return inputFilter;
98    }
99    }