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.atom;
016    
017    import com.liferay.portal.kernel.atom.AtomCollectionAdapter;
018    import com.liferay.portal.kernel.atom.AtomCollectionAdapterRegistry;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
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 Igor Spasic
030     */
031    @DoPrivileged
032    public class AtomCollectionAdapterRegistryImpl
033            implements AtomCollectionAdapterRegistry {
034    
035            @Override
036            public AtomCollectionAdapter<?> getAtomCollectionAdapter(
037                    String collectionName) {
038    
039                    return _atomCollectionAdapters.get(collectionName);
040            }
041    
042            @Override
043            public List<AtomCollectionAdapter<?>> getAtomCollectionAdapters() {
044                    return ListUtil.fromMapValues(_atomCollectionAdapters);
045            }
046    
047            @Override
048            public void register(AtomCollectionAdapter<?> atomCollectionAdapter) {
049                    if (_atomCollectionAdapters.containsKey(
050                                    atomCollectionAdapter.getCollectionName())) {
051    
052                            if (_log.isWarnEnabled()) {
053                                    _log.warn(
054                                            "Duplicate collection name " +
055                                                    atomCollectionAdapter.getCollectionName());
056                            }
057    
058                            return;
059                    }
060    
061                    _atomCollectionAdapters.put(
062                            atomCollectionAdapter.getCollectionName(), atomCollectionAdapter);
063            }
064    
065            @Override
066            public void unregister(AtomCollectionAdapter<?> atomCollectionAdapter) {
067                    _atomCollectionAdapters.remove(
068                            atomCollectionAdapter.getCollectionName());
069            }
070    
071            private static Log _log = LogFactoryUtil.getLog(
072                    AtomCollectionAdapterRegistryImpl.class);
073    
074            private Map<String, AtomCollectionAdapter<?>> _atomCollectionAdapters =
075                    new ConcurrentHashMap<String, AtomCollectionAdapter<?>>();
076    
077    }