View Javadoc

1   package org.apache.continuum.scm.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 org.apache.maven.scm.provider.ScmProvider;
23  import org.codehaus.plexus.spring.PlexusToSpringUtils;
24  import org.springframework.beans.BeansException;
25  import org.springframework.beans.factory.FactoryBean;
26  import org.springframework.context.ApplicationContext;
27  import org.springframework.context.ApplicationContextAware;
28  
29  import java.util.Map;
30  
31  /**
32   * <p>
33   * Factory bean to inject all beans of type {@link ScmProvider}
34   * </p>
35   * <p>
36   * <code>&lt;bean id="scmProviders" class="org.apache.continuum.scm.manager.spring.ScmManagerFactoryBean"/>
37   * </code>
38   * </p>
39   *
40   * @author Carlos Sanchez <carlos@apache.org>
41   * @version $Id: ScmProviderFactoryBean.java 1372260 2012-08-13 04:29:09Z brett $
42   */
43  public class ScmProviderFactoryBean
44      implements FactoryBean, ApplicationContextAware
45  {
46      private ApplicationContext applicationContext;
47  
48      /**
49       * FIXME : change how we find scm implementations
50       *
51       * @see org.springframework.beans.factory.FactoryBean#getObject()
52       */
53      public Object getObject()
54          throws Exception
55      {
56          Map<String, ScmProvider> providers;
57          /*
58           olamy : comment the pure spring use because we have a duplicate between cvs java and cvs native
59            
60           Map<String, ScmProvider> beans =
61              BeanFactoryUtils.beansOfTypeIncludingAncestors( applicationContext, ScmProvider.class );
62          
63         
64          for ( ScmProvider provider : beans.values() )
65          {
66              
67              if ( providers.containsKey( provider.getScmType() ) )
68              {
69                  throw new BeanInitializationException(
70                                                         "There are to ScmProvider beans in the appllication context for Scm type " +
71                                                             provider.getScmType() +
72                                                             ". Probably two conflicting scm implementations are present in the classpath." );
73              }
74              
75              if (log.isDebugEnabled())
76              {
77                  log.debug( "put provider with type " + provider.getScmType() + " and class " + provider.getClass().getName() );
78              }
79              providers.put( provider.getScmType(), provider );
80          }*/
81          providers = PlexusToSpringUtils.lookupMap( PlexusToSpringUtils.buildSpringId( ScmProvider.class ),
82                                                     applicationContext );
83          return providers;
84      }
85  
86      public Class getObjectType()
87      {
88          return Map.class;
89      }
90  
91      public boolean isSingleton()
92      {
93          return true;
94      }
95  
96      public void setApplicationContext( ApplicationContext applicationContext )
97          throws BeansException
98      {
99          this.applicationContext = applicationContext;
100     }
101 
102 }