001
014
015 package com.liferay.portlet;
016
017 import com.liferay.portal.model.Portlet;
018
019 import java.util.Map;
020 import java.util.concurrent.ConcurrentHashMap;
021
022 import javax.portlet.PortletConfig;
023 import javax.portlet.PortletContext;
024
025 import javax.servlet.ServletContext;
026
027
030 public class PortletConfigFactoryImpl implements PortletConfigFactory {
031
032 public PortletConfigFactoryImpl() {
033 _pool = new ConcurrentHashMap<String, Map<String, PortletConfig>>();
034 }
035
036 public PortletConfig create(
037 Portlet portlet, ServletContext servletContext) {
038
039 Map<String, PortletConfig> portletConfigs =
040 _pool.get(portlet.getRootPortletId());
041
042 if (portletConfigs == null) {
043 portletConfigs = new ConcurrentHashMap<String, PortletConfig>();
044
045 _pool.put(portlet.getRootPortletId(), portletConfigs);
046 }
047
048 PortletConfig portletConfig = portletConfigs.get(
049 portlet.getPortletId());
050
051 if (portletConfig == null) {
052 PortletContext portletContext =
053 PortletContextFactory.create(portlet, servletContext);
054
055 portletConfig = new PortletConfigImpl(portlet, portletContext);
056
057 portletConfigs.put(portlet.getPortletId(), portletConfig);
058 }
059
060 return portletConfig;
061 }
062
063 public void destroy(Portlet portlet) {
064 _pool.remove(portlet.getRootPortletId());
065 }
066
067 public PortletConfig update(Portlet portlet) {
068 Map<String, PortletConfig> portletConfigs =
069 _pool.get(portlet.getRootPortletId());
070
071 PortletConfig portletConfig = portletConfigs.get(
072 portlet.getPortletId());
073
074 PortletContext portletContext = portletConfig.getPortletContext();
075
076 portletConfig = new PortletConfigImpl(portlet, portletContext);
077
078 portletConfigs.put(portlet.getPortletId(), portletConfig);
079
080 return portletConfig;
081 }
082
083 private Map<String, Map<String, PortletConfig>> _pool;
084
085 }