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.model;
16  
17  import java.io.Serializable;
18  
19  /**
20   * <a href="PermissionDisplay.java.html"><b><i>View Source</i></b></a>
21   *
22   * @author Brian Wing Shun Chan
23   * @author Jorge Ferrer
24   */
25  public class PermissionDisplay
26      implements Comparable<PermissionDisplay>, Serializable {
27  
28      public PermissionDisplay(
29          Permission permission, Resource resource, String portletName,
30          String portletLabel, String modelName, String modelLabel,
31          String actionId, String actionLabel) {
32  
33          _permission = permission;
34          _resource = resource;
35          _portletName = portletName;
36          _portletLabel = portletLabel;
37          _modelName = modelName;
38          _modelLabel = modelLabel;
39          _actionId = actionId;
40          _actionLabel = actionLabel;
41      }
42  
43      public Permission getPermission() {
44          return _permission;
45      }
46  
47      public Resource getResource() {
48          return _resource;
49      }
50  
51      public String getPortletName() {
52          return _portletName;
53      }
54  
55      public String getPortletLabel() {
56          return _portletLabel;
57      }
58  
59      public String getModelName() {
60          return _modelName;
61      }
62  
63      public String getModelLabel() {
64          return _modelLabel;
65      }
66  
67      public String getActionId() {
68          return _actionId;
69      }
70  
71      public String getActionLabel() {
72          return _actionLabel;
73      }
74  
75      public int compareTo(PermissionDisplay permissionDisplay) {
76          int value = getPortletLabel().compareTo(
77              permissionDisplay.getPortletLabel());
78  
79          if (value == 0) {
80              value = getModelLabel().compareTo(
81                  permissionDisplay.getModelLabel());
82  
83              if (value == 0) {
84                  value = getActionLabel().compareTo(
85                      permissionDisplay.getActionLabel());
86              }
87          }
88  
89          return value;
90      }
91  
92      public boolean equals(Object obj) {
93          if (obj == null) {
94              return false;
95          }
96  
97          if (!(obj instanceof PermissionDisplay)) {
98              return false;
99          }
100 
101         PermissionDisplay permissionDisplay = (PermissionDisplay)obj;
102 
103         if (_portletName.equals(permissionDisplay.getPortletName()) &&
104             _modelName.equals(permissionDisplay.getModelName()) &&
105             _actionId.equals(permissionDisplay.getActionId())) {
106 
107             return true;
108         }
109         else {
110             return false;
111         }
112     }
113 
114     public int hashCode() {
115         return _portletName.concat(_modelName).concat(_actionId).hashCode();
116     }
117 
118     private Permission _permission;
119     private Resource _resource;
120     private String _portletName;
121     private String _portletLabel;
122     private String _modelName;
123     private String _modelLabel;
124     private String _actionId;
125     private String _actionLabel;
126 
127 }