001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: ConditionDecision.java,v 1.2 2008/06/25 05:43:43 qcheng Exp $
026 *
027 */
028
029
030
031package com.sun.identity.policy;
032
033import java.util.Map;
034import java.util.HashMap;
035
036/**
037 * The <code>ConditionDecision</code> class represents the result of  
038 * the evaluation of a condition. 
039 *
040 * @supported.all.api
041 */
042public class ConditionDecision {
043
044    private boolean allowed;
045    private Map advices = new HashMap();
046    private long timeToLive = Long.MAX_VALUE;
047
048    /** No argument constructor */
049    public ConditionDecision() {
050    }
051
052    /** Constructs <code>ConditionDecision</code> given the boolean result of 
053     *  a condition evaluation
054     *
055     * @param allowed boolean result of a condition evaluation
056     */
057    public ConditionDecision(boolean allowed) {
058        this.allowed = allowed;
059    }
060
061    /** Constructs <code>ConditionDecision</code> given the boolean result of
062     *  a condition evaluation and  advices 
063     *
064     * @param allowed boolean result of a condition evaluation
065     * @param advices A <code>Map</code> representing advices associated with 
066     *     this <code>ConditionDecision</code>.
067     *     The advice name is the key to the Map. The
068     *     value is a <code>Set</code> of advice message Strings corresponding 
069     *     to the advice name.
070     *     The advice name  examples are 
071     *     SessionCondition.SESSION_CONDITION_ADVICE
072     *     AuthSchemeCondition.AUTH_SCHEME_CONDITION_ADVICE
073     */
074    public ConditionDecision(boolean allowed, Map advices) {
075        this.allowed = allowed;
076        this.advices = advices;
077    }
078
079    /** Constructs <code>ConditionDecision</code> given the boolean result of 
080     *  a condition evaluation and time to live
081     *
082     * @param allowed boolean result of a condition evaluation
083     * @param timeToLive GMT time in milliseconds since epoch when 
084     *     this object is to be treated as expired. 
085     */
086    public ConditionDecision(boolean allowed, long timeToLive) {
087        this.allowed = allowed;
088        this.timeToLive = timeToLive;
089    }
090
091    /** Constructs <code>ConditionDecision</code> given the boolean result of 
092     *  a condition evaluation, time to live and advices
093     *
094     * @param allowed boolean result of a condition evaluation
095     * @param timeToLive GMT time in milliseconds since epoch when 
096     *     this object is to be treated as expired. 
097     * @param advices advices associated with this action decision. 
098     *     The advice name is the key to the Map. The
099     *     value is a set of advice message Strings corresponding to the 
100     *     advice name.
101     *     The advice name  examples are 
102     *     SessionCondition.SESSION_CONDITION_ADVICE
103     *     AuthSchemeCondition.AUTH_SCHEME_CONDITION_ADVICE
104     */
105    public ConditionDecision(boolean allowed, long timeToLive, Map advices) {
106        this.allowed = allowed;
107        this.timeToLive = timeToLive;
108        this.advices = advices;
109    }
110
111    /** Sets boolean result of condition evaluation
112     *
113     * @param allowed boolean result of condition evaluation
114     */
115    public void setAllowed(boolean allowed) {
116        this.allowed = allowed;
117    }
118
119    /** Gets boolean result of condition evaluation
120     *
121     * @return result of condition evaluation
122     */
123    public boolean isAllowed() {
124        return allowed;
125    }
126
127    /** Sets advices associated with this object 
128     *
129     * @param advices A <code>Map</code> representing advices associated with 
130     *     this object.
131     *     The advice name is the key to the Map. The
132     *     value is a <code>Set</code> of advice message Strings corresponding 
133     *     to the  advice name.
134     *     The advice name  examples are 
135     *     SessionCondition.SESSION_CONDITION_ADVICE
136     *     AuthSchemeCondition.AUTH_SCHEME_CONDITION_ADVICE
137     */
138    public void setAdvices(Map advices) {
139        this.advices = advices;
140    }
141
142    /** Gets advices associated with this object 
143     *
144     * @return advices associated with this object.
145     *     The advice name is the key to the <code>Map</code>. The
146     *     value is a <code>Set</code> of advice message Strings corresponding 
147     *     to the advice name.
148     */
149    public Map getAdvices() {
150        return advices;
151    }
152
153    /** Sets <code>timeToLive</code> associated with this object 
154     *
155     * @param timeToLive GMT time in milliseconds since epoch when 
156     *     this object is to be treated as expired. 
157     */
158    public void setTimeToLive(long timeToLive) {
159        this.timeToLive = timeToLive;
160    }
161
162    /** Gets <code>timeToLive</code> associated with this object 
163     *
164     * @return GMT time in milliseconds since epoch when 
165     *     this object is to be treated as expired. 
166     */
167    public long getTimeToLive() {
168        return timeToLive;
169    }
170}