001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }