001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014 ForgeRock AS
026 */
027package org.forgerock.opendj.config.conditions;
028
029import org.forgerock.opendj.config.AbstractManagedObjectDefinition;
030import org.forgerock.opendj.config.client.ManagedObject;
031import org.forgerock.opendj.config.client.ManagementContext;
032import org.forgerock.opendj.config.server.ConfigException;
033import org.forgerock.opendj.config.server.ServerManagedObject;
034import org.forgerock.opendj.ldap.LdapException;
035import org.forgerock.util.Reject;
036
037/**
038 * A condition which evaluates to <code>true</code> if the sub-condition is
039 * <code>false</code>, or <code>false</code> if the sub-condition is
040 * <code>true</code>.
041 */
042public final class NOTCondition implements Condition {
043
044    /** The single sub-condition. */
045    private final Condition condition;
046
047    /**
048     * Creates a new logical NOT condition with the provided sub-condition.
049     *
050     * @param condition
051     *            The sub-condition which will be inverted.
052     */
053    public NOTCondition(Condition condition) {
054        Reject.ifNull(condition);
055        this.condition = condition;
056    }
057
058    /** {@inheritDoc} */
059    public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws LdapException {
060        return !condition.evaluate(context, managedObject);
061    }
062
063    /** {@inheritDoc} */
064    public boolean evaluate(ServerManagedObject<?> managedObject) throws ConfigException {
065        return !condition.evaluate(managedObject);
066    }
067
068    /** {@inheritDoc} */
069    public void initialize(AbstractManagedObjectDefinition<?, ?> d) throws Exception {
070        condition.initialize(d);
071    }
072
073}