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.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    }