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