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.service;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.service.PermissionedModelLocalService;
020    import com.liferay.portal.kernel.service.PersistedModelLocalService;
021    import com.liferay.portal.kernel.service.PersistedModelLocalServiceRegistry;
022    import com.liferay.portal.kernel.util.ListUtil;
023    
024    import java.util.List;
025    import java.util.Map;
026    import java.util.concurrent.ConcurrentHashMap;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     * @author Connor McKay
031     */
032    public class PersistedModelLocalServiceRegistryImpl
033            implements PersistedModelLocalServiceRegistry {
034    
035            @Override
036            public PersistedModelLocalService getPersistedModelLocalService(
037                    String className) {
038    
039                    return _persistedModelLocalServices.get(className);
040            }
041    
042            @Override
043            public List<PersistedModelLocalService> getPersistedModelLocalServices() {
044                    return ListUtil.fromMapValues(_persistedModelLocalServices);
045            }
046    
047            @Override
048            public boolean isPermissionedModelLocalService(String className) {
049                    PersistedModelLocalService persistedModelLocalService =
050                            getPersistedModelLocalService(className);
051    
052                    if (persistedModelLocalService == null) {
053                            return false;
054                    }
055    
056                    if (persistedModelLocalService instanceof
057                                    PermissionedModelLocalService) {
058    
059                            return true;
060                    }
061    
062                    return false;
063            }
064    
065            @Override
066            public void register(
067                    String className,
068                    PersistedModelLocalService persistedModelLocalService) {
069    
070                    PersistedModelLocalService oldPersistedModelLocalService =
071                            _persistedModelLocalServices.put(
072                                    className, persistedModelLocalService);
073    
074                    if ((oldPersistedModelLocalService != null) && _log.isWarnEnabled()) {
075                            _log.warn("Duplicate class name " + className);
076                    }
077            }
078    
079            @Override
080            public void unregister(String className) {
081                    _persistedModelLocalServices.remove(className);
082            }
083    
084            private static final Log _log = LogFactoryUtil.getLog(
085                    PersistedModelLocalServiceRegistryImpl.class);
086    
087            private final Map<String, PersistedModelLocalService>
088                    _persistedModelLocalServices = new ConcurrentHashMap<>();
089    
090    }