001package org.apache.archiva.metadata.repository; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.slf4j.Logger; 023import org.slf4j.LoggerFactory; 024import org.springframework.beans.factory.config.AbstractFactoryBean; 025 026import java.util.Properties; 027 028/** 029 * @author Olivier Lamy 030 * @since 2.0.2 031 */ 032public class RepositorySessionFactoryBean 033 extends AbstractFactoryBean<RepositorySessionFactory> 034{ 035 036 private Logger logger = LoggerFactory.getLogger( getClass() ); 037 038 private static final String BEAN_ID_SYS_PROPS = "archiva.repositorySessionFactory.id"; 039 040 private Properties properties; 041 042 private String id; 043 044 public RepositorySessionFactoryBean( Properties properties ) 045 { 046 this.properties = properties; 047 // we can override with system props 048 String value = System.getProperty( BEAN_ID_SYS_PROPS ); 049 if ( value != null ) 050 { 051 this.properties.put( BEAN_ID_SYS_PROPS, value ); 052 } 053 id = properties.getProperty( BEAN_ID_SYS_PROPS ); 054 } 055 056 @Override 057 public Class<RepositorySessionFactory> getObjectType() 058 { 059 return RepositorySessionFactory.class; 060 } 061 062 @Override 063 protected RepositorySessionFactory createInstance() 064 throws Exception 065 { 066 RepositorySessionFactory repositorySessionFactory = 067 getBeanFactory().getBean( "repositorySessionFactory#" + id, RepositorySessionFactory.class ); 068 logger.info( "create RepositorySessionFactory with id {} instance of {}", // 069 id, // 070 repositorySessionFactory.getClass().getName() ); 071 if (!repositorySessionFactory.isOpen()) { 072 repositorySessionFactory.open(); 073 } 074 return repositorySessionFactory; 075 } 076 077 public String getId() 078 { 079 return id; 080 } 081 082 public void setId( String id ) 083 { 084 this.id = id; 085 } 086 087 public Properties getProperties() 088 { 089 return properties; 090 } 091 092 public void setProperties( Properties properties ) 093 { 094 this.properties = properties; 095 } 096}