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