1 13 package org.jahia.services.acl; 14 15 import java.io.Serializable ; 16 17 public class JahiaACLEntry implements Cloneable , Serializable { 18 public static final int ACL_YES = 0; 19 public static final int ACL_NO = 1; 20 public static final int ACL_NEUTRAL = 2; 21 22 private int mState = 0; 23 private int mTriState = 0xFFFFFFFF; 25 26 30 public JahiaACLEntry () { 31 } 32 33 34 43 public JahiaACLEntry (int state, int tristate) { 44 mState = state; 45 mTriState = tristate; 46 } 47 48 49 57 public int getPermission (int permission) { 58 int mask; 59 60 mask = 1; 61 mask = mask << permission; 62 63 if ((mTriState & mask) != 0) { 64 return ACL_NEUTRAL; 65 } 66 67 if ((mState & mask) != 0) { 68 return ACL_YES; 69 } 70 return ACL_NO; 71 } 72 73 74 82 public void setPermission (int permission, int state) { 83 int tmp = 0; 84 int tmp_tristate = 0; 85 86 tmp = 1; 88 tmp = tmp << permission; 89 90 if (state == ACL_YES) { 91 mState |= tmp; 92 } else { 93 mState &= ~tmp; 94 } 95 96 tmp = 1; 98 tmp = tmp << permission; 99 100 if (state == ACL_NEUTRAL) { 101 mTriState |= tmp; 102 } else { 103 mTriState &= ~tmp; 104 } 105 } 106 107 108 115 public final int getState () { 116 return mState; 117 } 118 119 120 127 public final int getTriState () { 128 return mTriState; 129 } 130 131 132 141 public final void set (int state, int tristate) { 142 mState = state; 143 mTriState = tristate; 144 } 145 146 147 152 public final void clear () { 153 set (0, 0xFFFF); 154 } 155 156 167 public boolean hasSameBitsActivated (JahiaACLEntry entry) { 168 if (entry != null) { 169 int mask = (entry.mState & mState); 170 if (mask == entry.mState) { 171 return (((mTriState & mask) == 0) && ((entry.mTriState & mask) == 0)); 172 } else { 173 return false; 174 } 175 } 176 return false; 177 } 178 179 185 public String toString () { 186 String result = "state=[" + Integer.toBinaryString (mState) + 187 "], tristate=[" + Integer.toBinaryString (mTriState) + "]"; 188 return result; 189 } 190 191 198 public void merge (JahiaACLEntry entry) { 199 if (entry != null) { 200 mState = mState | entry.getState (); 201 mTriState = mTriState & entry.getTriState (); 202 } 203 } 204 205 212 public Object clone () { 213 return new JahiaACLEntry (mState, mTriState); 214 } 215 } 216 | Popular Tags |