001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Nuxeo - initial API and implementation 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.ecm.core.api.security; 016 017import java.io.Serializable; 018 019/** 020 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 021 */ 022public final class Access implements Serializable { 023 024 public static final Access GRANT = new Access(1); 025 026 public static final Access DENY = new Access(0); 027 028 public static final Access UNKNOWN = new Access(-1); 029 030 private static final long serialVersionUID = 4797108620404301529L; 031 032 private final int value; 033 034 private Access(int value) { 035 this.value = value; 036 } 037 038 public int value() { 039 return value; 040 } 041 042 /** 043 * If granted returns true, otherwise returns false. 044 * 045 * @return true if granted 046 */ 047 public boolean toBoolean() { 048 return value > 0; 049 } 050 051 @Override 052 public String toString() { 053 return String.valueOf(value); 054 } 055 056 /** 057 * Be aware of Java serialization. Avoid initializing another instance than allowed constants. 058 * 059 * @return GRANT, DENY or UNKNOWN 060 */ 061 private Object readResolve() { 062 switch (value) { 063 case 1: 064 return GRANT; 065 case 0: 066 return DENY; 067 default: 068 return UNKNOWN; 069 } 070 } 071 072}