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