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

File ComponentCreatedListener.java

 

Coverage histogram

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

Code metrics

2
8
3
1
86
47
4
0.5
2.67
3
1.33

Classes

Class Line # Actions
ComponentCreatedListener 43 8 0% 4 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 javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.component.event.ComponentDescriptorAddedEvent;
29    import org.xwiki.component.manager.ComponentManager;
30    import org.xwiki.observation.AbstractEventListener;
31    import org.xwiki.observation.event.Event;
32   
33    /**
34    * Make sure to clean any existing context cache when a new {@link org.xwiki.component.manager.ComponentManager} is
35    * created.
36    *
37    * @version $Id: 745a689bcf07acd80aa139f5a64d884f33fe78bc $
38    * @since 7.1RC1
39    */
40    @Component
41    @Named("org.xwiki.component.internal.ComponentCreatedListener")
42    @Singleton
 
43    public class ComponentCreatedListener extends AbstractEventListener
44    {
45    @Inject
46    @Named(UserComponentManager.ID)
47    private Provider<ComponentManager> userComponentManagerProvider;
48   
49    @Inject
50    @Named(DocumentComponentManager.ID)
51    private Provider<ComponentManager> documentComponentManagerProvider;
52   
53    @Inject
54    @Named(SpaceComponentManager.ID)
55    private Provider<ComponentManager> spaceComponentManagerProvider;
56   
57    @Inject
58    @Named(WikiComponentManager.ID)
59    private Provider<ComponentManager> wikiComponentManagerProvider;
60   
61    /**
62    * Default constructor.
63    */
 
64  199 toggle public ComponentCreatedListener()
65    {
66  199 super(ComponentCreatedListener.class.getName(), new ComponentDescriptorAddedEvent());
67    }
68   
 
69  683 toggle @Override
70    public void onEvent(Event event, Object source, Object data)
71    {
72  683 notifyComponentManager(this.userComponentManagerProvider);
73  683 notifyComponentManager(this.documentComponentManagerProvider);
74  683 notifyComponentManager(this.spaceComponentManagerProvider);
75  683 notifyComponentManager(this.wikiComponentManagerProvider);
76    }
77   
 
78  2732 toggle private void notifyComponentManager(Provider<ComponentManager> provider)
79    {
80  2732 ComponentManager componentManager = provider.get();
81   
82  2732 if (componentManager instanceof AbstractEntityComponentManager) {
83  2732 ((AbstractEntityComponentManager) componentManager).onComponentAdded();
84    }
85    }
86    }