001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.repository.util;
016    
017    import com.liferay.portal.kernel.repository.BaseRepository;
018    import com.liferay.portal.kernel.util.InstanceFactory;
019    import com.liferay.portal.kernel.util.ProxyFactory;
020    import com.liferay.portal.repository.proxy.BaseRepositoryProxyBean;
021    
022    /**
023     * @author Adolfo P??rez
024     * @author Mika Koivisto
025     */
026    public class ExternalRepositoryFactoryImpl
027            implements ExternalRepositoryFactory {
028    
029            public ExternalRepositoryFactoryImpl(String className) {
030                    _className = className;
031            }
032    
033            public ExternalRepositoryFactoryImpl(
034                    String className, ClassLoader classLoader) {
035    
036                    _className = className;
037                    _classLoader = classLoader;
038            }
039    
040            @Override
041            public BaseRepository getInstance() throws Exception {
042                    if (_classLoader == null) {
043                            return (BaseRepository)InstanceFactory.newInstance(_className);
044                    }
045    
046                    BaseRepository baseRepository =
047                            (BaseRepository)ProxyFactory.newInstance(
048                                    _classLoader, BaseRepository.class, _className);
049    
050                    return new BaseRepositoryProxyBean(baseRepository, _classLoader);
051            }
052    
053            private ClassLoader _classLoader;
054            private final String _className;
055    
056    }