| | |
| | | */ |
| | | package org.opends.server.admin.condition; |
| | | |
| | | |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | |
| | | import org.opends.server.admin.client.ManagementContext; |
| | | import org.opends.server.admin.server.ServerManagedObject; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.util.Validator; |
| | | |
| | | |
| | | import com.forgerock.opendj.util.Validator; |
| | | |
| | | /** |
| | | * A condition which evaluates to <code>false</code> if and only if |
| | | * all of its sub-conditions are <code>false</code>. |
| | | * A condition which evaluates to <code>false</code> if and only if all of its |
| | | * sub-conditions are <code>false</code>. |
| | | */ |
| | | public final class ORCondition implements Condition { |
| | | |
| | | // The list of sub-conditions. |
| | | private final List<Condition> conditions; |
| | | // The list of sub-conditions. |
| | | private final List<Condition> conditions; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Creates a new logical OR condition with the provided |
| | | * sub-conditions. |
| | | * |
| | | * @param conditions |
| | | * The sub-conditions which will be combined using a |
| | | * logical OR. |
| | | */ |
| | | public ORCondition(Condition... conditions) { |
| | | Validator.ensureNotNull(conditions); |
| | | this.conditions = Arrays.asList(conditions); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ManagementContext context, |
| | | ManagedObject<?> managedObject) throws AuthorizationException, |
| | | CommunicationException { |
| | | for (Condition condition : conditions) { |
| | | if (condition.evaluate(context, managedObject)) { |
| | | return true; |
| | | } |
| | | /** |
| | | * Creates a new logical OR condition with the provided sub-conditions. |
| | | * |
| | | * @param conditions |
| | | * The sub-conditions which will be combined using a logical OR. |
| | | */ |
| | | public ORCondition(Condition... conditions) { |
| | | Validator.ensureNotNull(conditions); |
| | | this.conditions = Arrays.asList(conditions); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ServerManagedObject<?> managedObject) |
| | | throws ConfigException { |
| | | for (Condition condition : conditions) { |
| | | if (condition.evaluate(managedObject)) { |
| | | return true; |
| | | } |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws AuthorizationException, |
| | | CommunicationException { |
| | | for (Condition condition : conditions) { |
| | | if (condition.evaluate(context, managedObject)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void initialize(AbstractManagedObjectDefinition<?, ?> d) |
| | | throws Exception { |
| | | for (Condition condition : conditions) { |
| | | condition.initialize(d); |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean evaluate(ServerManagedObject<?> managedObject) throws ConfigException { |
| | | for (Condition condition : conditions) { |
| | | if (condition.evaluate(managedObject)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void initialize(AbstractManagedObjectDefinition<?, ?> d) throws Exception { |
| | | for (Condition condition : conditions) { |
| | | condition.initialize(d); |
| | | } |
| | | } |
| | | |
| | | } |