001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2008 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.3 2009/09/05 00:24:04 veiming Exp $
026 */
027
028/**
029 * Portions copyright 2010-2014 ForgeRock AS.
030 */
031
032package com.sun.identity.entitlement;
033
034import java.util.Collections;
035import java.util.HashMap;
036import java.util.Map;
037import java.util.Set;
038
039/**
040 * Class to represent {@link EntitlementCondition} evaluation match result and - if applicable - its advices.
041 *
042 * @supported.all.api
043 */
044public class ConditionDecision {
045
046    private boolean satisfied;
047    private Map<String, Set<String>> advices;
048    private long timeToLive = Long.MAX_VALUE;
049
050    /**
051     * Constructs an instance of <code>ConditionDecision</code>.
052     *
053     * @param satisfied result of this <code>ConditionDecision</code>.
054     * @param advices Advice map of this <code>ConditionDecision</code>.
055     */
056    public ConditionDecision(boolean satisfied, Map<String, Set<String>> advices) {
057        this.satisfied = satisfied;
058        this.advices = new HashMap<String, Set<String>>(advices);
059    }
060
061    /**
062     * Constructs an instance of <code>ConditionDecision</code>.
063     *
064     * @param satisfied Result of this <code>ConditionDecision</code>.
065     * @param advices Advice map of this <code>ConditionDecision</code>.
066     * @param ttl The TTL of this <code>ConditionDecision</code>.
067     */
068    public ConditionDecision(boolean satisfied, Map<String, Set<String>> advices, long ttl) {
069        this(satisfied, advices);
070        this.timeToLive = ttl;
071    }
072
073    /**
074     * Whether this <code>ConditionDecision</code> is satisfied.
075     *
076     * @return <code>true</code> if <code>ConditionDecision</code> is fulfilled.
077     */
078    public boolean isSatisfied() {
079        return satisfied;
080    }
081
082    /**
083     * Sets satisfied state.
084     *
085     * @param satisfied New satisfied state.
086     */
087    public void setSatisfied(boolean satisfied) {
088        this.satisfied = satisfied;
089    }
090
091    /**
092     * Advices associated with this <code>ConditionDecision</code>.
093     *
094     * @return advices of <code>ConditionDecision</code>.
095     */
096    public Map<String, Set<String>> getAdvices() {
097        return Collections.unmodifiableMap(advices);
098    }
099
100    /**
101     * Clears the current advices associated with this <code>ConditionDecision</code>.
102     */
103    public void clearAdvices() {
104        advices.clear();
105    }
106
107    /**
108     * Adds an advice (from another <code>ConditionDecision</code>) to this <code>ConditionDecision</code>.
109     *
110     * @param decision The <code>ConditionDecision</code> whose advices should be added to this
111     *                 <code>ConditionDecision</code>.
112     */
113    public void addAdvices(ConditionDecision decision) {
114        if (decision != null) {
115            Map<String, Set<String>> otherAdvices = decision.getAdvices();
116            if ((otherAdvices != null) && !otherAdvices.isEmpty()) {
117                if ((advices == null) || advices.isEmpty()) {
118                    advices = new HashMap<String, Set<String>>();
119                }
120                advices.putAll(otherAdvices);
121            }
122        }
123    }
124
125    /**
126     * Returns the time to live (TTL) of this <code>ConditionDecision</code>.
127     *
128     * @return The TTL time in ms.
129     */
130    public long getTimeToLive() {
131        return timeToLive;
132    }
133}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.