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            public AtomCollectionAdapter<?> getAtomCollectionAdapter(
036                    String collectionName) {
037    
038                    return _atomCollectionAdapters.get(collectionName);
039            }
040    
041            public List<AtomCollectionAdapter<?>> getAtomCollectionAdapters() {
042                    return ListUtil.fromMapValues(_atomCollectionAdapters);
043            }
044    
045            public void register(AtomCollectionAdapter<?> atomCollectionAdapter) {
046                    if (_atomCollectionAdapters.containsKey(
047                                    atomCollectionAdapter.getCollectionName())) {
048    
049                            if (_log.isWarnEnabled()) {
050                                    _log.warn(
051                                            "Duplicate collection name " +
052                                                    atomCollectionAdapter.getCollectionName());
053                            }
054    
055                            return;
056                    }
057    
058                    _atomCollectionAdapters.put(
059                            atomCollectionAdapter.getCollectionName(), atomCollectionAdapter);
060            }
061    
062            public void unregister(AtomCollectionAdapter<?> atomCollectionAdapter) {
063                    _atomCollectionAdapters.remove(
064                            atomCollectionAdapter.getCollectionName());
065            }
066    
067            private static Log _log = LogFactoryUtil.getLog(
068                    AtomCollectionAdapterRegistryImpl.class);
069    
070            private Map<String, AtomCollectionAdapter<?>> _atomCollectionAdapters =
071                    new ConcurrentHashMap<String, AtomCollectionAdapter<?>>();
072    
073    }