1. Project Clover database Sat Feb 2 2019 06:45:20 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
90
51
4
0.5
2.67
3
1.33

Classes

Class Line # Actions
ComponentCreatedListener 47 8 0% 4 1
0.923076992.3%
 

Contributing tests

This file is covered by 78 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.model.namespace.DocumentNamespace;
31    import org.xwiki.model.namespace.SpaceNamespace;
32    import org.xwiki.model.namespace.UserNamespace;
33    import org.xwiki.model.namespace.WikiNamespace;
34    import org.xwiki.observation.AbstractEventListener;
35    import org.xwiki.observation.event.Event;
36   
37    /**
38    * Make sure to clean any existing context cache when a new {@link org.xwiki.component.manager.ComponentManager} is
39    * created.
40    *
41    * @version $Id: 9a7c457f49ea5f200cc27ec917c38623af020631 $
42    * @since 7.1RC1
43    */
44    @Component
45    @Named("org.xwiki.component.internal.ComponentCreatedListener")
46    @Singleton
 
47    public class ComponentCreatedListener extends AbstractEventListener
48    {
49    @Inject
50    @Named(UserNamespace.TYPE)
51    private Provider<ComponentManager> userComponentManagerProvider;
52   
53    @Inject
54    @Named(DocumentNamespace.TYPE)
55    private Provider<ComponentManager> documentComponentManagerProvider;
56   
57    @Inject
58    @Named(SpaceNamespace.TYPE)
59    private Provider<ComponentManager> spaceComponentManagerProvider;
60   
61    @Inject
62    @Named(WikiNamespace.TYPE)
63    private Provider<ComponentManager> wikiComponentManagerProvider;
64   
65    /**
66    * Default constructor.
67    */
 
68  223 toggle public ComponentCreatedListener()
69    {
70  223 super(ComponentCreatedListener.class.getName(), new ComponentDescriptorAddedEvent());
71    }
72   
 
73  5017 toggle @Override
74    public void onEvent(Event event, Object source, Object data)
75    {
76  5017 notifyComponentManager(this.userComponentManagerProvider);
77  5017 notifyComponentManager(this.documentComponentManagerProvider);
78  5017 notifyComponentManager(this.spaceComponentManagerProvider);
79  5017 notifyComponentManager(this.wikiComponentManagerProvider);
80    }
81   
 
82  20068 toggle private void notifyComponentManager(Provider<ComponentManager> provider)
83    {
84  20068 ComponentManager componentManager = provider.get();
85   
86  20068 if (componentManager instanceof AbstractEntityComponentManager) {
87  20068 ((AbstractEntityComponentManager) componentManager).onComponentAdded();
88    }
89    }
90    }