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.portlet.dynamicdatamapping.util;
016    
017    import com.liferay.portal.kernel.util.ListUtil;
018    
019    import java.util.HashMap;
020    import java.util.List;
021    import java.util.Map;
022    import java.util.Set;
023    
024    /**
025     * @author Eduardo Garcia
026     */
027    public class DDMDisplayRegistryImpl implements DDMDisplayRegistry {
028    
029            @Override
030            public DDMDisplay getDDMDisplay(String portletId) {
031                    return _ddmDisplays.get(portletId);
032            }
033    
034            @Override
035            public List<DDMDisplay> getDDMDisplays() {
036                    return ListUtil.fromMapValues(_ddmDisplays);
037            }
038    
039            @Override
040            public String[] getPortletIds() {
041                    Set<String> portletIds = _ddmDisplays.keySet();
042    
043                    return portletIds.toArray(new String[portletIds.size()]);
044            }
045    
046            @Override
047            public void register(DDMDisplay ddmDisplay) {
048                    _ddmDisplays.put(ddmDisplay.getPortletId(), ddmDisplay);
049            }
050    
051            @Override
052            public void unregister(DDMDisplay ddmDisplay) {
053                    _ddmDisplays.remove(ddmDisplay.getPortletId());
054            }
055    
056            private Map<String, DDMDisplay> _ddmDisplays =
057                    new HashMap<String, DDMDisplay>();
058    
059    }