1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.model;
24  
25  import java.io.Serializable;
26  
27  /**
28   * <a href="PermissionDisplay.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   * @author Jorge Ferrer
32   *
33   */
34  public class PermissionDisplay implements Comparable, Serializable {
35  
36      public PermissionDisplay(
37          Permission permission, Resource resource, String portletName,
38          String portletLabel, String modelName, String modelLabel,
39          String actionId, String actionLabel) {
40  
41          _permission = permission;
42          _resource = resource;
43          _portletName = portletName;
44          _portletLabel = portletLabel;
45          _modelName = modelName;
46          _modelLabel = modelLabel;
47          _actionId = actionId;
48          _actionLabel = actionLabel;
49      }
50  
51      public Permission getPermission() {
52          return _permission;
53      }
54  
55      public Resource getResource() {
56          return _resource;
57      }
58  
59      public String getPortletName() {
60          return _portletName;
61      }
62  
63      public String getPortletLabel() {
64          return _portletLabel;
65      }
66  
67      public String getModelName() {
68          return _modelName;
69      }
70  
71      public String getModelLabel() {
72          return _modelLabel;
73      }
74  
75      public String getActionId() {
76          return _actionId;
77      }
78  
79      public String getActionLabel() {
80          return _actionLabel;
81      }
82  
83      public int compareTo(Object obj) {
84          if (obj == null) {
85              return -1;
86          }
87  
88          PermissionDisplay permissionDisplay = (PermissionDisplay)obj;
89  
90          int value = getPortletLabel().compareTo(
91              permissionDisplay.getPortletLabel());
92  
93          if (value == 0) {
94              value = getModelLabel().compareTo(
95                  permissionDisplay.getModelLabel());
96  
97              if (value == 0) {
98                  value = getActionLabel().compareTo(
99                      permissionDisplay.getActionLabel());
100             }
101         }
102 
103         return value;
104     }
105 
106     public boolean equals(Object obj) {
107         if (obj == null) {
108             return false;
109         }
110 
111         if (!(obj instanceof PermissionDisplay)) {
112             return false;
113         }
114 
115         PermissionDisplay permissionDisplay = (PermissionDisplay)obj;
116 
117         if (_portletName.equals(permissionDisplay.getPortletName()) &&
118             _modelName.equals(permissionDisplay.getModelName()) &&
119             _actionId.equals(permissionDisplay.getActionId())) {
120 
121             return true;
122         }
123         else {
124             return false;
125         }
126     }
127 
128     private Permission _permission;
129     private Resource _resource;
130     private String _portletName;
131     private String _portletLabel;
132     private String _modelName;
133     private String _modelLabel;
134     private String _actionId;
135     private String _actionLabel;
136 
137 }