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

com.liferay.portlet.internal.PortletBagImpl Maven / Gradle / Ivy

There is a newer version: 7.4.3.112-ga112
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.portlet.internal;

import com.liferay.asset.kernel.model.AssetRendererFactory;
import com.liferay.expando.kernel.model.CustomAttributesDisplay;
import com.liferay.exportimport.kernel.lar.PortletDataHandler;
import com.liferay.exportimport.kernel.lar.StagedModelDataHandler;
import com.liferay.portal.kernel.atom.AtomCollectionAdapter;
import com.liferay.portal.kernel.notifications.UserNotificationDefinition;
import com.liferay.portal.kernel.notifications.UserNotificationHandler;
import com.liferay.portal.kernel.poller.PollerProcessor;
import com.liferay.portal.kernel.pop.MessageListener;
import com.liferay.portal.kernel.portlet.ConfigurationAction;
import com.liferay.portal.kernel.portlet.ControlPanelEntry;
import com.liferay.portal.kernel.portlet.FriendlyURLMapperTracker;
import com.liferay.portal.kernel.portlet.PortletBag;
import com.liferay.portal.kernel.portlet.PortletLayoutListener;
import com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListener;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.search.OpenSearch;
import com.liferay.portal.kernel.security.permission.PermissionPropagator;
import com.liferay.portal.kernel.servlet.URLEncoder;
import com.liferay.portal.kernel.template.TemplateHandler;
import com.liferay.portal.kernel.trash.TrashHandler;
import com.liferay.portal.kernel.util.ResourceBundleLoader;
import com.liferay.portal.kernel.util.ServiceProxyFactory;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.webdav.WebDAVStorage;
import com.liferay.portal.kernel.workflow.WorkflowHandler;
import com.liferay.portal.kernel.xmlrpc.Method;
import com.liferay.registry.Filter;
import com.liferay.registry.Registry;
import com.liferay.registry.RegistryUtil;
import com.liferay.registry.ServiceRegistration;
import com.liferay.registry.collections.ServiceTrackerCollections;
import com.liferay.social.kernel.model.SocialActivityInterpreter;
import com.liferay.social.kernel.model.SocialRequestInterpreter;

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

import javax.portlet.Portlet;
import javax.portlet.PreferencesValidator;

import javax.servlet.ServletContext;

/**
 * @author Brian Wing Shun Chan
 * @author Jorge Ferrer
 */
public class PortletBagImpl implements PortletBag {

	public PortletBagImpl(
		String portletName, ServletContext servletContext,
		Portlet portletInstance, String resourceBundleBaseName,
		FriendlyURLMapperTracker friendlyURLMapperTracker,
		List> serviceRegistrations) {

		_portletName = portletName;
		_servletContext = servletContext;
		_portletInstance = portletInstance;
		_resourceBundleBaseName = resourceBundleBaseName;
		_friendlyURLMapperTracker = friendlyURLMapperTracker;
		_serviceRegistrations = serviceRegistrations;

		Registry registry = RegistryUtil.getRegistry();

		_filter = registry.getFilter(
			"(|(javax.portlet.name=" + portletName +
				")(javax.portlet.name=ALL))");

		_properties = Collections.singletonMap(
			"javax.portlet.name", portletName);
	}

	@Override
	public Object clone() {
		return new PortletBagImpl(
			getPortletName(), getServletContext(), getPortletInstance(),
			getResourceBundleBaseName(), getFriendlyURLMapperTracker(), null);
	}

	@Override
	public void destroy() {
		if (_serviceRegistrations == null) {
			return;
		}

		_friendlyURLMapperTracker.close();

		for (ServiceRegistration serviceRegistration :
				_serviceRegistrations) {

			serviceRegistration.unregister();
		}

		_serviceRegistrations.clear();
	}

	@Override
	public List> getAssetRendererFactoryInstances() {
		if (_assetRendererFactoryInstances == null) {
			synchronized (this) {
				if (_assetRendererFactoryInstances == null) {
					_assetRendererFactoryInstances =
						ServiceTrackerCollections.openList(
							(Class>)
								(Class)AssetRendererFactory.class,
							_filter, _properties);
				}
			}
		}

		return _assetRendererFactoryInstances;
	}

	@Override
	public List> getAtomCollectionAdapterInstances() {
		if (_atomCollectionAdapterInstances == null) {
			synchronized (this) {
				if (_atomCollectionAdapterInstances == null) {
					_atomCollectionAdapterInstances =
						ServiceTrackerCollections.openList(
							(Class>)
								(Class)AtomCollectionAdapter.class,
							_filter, _properties);
				}
			}
		}

		return _atomCollectionAdapterInstances;
	}

	@Override
	public List getConfigurationActionInstances() {
		if (_configurationActionInstances == null) {
			synchronized (this) {
				if (_configurationActionInstances == null) {
					_configurationActionInstances =
						ServiceTrackerCollections.openList(
							ConfigurationAction.class, _filter, _properties);
				}
			}
		}

		return _configurationActionInstances;
	}

	@Override
	public List getControlPanelEntryInstances() {
		if (_controlPanelEntryInstances == null) {
			synchronized (this) {
				if (_controlPanelEntryInstances == null) {
					_controlPanelEntryInstances =
						ServiceTrackerCollections.openList(
							ControlPanelEntry.class, _filter, _properties);
				}
			}
		}

		return _controlPanelEntryInstances;
	}

	@Override
	public List getCustomAttributesDisplayInstances() {
		if (_customAttributesDisplayInstances == null) {
			synchronized (this) {
				if (_customAttributesDisplayInstances == null) {
					_customAttributesDisplayInstances =
						ServiceTrackerCollections.openList(
							CustomAttributesDisplay.class, _filter,
							_properties);
				}
			}
		}

		return _customAttributesDisplayInstances;
	}

	@Override
	public FriendlyURLMapperTracker getFriendlyURLMapperTracker() {
		return _friendlyURLMapperTracker;
	}

	@Override
	public List> getIndexerInstances() {
		if (_indexerInstances == null) {
			synchronized (this) {
				if (_indexerInstances == null) {
					_indexerInstances = ServiceTrackerCollections.openList(
						(Class>)(Class)Indexer.class, _filter,
						_properties);
				}
			}
		}

		return _indexerInstances;
	}

	@Override
	public List getOpenSearchInstances() {
		if (_openSearchInstances == null) {
			synchronized (this) {
				if (_openSearchInstances == null) {
					_openSearchInstances = ServiceTrackerCollections.openList(
						OpenSearch.class, _filter, _properties);
				}
			}
		}

		return _openSearchInstances;
	}

	@Override
	public List getPermissionPropagatorInstances() {
		if (_permissionPropagatorInstances == null) {
			synchronized (this) {
				if (_permissionPropagatorInstances == null) {
					_permissionPropagatorInstances =
						ServiceTrackerCollections.openList(
							PermissionPropagator.class, _filter, _properties);
				}
			}
		}

		return _permissionPropagatorInstances;
	}

	@Override
	public List getPollerProcessorInstances() {
		if (_pollerProcessorInstances == null) {
			synchronized (this) {
				if (_pollerProcessorInstances == null) {
					_pollerProcessorInstances =
						ServiceTrackerCollections.openList(
							PollerProcessor.class, _filter, _properties);
				}
			}
		}

		return _pollerProcessorInstances;
	}

	@Override
	public List getPopMessageListenerInstances() {
		if (_popMessageListenerInstances == null) {
			synchronized (this) {
				if (_popMessageListenerInstances == null) {
					_popMessageListenerInstances =
						ServiceTrackerCollections.openList(
							MessageListener.class, _filter, _properties);
				}
			}
		}

		return _popMessageListenerInstances;
	}

	@Override
	public List getPortletDataHandlerInstances() {
		if (_portletDataHandlerInstances == null) {
			synchronized (this) {
				if (_portletDataHandlerInstances == null) {
					_portletDataHandlerInstances =
						ServiceTrackerCollections.openList(
							PortletDataHandler.class, _filter, _properties);
				}
			}
		}

		return _portletDataHandlerInstances;
	}

	@Override
	public Portlet getPortletInstance() {
		return _portletInstance;
	}

	@Override
	public List getPortletLayoutListenerInstances() {
		if (_portletLayoutListenerInstances == null) {
			synchronized (this) {
				if (_portletLayoutListenerInstances == null) {
					_portletLayoutListenerInstances =
						ServiceTrackerCollections.openList(
							PortletLayoutListener.class, _filter, _properties);
				}
			}
		}

		return _portletLayoutListenerInstances;
	}

	@Override
	public String getPortletName() {
		return _portletName;
	}

	@Override
	public List getPreferencesValidatorInstances() {
		if (_preferencesValidatorInstances == null) {
			synchronized (this) {
				if (_preferencesValidatorInstances == null) {
					_preferencesValidatorInstances =
						ServiceTrackerCollections.openList(
							PreferencesValidator.class, _filter, _properties);
				}
			}
		}

		return _preferencesValidatorInstances;
	}

	@Override
	public ResourceBundle getResourceBundle(Locale locale) {
		ResourceBundleLoader resourceBundleLoader = _resourceBundleLoader;

		if (resourceBundleLoader == null) {
			synchronized (this) {
				if (_resourceBundleLoader == null) {
					StringBundler sb = new StringBundler(5);

					sb.append("(resource.bundle.base.name=");
					sb.append(getResourceBundleBaseName());
					sb.append(")(servlet.context.name=");
					sb.append(_servletContext.getServletContextName());
					sb.append(")");

					_resourceBundleLoader =
						ServiceProxyFactory.newServiceTrackedInstance(
							ResourceBundleLoader.class, PortletBagImpl.class,
							this, "_resourceBundleLoader", sb.toString(),
							false);
				}

				resourceBundleLoader = _resourceBundleLoader;
			}
		}

		return resourceBundleLoader.loadResourceBundle(locale);
	}

	@Override
	public String getResourceBundleBaseName() {
		return _resourceBundleBaseName;
	}

	@Override
	public List
		getSchedulerEventMessageListeners() {

		if (_schedulerEventMessageListeners == null) {
			synchronized (this) {
				if (_schedulerEventMessageListeners == null) {
					_schedulerEventMessageListeners =
						ServiceTrackerCollections.openList(
							SchedulerEventMessageListener.class, _filter,
							_properties);
				}
			}
		}

		return _schedulerEventMessageListeners;
	}

	@Override
	public ServletContext getServletContext() {
		return _servletContext;
	}

	@Override
	public List
		getSocialActivityInterpreterInstances() {

		if (_socialActivityInterpreterInstances == null) {
			synchronized (this) {
				if (_socialActivityInterpreterInstances == null) {
					_socialActivityInterpreterInstances =
						ServiceTrackerCollections.openList(
							SocialActivityInterpreter.class, _filter,
							_properties);
				}
			}
		}

		return _socialActivityInterpreterInstances;
	}

	@Override
	public List
		getSocialRequestInterpreterInstances() {

		if (_socialRequestInterpreterInstances == null) {
			synchronized (this) {
				if (_socialRequestInterpreterInstances == null) {
					_socialRequestInterpreterInstances =
						ServiceTrackerCollections.openList(
							SocialRequestInterpreter.class, _filter,
							_properties);
				}
			}
		}

		return _socialRequestInterpreterInstances;
	}

	@Override
	public List>
		getStagedModelDataHandlerInstances() {

		if (_stagedModelDataHandlerInstances == null) {
			synchronized (this) {
				if (_stagedModelDataHandlerInstances == null) {
					_stagedModelDataHandlerInstances =
						ServiceTrackerCollections.openList(
							(Class>)
								(Class)StagedModelDataHandler.class,
							_filter, _properties);
				}
			}
		}

		return _stagedModelDataHandlerInstances;
	}

	@Override
	public List getTemplateHandlerInstances() {
		if (_templateHandlerInstances == null) {
			synchronized (this) {
				if (_templateHandlerInstances == null) {
					_templateHandlerInstances =
						ServiceTrackerCollections.openList(
							TemplateHandler.class, _filter, _properties);
				}
			}
		}

		return _templateHandlerInstances;
	}

	@Override
	public List getTrashHandlerInstances() {
		if (_trashHandlerInstances == null) {
			synchronized (this) {
				if (_trashHandlerInstances == null) {
					_trashHandlerInstances = ServiceTrackerCollections.openList(
						TrashHandler.class, _filter, _properties);
				}
			}
		}

		return _trashHandlerInstances;
	}

	@Override
	public List getURLEncoderInstances() {
		if (_urlEncoderInstances == null) {
			synchronized (this) {
				if (_urlEncoderInstances == null) {
					_urlEncoderInstances = ServiceTrackerCollections.openList(
						URLEncoder.class, _filter, _properties);
				}
			}
		}

		return _urlEncoderInstances;
	}

	@Override
	public List
		getUserNotificationDefinitionInstances() {

		if (_userNotificationDefinitionInstances == null) {
			synchronized (this) {
				if (_userNotificationDefinitionInstances == null) {
					_userNotificationDefinitionInstances =
						ServiceTrackerCollections.openList(
							UserNotificationDefinition.class, _filter,
							_properties);
				}
			}
		}

		return _userNotificationDefinitionInstances;
	}

	@Override
	public List getUserNotificationHandlerInstances() {
		if (_userNotificationHandlerInstances == null) {
			synchronized (this) {
				if (_userNotificationHandlerInstances == null) {
					_userNotificationHandlerInstances =
						ServiceTrackerCollections.openList(
							UserNotificationHandler.class, _filter,
							_properties);
				}
			}
		}

		return _userNotificationHandlerInstances;
	}

	@Override
	public List getWebDAVStorageInstances() {
		if (_webDAVStorageInstances == null) {
			synchronized (this) {
				if (_webDAVStorageInstances == null) {
					_webDAVStorageInstances =
						ServiceTrackerCollections.openList(
							WebDAVStorage.class, _filter, _properties);
				}
			}
		}

		return _webDAVStorageInstances;
	}

	@Override
	public List> getWorkflowHandlerInstances() {
		if (_workflowHandlerInstances == null) {
			synchronized (this) {
				if (_workflowHandlerInstances == null) {
					_workflowHandlerInstances =
						ServiceTrackerCollections.openList(
							(Class>)
								(Class)WorkflowHandler.class,
							_filter, _properties);
				}
			}
		}

		return _workflowHandlerInstances;
	}

	@Override
	public List getXmlRpcMethodInstances() {
		if (_xmlRpcMethodInstances == null) {
			synchronized (this) {
				if (_xmlRpcMethodInstances == null) {
					_xmlRpcMethodInstances = ServiceTrackerCollections.openList(
						Method.class, _filter, _properties);
				}
			}
		}

		return _xmlRpcMethodInstances;
	}

	@Override
	public void setPortletDataHandlerInstances(
		List portletDataHandlerInstances) {

		_portletDataHandlerInstances = portletDataHandlerInstances;
	}

	@Override
	public void setPortletInstance(Portlet portletInstance) {
		_portletInstance = portletInstance;
	}

	@Override
	public void setPortletName(String portletName) {
		_portletName = portletName;
	}

	private volatile List>
		_assetRendererFactoryInstances;
	private volatile List>
		_atomCollectionAdapterInstances;
	private volatile List _configurationActionInstances;
	private volatile List _controlPanelEntryInstances;
	private volatile List
		_customAttributesDisplayInstances;
	private final Filter _filter;
	private final FriendlyURLMapperTracker _friendlyURLMapperTracker;
	private volatile List> _indexerInstances;
	private volatile List _openSearchInstances;
	private volatile List _permissionPropagatorInstances;
	private volatile List _pollerProcessorInstances;
	private volatile List _popMessageListenerInstances;
	private volatile List _portletDataHandlerInstances;
	private Portlet _portletInstance;
	private volatile List
		_portletLayoutListenerInstances;
	private String _portletName;
	private volatile List _preferencesValidatorInstances;
	private final Map _properties;
	private final String _resourceBundleBaseName;
	private volatile ResourceBundleLoader _resourceBundleLoader;
	private volatile List
		_schedulerEventMessageListeners;
	private final List> _serviceRegistrations;
	private final ServletContext _servletContext;
	private volatile List
		_socialActivityInterpreterInstances;
	private volatile List
		_socialRequestInterpreterInstances;
	private volatile List>
		_stagedModelDataHandlerInstances;
	private volatile List _templateHandlerInstances;
	private volatile List _trashHandlerInstances;
	private volatile List _urlEncoderInstances;
	private volatile List
		_userNotificationDefinitionInstances;
	private volatile List
		_userNotificationHandlerInstances;
	private volatile List _webDAVStorageInstances;
	private volatile List> _workflowHandlerInstances;
	private volatile List _xmlRpcMethodInstances;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy