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

File CompositeFilter.java

 

Coverage histogram

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

Code metrics

0
11
3
2
83
43
4
0.36
3.67
1.5
1.33

Classes

Class Line # Actions
CompositeFilter 37 9 0% 3 1
0.9090909490.9%
CompositeFilter.SubFilter 43 2 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 12 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.internal;
21   
22    import java.lang.reflect.InvocationHandler;
23    import java.lang.reflect.InvocationTargetException;
24    import java.lang.reflect.Method;
25    import java.util.ArrayList;
26    import java.util.List;
27   
28    import org.xwiki.filter.FilterDescriptor;
29    import org.xwiki.filter.FilterDescriptorManager;
30   
31    /**
32    * Support any event in input and pass them to a list of filters.
33    *
34    * @version $Id: cb0425a03ced28d3934c1d3911bee9f85ff1ba35 $
35    * @since 5.2
36    */
 
37    public class CompositeFilter implements InvocationHandler
38    {
39    private FilterDescriptorManager filterManager;
40   
41    private List<SubFilter> filters;
42   
 
43    private static class SubFilter
44    {
45    public final Object filter;
46   
47    public final FilterDescriptor descriptor;
48   
 
49  86 toggle public SubFilter(Object filter, FilterDescriptor descriptor)
50    {
51  86 this.filter = filter;
52  86 this.descriptor = descriptor;
53    }
54    }
55   
56    /**
57    * @param filters the filters
58    * @param filterManager the filter descriptor manager used to generate passed filter descriptors
59    */
 
60  44 toggle public CompositeFilter(FilterDescriptorManager filterManager, Object... filters)
61    {
62  44 this.filterManager = filterManager;
63   
64  44 this.filters = new ArrayList<SubFilter>(filters.length);
65  44 for (Object filter : filters) {
66  86 this.filters.add(new SubFilter(filter, this.filterManager.getFilterDescriptor(filter.getClass())));
67    }
68    }
69   
 
70  1510 toggle @Override
71    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
72    {
73  1510 for (SubFilter filter : this.filters) {
74  3010 try {
75  3010 FilterProxy.invoke(filter.filter, filter.descriptor, method, args);
76    } catch (InvocationTargetException e) {
77  0 throw e.getCause();
78    }
79    }
80   
81  1510 return null;
82    }
83    }