1 | package org.apache.maven.continuum.notification.manager.spring; |
2 | |
3 | /* |
4 | * Licensed to the Apache Software Foundation (ASF) under one |
5 | * or more contributor license agreements. See the NOTICE file |
6 | * distributed with this work for additional information |
7 | * regarding copyright ownership. The ASF licenses this file |
8 | * to you under the Apache License, Version 2.0 (the |
9 | * "License"); you may not use this file except in compliance |
10 | * with the License. You may obtain a copy of the License at |
11 | * |
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | * |
14 | * Unless required by applicable law or agreed to in writing, |
15 | * software distributed under the License is distributed on an |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
17 | * KIND, either express or implied. See the License for the |
18 | * specific language governing permissions and limitations |
19 | * under the License. |
20 | */ |
21 | |
22 | import java.util.HashMap; |
23 | import java.util.Map; |
24 | |
25 | import org.apache.maven.continuum.notification.Notifier; |
26 | import org.slf4j.Logger; |
27 | import org.slf4j.LoggerFactory; |
28 | import org.springframework.beans.BeansException; |
29 | import org.springframework.beans.factory.BeanFactoryUtils; |
30 | import org.springframework.beans.factory.BeanInitializationException; |
31 | import org.springframework.beans.factory.FactoryBean; |
32 | import org.springframework.context.ApplicationContext; |
33 | import org.springframework.context.ApplicationContextAware; |
34 | |
35 | /** |
36 | * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> |
37 | * @version $Id: NotifierFactoryBean.java 764863 2009-04-14 16:28:12Z evenisse $ |
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 = |
52 | BeanFactoryUtils.beansOfTypeIncludingAncestors( applicationContext, 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 | } |