01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15: package org.acegisecurity.acls.domain;
16:
17: import org.acegisecurity.acls.AclFormattingUtils;
18: import org.acegisecurity.acls.Permission;
19:
20: /**
21: * Represents a <code>Permission</code> that is constructed at runtime from other permissions.<p>Methods return
22: * <code>this</code>, in order to facilitate method chaining.</p>
23: *
24: * @author Ben Alex
25: * @version $Id: CumulativePermission.java 1868 2007-05-25 02:28:40Z benalex $
26: */
27: public class CumulativePermission implements Permission {
28: //~ Instance fields ================================================================================================
29:
30: private String pattern = THIRTY_TWO_RESERVED_OFF;
31: private int mask = 0;
32:
33: //~ Methods ========================================================================================================
34:
35: public CumulativePermission clear(Permission permission) {
36: this .mask &= ~permission.getMask();
37: this .pattern = AclFormattingUtils.demergePatterns(this .pattern,
38: permission.getPattern());
39:
40: return this ;
41: }
42:
43: public CumulativePermission clear() {
44: this .mask = 0;
45: this .pattern = THIRTY_TWO_RESERVED_OFF;
46:
47: return this ;
48: }
49:
50: public boolean equals(Object arg0) {
51: if (!(arg0 instanceof CumulativePermission)) {
52: return false;
53: }
54:
55: CumulativePermission rhs = (CumulativePermission) arg0;
56:
57: return (this .mask == rhs.getMask());
58: }
59:
60: public int hashCode() {
61: return this .mask;
62: }
63:
64: public int getMask() {
65: return this .mask;
66: }
67:
68: public String getPattern() {
69: return this .pattern;
70: }
71:
72: public CumulativePermission set(Permission permission) {
73: this .mask |= permission.getMask();
74: this .pattern = AclFormattingUtils.mergePatterns(this .pattern,
75: permission.getPattern());
76:
77: return this ;
78: }
79:
80: public String toString() {
81: return "CumulativePermission[" + pattern + "=" + this .mask
82: + "]";
83: }
84: }
|