| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| CumulativePermission |
|
| 1.25;1.25 |
| 1 | /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
|
| 2 | * |
|
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 4 | * you may not use this file except in compliance with the License. |
|
| 5 | * You may obtain a copy of the License at |
|
| 6 | * |
|
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 8 | * |
|
| 9 | * 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 | /** |
|
| 22 | * Represents a <code>Permission</code> that is constructed at runtime from other permissions.<p>Methods return |
|
| 23 | * <code>this</code>, in order to facilitate method chaining.</p> |
|
| 24 | * |
|
| 25 | * @author Ben Alex |
|
| 26 | * @version $Id: CumulativePermission.java 1868 2007-05-25 02:28:40Z benalex $ |
|
| 27 | */ |
|
| 28 | 13 | public class CumulativePermission implements Permission { |
| 29 | //~ Instance fields ================================================================================================ |
|
| 30 | ||
| 31 | 13 | private String pattern = THIRTY_TWO_RESERVED_OFF; |
| 32 | 13 | private int mask = 0; |
| 33 | ||
| 34 | //~ Methods ======================================================================================================== |
|
| 35 | ||
| 36 | public CumulativePermission clear(Permission permission) { |
|
| 37 | 6 | this.mask &= ~permission.getMask(); |
| 38 | 6 | this.pattern = AclFormattingUtils.demergePatterns(this.pattern, permission.getPattern()); |
| 39 | ||
| 40 | 6 | return this; |
| 41 | } |
|
| 42 | ||
| 43 | public CumulativePermission clear() { |
|
| 44 | 0 | this.mask = 0; |
| 45 | 0 | this.pattern = THIRTY_TWO_RESERVED_OFF; |
| 46 | ||
| 47 | 0 | return this; |
| 48 | } |
|
| 49 | ||
| 50 | public boolean equals(Object arg0) { |
|
| 51 | 0 | if (!(arg0 instanceof CumulativePermission)) { |
| 52 | 0 | return false; |
| 53 | } |
|
| 54 | ||
| 55 | 0 | CumulativePermission rhs = (CumulativePermission) arg0; |
| 56 | ||
| 57 | 0 | return (this.mask == rhs.getMask()); |
| 58 | } |
|
| 59 | ||
| 60 | public int hashCode() { |
|
| 61 | 0 | return this.mask; |
| 62 | } |
|
| 63 | ||
| 64 | public int getMask() { |
|
| 65 | 2 | return this.mask; |
| 66 | } |
|
| 67 | ||
| 68 | public String getPattern() { |
|
| 69 | 0 | return this.pattern; |
| 70 | } |
|
| 71 | ||
| 72 | public CumulativePermission set(Permission permission) { |
|
| 73 | 24 | this.mask |= permission.getMask(); |
| 74 | 24 | this.pattern = AclFormattingUtils.mergePatterns(this.pattern, permission.getPattern()); |
| 75 | ||
| 76 | 24 | return this; |
| 77 | } |
|
| 78 | ||
| 79 | public String toString() { |
|
| 80 | 11 | return "CumulativePermission[" + pattern + "=" + this.mask + "]"; |
| 81 | } |
|
| 82 | } |