All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.dynamic.data.mapping.util.DDMDisplayRegistry Maven / Gradle / Ivy

There is a newer version: 33.1.0
Show newest version
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.liferay.dynamic.data.mapping.util;

import aQute.bnd.annotation.ProviderType;

import com.liferay.portal.kernel.util.ListUtil;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;

/**
 * @author Eduardo Garcia
 */
@Component(immediate = true, service = DDMDisplayRegistry.class)
@ProviderType
public class DDMDisplayRegistry {

	public DDMDisplay getDDMDisplay(String portletId) {
		return _getDDMDisplay(portletId);
	}

	public List getDDMDisplays() {
		return _getDDMDisplays();
	}

	public String[] getPortletIds() {
		return _getPortletIds();
	}

	@Reference(
		cardinality = ReferenceCardinality.MULTIPLE,
		policy = ReferencePolicy.DYNAMIC,
		policyOption = ReferencePolicyOption.GREEDY, unbind = "unsetDDMDisplay"
	)
	protected void setDDMDisplay(DDMDisplay ddmDisplay) {
		_ddmDisplays.put(ddmDisplay.getPortletId(), ddmDisplay);
	}

	protected void unsetDDMDisplay(DDMDisplay ddmDisplay) {
		_ddmDisplays.remove(ddmDisplay.getPortletId());
	}

	private DDMDisplay _getDDMDisplay(String portletId) {
		return _ddmDisplays.get(portletId);
	}

	private List _getDDMDisplays() {
		return ListUtil.fromMapValues(_ddmDisplays);
	}

	private String[] _getPortletIds() {
		Set portletIds = _ddmDisplays.keySet();

		return portletIds.toArray(new String[portletIds.size()]);
	}

	private final Map _ddmDisplays =
		new ConcurrentHashMap<>();

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy