1   package org.apache.maven.continuum.notification.manager.spring;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  import org.apache.maven.continuum.notification.Notifier;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  import org.springframework.beans.BeansException;
26  import org.springframework.beans.factory.BeanFactoryUtils;
27  import org.springframework.beans.factory.BeanInitializationException;
28  import org.springframework.beans.factory.FactoryBean;
29  import org.springframework.context.ApplicationContext;
30  import org.springframework.context.ApplicationContextAware;
31  
32  import java.util.HashMap;
33  import java.util.Map;
34  
35  
36  
37  
38  
39  public class NotifierFactoryBean
40      implements FactoryBean, ApplicationContextAware
41  {
42      private static final Logger log = LoggerFactory.getLogger( NotifierFactoryBean.class );
43  
44      private ApplicationContext applicationContext;
45  
46      public Object getObject()
47          throws Exception
48      {
49          Map<String, Notifier> notifiers = new HashMap<String, Notifier>();
50  
51          Map<String, Notifier> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors( applicationContext,
52                                                                                        Notifier.class );
53  
54          for ( Notifier notifier : beans.values() )
55          {
56  
57              if ( notifiers.containsKey( notifier.getType() ) )
58              {
59                  throw new BeanInitializationException(
60                      "There are two Notifier beans in the appllication context for Notifier type " + notifier.getType() +
61                          ". Probably two conflicting scm implementations are present in the classpath." );
62              }
63  
64              if ( log.isDebugEnabled() )
65              {
66                  log.debug(
67                      "put provider with type " + notifier.getType() + " and class " + notifier.getClass().getName() );
68              }
69              notifiers.put( notifier.getType(), notifier );
70          }
71          return notifiers;
72      }
73  
74      public Class getObjectType()
75      {
76          return Map.class;
77      }
78  
79      public boolean isSingleton()
80      {
81          return true;
82      }
83  
84      public void setApplicationContext( ApplicationContext applicationContext )
85          throws BeansException
86      {
87          this.applicationContext = applicationContext;
88      }
89  }