Coverage Report - org.codehaus.plexus.component.discovery.DefaultComponentDiscovererManager
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultComponentDiscovererManager
63 %
12/19
25 %
1/4
1,333
 
 1  
 package org.codehaus.plexus.component.discovery;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 Codehaus Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 import java.util.Set;
 22  
 import java.util.Map;
 23  
 import java.util.LinkedHashMap;
 24  
 
 25  61
 public class DefaultComponentDiscovererManager
 26  
     implements ComponentDiscovererManager
 27  
 {
 28  61
     private final List<ComponentDiscoverer> componentDiscoverers = new ArrayList<ComponentDiscoverer>();
 29  
 
 30  
     // todo dain change this to LinkedHashSet<ComponentDiscoveryListener> (requires change to maven)
 31  61
     private final Map<ComponentDiscoveryListener, Object> listeners = new LinkedHashMap<ComponentDiscoveryListener, Object>();
 32  
 
 33  
     public synchronized void addComponentDiscoverer( ComponentDiscoverer discoverer )
 34  
     {
 35  122
         componentDiscoverers.add( discoverer );
 36  122
     }
 37  
 
 38  
     // todo this is not thread safe... we are returning the raw collection
 39  
     public synchronized List<ComponentDiscoverer> getComponentDiscoverers()
 40  
     {
 41  140
         return componentDiscoverers;
 42  
     }
 43  
 
 44  
     // Listeners
 45  
 
 46  
     // todo this is not thread safe... we are returning the raw collection
 47  
     public synchronized Map<ComponentDiscoveryListener, Object> getComponentDiscoveryListeners()
 48  
     {
 49  61
         return listeners;
 50  
     }
 51  
 
 52  
     public synchronized void registerComponentDiscoveryListener( ComponentDiscoveryListener listener )
 53  
     {
 54  0
         if ( !listeners.containsKey( listener ) )
 55  
         {
 56  0
             listeners.put( listener, new Object() );
 57  
         }
 58  0
     }
 59  
 
 60  
     public synchronized void removeComponentDiscoveryListener( ComponentDiscoveryListener listener )
 61  
     {
 62  0
         listeners.remove( listener );
 63  0
     }
 64  
 
 65  
     public void fireComponentDiscoveryEvent( ComponentDiscoveryEvent event )
 66  
     {
 67  
         Set<ComponentDiscoveryListener> listeners;
 68  515
         synchronized ( this )
 69  
         {
 70  517
             listeners = this.listeners.keySet();
 71  517
         }
 72  
 
 73  517
         for ( ComponentDiscoveryListener listener : listeners )
 74  
         {
 75  0
             listener.componentDiscovered( event );
 76  0
         }
 77  517
     }
 78  
 }