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.repository.RepositoryException;
019    import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
020    import com.liferay.portal.util.PropsValues;
021    
022    import java.util.Set;
023    import java.util.concurrent.ConcurrentHashMap;
024    import java.util.concurrent.ConcurrentMap;
025    
026    /**
027     * @author     Mika Koivisto
028     * @deprecated As of 7.0.0, replaced by {@link
029     *             com.liferay.portal.repository.util.ExternalRepositoryFactoryUtil}
030     */
031    @Deprecated
032    public class RepositoryFactoryUtil {
033    
034            public static BaseRepository getInstance(String className)
035                    throws Exception {
036    
037                    RepositoryFactory repositoryFactory = _repositoryFactories.get(
038                            className);
039    
040                    BaseRepository baseRepository = null;
041    
042                    if (repositoryFactory != null) {
043                            baseRepository = repositoryFactory.getInstance();
044                    }
045    
046                    if (baseRepository != null) {
047                            return baseRepository;
048                    }
049    
050                    throw new RepositoryException(
051                            "Repository with class name " + className + " is unavailable");
052            }
053    
054            public static String[] getRepositoryClassNames() {
055                    Set<String> classNames = _repositoryFactories.keySet();
056    
057                    return classNames.toArray(new String[classNames.size()]);
058            }
059    
060            public static void registerRepositoryFactory(
061                    String className, RepositoryFactory repositoryFactory) {
062    
063                    _repositoryFactories.put(className, repositoryFactory);
064            }
065    
066            public static void unregisterRepositoryFactory(String className) {
067                    _repositoryFactories.remove(className);
068            }
069    
070            private static final ConcurrentMap<String, RepositoryFactory>
071                    _repositoryFactories = new ConcurrentHashMap<>();
072    
073            static {
074                    ClassLoader classLoader = PortalClassLoaderUtil.getClassLoader();
075    
076                    for (String className : PropsValues.DL_REPOSITORY_IMPL) {
077                            RepositoryFactory repositoryFactory = new RepositoryFactoryImpl(
078                                    className, classLoader);
079    
080                            _repositoryFactories.put(className, repositoryFactory);
081                    }
082            }
083    
084    }