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