This project has retired. For details please refer to its Attic page.
RepositorySessionFactoryBean xref
View Javadoc
1   package org.apache.archiva.metadata.repository;
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.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  import org.springframework.beans.factory.config.AbstractFactoryBean;
25  
26  import java.util.Properties;
27  
28  /**
29   * @author Olivier Lamy
30   * @since 2.0.2
31   */
32  public class RepositorySessionFactoryBean
33      extends AbstractFactoryBean<RepositorySessionFactory>
34  {
35  
36      private Logger logger = LoggerFactory.getLogger( getClass() );
37  
38      private static final String BEAN_ID_SYS_PROPS = "archiva.repositorySessionFactory.id";
39  
40      private Properties properties;
41  
42      private String id;
43  
44      public RepositorySessionFactoryBean( Properties properties )
45      {
46          this.properties = properties;
47          // we can override with system props
48          String value = System.getProperty( BEAN_ID_SYS_PROPS );
49          if ( value != null )
50          {
51              this.properties.put( BEAN_ID_SYS_PROPS, value );
52          }
53          id = properties.getProperty( BEAN_ID_SYS_PROPS );
54      }
55  
56      @Override
57      public Class<RepositorySessionFactory> getObjectType()
58      {
59          return RepositorySessionFactory.class;
60      }
61  
62      @Override
63      protected RepositorySessionFactory createInstance()
64          throws Exception
65      {
66          RepositorySessionFactory repositorySessionFactory =
67              getBeanFactory().getBean( "repositorySessionFactory#" + id, RepositorySessionFactory.class );
68          logger.info( "create RepositorySessionFactory with id {} instance of {}", //
69                       id, //
70                       repositorySessionFactory.getClass().getName() );
71          return repositorySessionFactory;
72      }
73  
74      public String getId()
75      {
76          return id;
77      }
78  
79      public void setId( String id )
80      {
81          this.id = id;
82      }
83  
84      public Properties getProperties()
85      {
86          return properties;
87      }
88  
89      public void setProperties( Properties properties )
90      {
91          this.properties = properties;
92      }
93  }