1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet;
16  
17  import com.liferay.portal.model.PortletApp;
18  
19  import java.util.Map;
20  import java.util.concurrent.ConcurrentHashMap;
21  
22  import javax.portlet.PortletContext;
23  import javax.portlet.filter.FilterConfig;
24  
25  /**
26   * <a href="FilterConfigFactory.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   */
30  public class FilterConfigFactory {
31  
32      public static FilterConfig create(
33          com.liferay.portal.model.PortletFilter portletFilter,
34          PortletContext ctx) {
35  
36          return _instance._create(portletFilter, ctx);
37      }
38  
39      public static void destroy(
40          com.liferay.portal.model.PortletFilter portletFilter) {
41  
42          _instance._destroy(portletFilter);
43      }
44  
45      private FilterConfigFactory() {
46          _pool = new ConcurrentHashMap<String, Map<String, FilterConfig>>();
47      }
48  
49      private FilterConfig _create(
50          com.liferay.portal.model.PortletFilter portletFilter,
51          PortletContext ctx) {
52  
53          PortletApp portletApp = portletFilter.getPortletApp();
54  
55          Map<String, FilterConfig> filterConfigs =
56              _pool.get(portletApp.getServletContextName());
57  
58          if (filterConfigs == null) {
59              filterConfigs = new ConcurrentHashMap<String, FilterConfig>();
60  
61              _pool.put(portletApp.getServletContextName(), filterConfigs);
62          }
63  
64          FilterConfig filterConfig = filterConfigs.get(
65              portletFilter.getFilterName());
66  
67          if (filterConfig == null) {
68              filterConfig = new FilterConfigImpl(
69                  portletFilter.getFilterName(), ctx,
70                  portletFilter.getInitParams());
71  
72              filterConfigs.put(portletFilter.getFilterName(), filterConfig);
73          }
74  
75          return filterConfig;
76      }
77  
78      private void _destroy(
79          com.liferay.portal.model.PortletFilter portletFilter) {
80  
81          PortletApp portletApp = portletFilter.getPortletApp();
82  
83          _pool.remove(portletApp.getServletContextName());
84      }
85  
86      private static FilterConfigFactory _instance = new FilterConfigFactory();
87  
88      private Map<String, Map<String, FilterConfig>> _pool;
89  
90  }