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

File DocumentDeletedListener.java

 

Coverage histogram

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

Code metrics

2
8
3
1
94
52
5
0.62
2.67
3
1.67

Classes

Class Line # Actions
DocumentDeletedListener 49 8 0% 5 1
0.923076992.3%
 

Contributing tests

This file is covered by 74 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.component.internal;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.slf4j.Logger;
30    import org.xwiki.bridge.event.DocumentDeletedEvent;
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.component.internal.multi.ComponentManagerManager;
33    import org.xwiki.component.manager.ComponentLifecycleException;
34    import org.xwiki.component.manager.ComponentManager;
35    import org.xwiki.component.phase.Disposable;
36    import org.xwiki.model.EntityType;
37    import org.xwiki.observation.EventListener;
38    import org.xwiki.observation.event.Event;
39   
40    /**
41    * Make sure to dispose the {@link ComponentManager} associated to a deleted document.
42    *
43    * @version $Id: 06065dd05222d6581f3eaa460700d80da7a80aaf $
44    * @since 5.2RC1
45    */
46    @Component
47    @Singleton
48    @Named("component.multi.DocumentDeletedListener")
 
49    public class DocumentDeletedListener implements EventListener
50    {
51    /**
52    * The list of events observed.
53    */
54    private static final List<Event> EVENTS = Arrays.<Event> asList(new DocumentDeletedEvent());
55   
56    /**
57    * Store and provide {@link ComponentManager} instances.
58    */
59    @Inject
60    private ComponentManagerManager componentManagerManager;
61   
62    @Inject
63    private Logger logger;
64   
 
65  682 toggle @Override
66    public String getName()
67    {
68  682 return "component.multi.DocumentDeletedListener";
69    }
70   
 
71  199 toggle @Override
72    public List<Event> getEvents()
73    {
74  199 return EVENTS;
75    }
76   
 
77  158 toggle @Override
78    public void onEvent(Event event, Object o, Object context)
79    {
80  158 String document = ((DocumentDeletedEvent) event).getEventFilter().getFilter();
81   
82  158 ComponentManager componentManager =
83    this.componentManagerManager.getComponentManager(EntityType.DOCUMENT.toString().toLowerCase() + ':'
84    + document, false);
85   
86  158 if (componentManager instanceof Disposable) {
87  1 try {
88  1 ((Disposable) componentManager).dispose();
89    } catch (ComponentLifecycleException e) {
90  0 this.logger.error(String.format("Failed to dispose component manager for document [%s]", document), e);
91    }
92    }
93    }
94    }