| ResourcePermissionsThreadLocal.java |
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.portal.util;
16
17 import com.liferay.portal.kernel.util.InitialThreadLocal;
18 import com.liferay.portal.model.ResourcePermission;
19
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 /**
25 * <a href="ResourcePermissionsThreadLocal.java.html"><b><i>View Source</i></b>
26 * </a>
27 *
28 * @author Shuyang Zhou
29 * @author Brian Wing Shun Chan
30 */
31 public class ResourcePermissionsThreadLocal {
32
33 public static Map<Long, ResourcePermission> getResourcePermissions() {
34 return _resourcePermissions.get();
35 }
36
37 public static void setResourcePermissions(
38 List<ResourcePermission> resourcePermissions) {
39
40 if (resourcePermissions != null) {
41 Map<Long, ResourcePermission> resourcePermissionMap =
42 new HashMap<Long, ResourcePermission>();
43
44 for (ResourcePermission resourcePermission : resourcePermissions) {
45 resourcePermissionMap.put(
46 resourcePermission.getRoleId(), resourcePermission);
47 }
48 }
49 else {
50 _resourcePermissions.remove();
51 }
52 }
53
54 private static ThreadLocal<Map<Long, ResourcePermission>>
55 _resourcePermissions = new InitialThreadLocal
56 <Map<Long, ResourcePermission>>(null);
57
58 }