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