001    /**
002     * Copyright (c) 2000-present 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;
016    
017    import com.liferay.portal.kernel.portlet.ControlPanelEntry;
018    import com.liferay.registry.Filter;
019    import com.liferay.registry.Registry;
020    import com.liferay.registry.RegistryUtil;
021    import com.liferay.registry.ServiceTracker;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Shuyang Zhou
026     * @author Peter Fellwock
027     */
028    public class DefaultControlPanelEntryFactory {
029    
030            public static ControlPanelEntry getInstance() {
031                    return _instance._serviceTracker.getService();
032            }
033    
034            private DefaultControlPanelEntryFactory() {
035                    Registry registry = RegistryUtil.getRegistry();
036    
037                    Filter filter = registry.getFilter(
038                            "(&(!(javax.portlet.name=*))(objectClass=" +
039                                    ControlPanelEntry.class.getName() + "))");
040    
041                    _serviceTracker = registry.trackServices(filter);
042    
043                    _serviceTracker.open();
044            }
045    
046            private static final DefaultControlPanelEntryFactory _instance =
047                    new DefaultControlPanelEntryFactory();
048    
049            private final ServiceTracker<ControlPanelEntry, ControlPanelEntry>
050                    _serviceTracker;
051    
052    }