1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.filter.input

File AbstractBeanInputFilterStreamFactory.java

 

Coverage histogram

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

Code metrics

0
12
5
1
100
61
6
0.5
2.4
5
1.2

Classes

Class Line # Actions
AbstractBeanInputFilterStreamFactory 46 12 0% 6 1
0.941176594.1%
 

Contributing tests

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