001    /**
002     * Copyright (c) 2000-2012 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            public PersistedModelLocalService getPersistedModelLocalService(
033                    String className) {
034    
035                    return _persistedModelLocalServices.get(className);
036            }
037    
038            public List<PersistedModelLocalService> getPersistedModelLocalServices() {
039                    return ListUtil.fromMapValues(_persistedModelLocalServices);
040            }
041    
042            public boolean isPermissionedModelLocalService(String className) {
043                    PersistedModelLocalService persistedModelLocalService =
044                            getPersistedModelLocalService(className);
045    
046                    if (persistedModelLocalService == null) {
047                            return false;
048                    }
049    
050                    if (persistedModelLocalService instanceof
051                                    PermissionedModelLocalService) {
052    
053                            return true;
054                    }
055    
056                    return false;
057            }
058    
059            public void register(
060                    String className,
061                    PersistedModelLocalService persistedModelLocalService) {
062    
063                    PersistedModelLocalService oldPersistedModelLocalService =
064                            _persistedModelLocalServices.put(
065                                    className, persistedModelLocalService);
066    
067                    if (oldPersistedModelLocalService != null) {
068                            _log.warn("Duplicate class name " + className);
069                    }
070            }
071    
072            public void unregister(String className) {
073                    _persistedModelLocalServices.remove(className);
074            }
075    
076            private static Log _log = LogFactoryUtil.getLog(
077                    PersistedModelLocalServiceRegistryImpl.class);
078    
079            private Map<String, PersistedModelLocalService>
080                    _persistedModelLocalServices =
081                            new ConcurrentHashMap<String, PersistedModelLocalService>();
082    
083    }