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    
025    /**
026     * @author     Mika Koivisto
027     * @deprecated As of 7.0.0, replaced by {@link
028     *             com.liferay.portal.repository.util.ExternalRepositoryFactoryUtil}
029     */
030    @Deprecated
031    public class RepositoryFactoryUtil {
032    
033            public static BaseRepository getInstance(String className)
034                    throws Exception {
035    
036                    RepositoryFactory repositoryFactory = _repositoryFactories.get(
037                            className);
038    
039                    BaseRepository baseRepository = null;
040    
041                    if (repositoryFactory != null) {
042                            baseRepository = repositoryFactory.getInstance();
043                    }
044    
045                    if (baseRepository != null) {
046                            return baseRepository;
047                    }
048    
049                    throw new RepositoryException(
050                            "Repository with class name " + className + " is unavailable");
051            }
052    
053            public static String[] getRepositoryClassNames() {
054                    Set<String> classNames = _repositoryFactories.keySet();
055    
056                    return classNames.toArray(new String[classNames.size()]);
057            }
058    
059            public static void registerRepositoryFactory(
060                    String className, RepositoryFactory repositoryFactory) {
061    
062                    _repositoryFactories.put(className, repositoryFactory);
063            }
064    
065            public static void unregisterRepositoryFactory(String className) {
066                    _repositoryFactories.remove(className);
067            }
068    
069            private static final ConcurrentHashMap<String, RepositoryFactory>
070                    _repositoryFactories =
071                            new ConcurrentHashMap<String, RepositoryFactory>();
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    }