mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
02.21.2013 e8388c3f6461f17415b6578d2dad0b4d13138282
OpenDJ 3 : config framework

Reducing compilation errors in org.opends.server.admin packages :
all classes in package org.opends.server.admin.condition compile

* Simple changes in org.opends.server.admin.condition package
** use Validator class from SDK
** remove API annotation
6 files modified
633 ■■■■■ changed files
opendj-admin/src/main/java/org/opends/server/admin/condition/ANDCondition.java 104 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/condition/ContainsCondition.java 246 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/condition/IsPresentCondition.java 92 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/condition/NOTCondition.java 85 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/condition/ORCondition.java 104 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/condition/package-info.java 2 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/condition/ANDCondition.java
@@ -26,8 +26,6 @@
 */
package org.opends.server.admin.condition;
import java.util.Arrays;
import java.util.List;
@@ -38,75 +36,61 @@
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>true</code> if and only if
 * all of its sub-conditions are <code>true</code>.
 * A condition which evaluates to <code>true</code> if and only if all of its
 * sub-conditions are <code>true</code>.
 */
public final class ANDCondition 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 AND condition with the provided
   * sub-conditions.
   *
   * @param conditions
   *          The sub-conditions which will be combined using a
   *          logical AND.
   */
  public ANDCondition(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 false;
      }
    /**
     * Creates a new logical AND condition with the provided sub-conditions.
     *
     * @param conditions
     *            The sub-conditions which will be combined using a logical AND.
     */
    public ANDCondition(Condition... conditions) {
        Validator.ensureNotNull(conditions);
        this.conditions = Arrays.asList(conditions);
    }
    return true;
  }
  /**
   * {@inheritDoc}
   */
  public boolean evaluate(ServerManagedObject<?> managedObject)
      throws ConfigException {
    for (Condition condition : conditions) {
      if (!condition.evaluate(managedObject)) {
        return false;
      }
    /**
     * {@inheritDoc}
     */
    public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws AuthorizationException,
            CommunicationException {
        for (Condition condition : conditions) {
            if (!condition.evaluate(context, managedObject)) {
                return false;
            }
        }
        return true;
    }
    return true;
  }
  /**
   * {@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 false;
            }
        }
        return true;
    }
  }
    /**
     * {@inheritDoc}
     */
    public void initialize(AbstractManagedObjectDefinition<?, ?> d) throws Exception {
        for (Condition condition : conditions) {
            condition.initialize(d);
        }
    }
}
opendj-admin/src/main/java/org/opends/server/admin/condition/ContainsCondition.java
@@ -26,8 +26,6 @@
 */
package org.opends.server.admin.condition;
import java.util.SortedSet;
import org.opends.server.admin.AbstractManagedObjectDefinition;
@@ -39,176 +37,144 @@
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>true</code> if and only if a
 * property contains a particular value.
 * A condition which evaluates to <code>true</code> if and only if a property
 * contains a particular value.
 */
public final class ContainsCondition implements Condition {
  /**
   * The strongly typed underlying implementation.
   *
   * @param <T>
   *          The type of the property value being tested.
   */
  private static final class Impl<T> implements Condition {
    /**
     * The strongly typed underlying implementation.
     *
     * @param <T>
     *            The type of the property value being tested.
     */
    private static final class Impl<T> implements Condition {
    // The property.
    final PropertyDefinition<T> pd;
        // The property.
        final PropertyDefinition<T> pd;
    // The required property value.
    final T value;
        // The required property value.
        final T value;
        // Private constructor.
        private Impl(PropertyDefinition<T> pd, T value) throws IllegalPropertyValueStringException {
            this.pd = pd;
            this.value = value;
        }
        /**
         * {@inheritDoc}
         */
        public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject)
                throws AuthorizationException, CommunicationException {
            SortedSet<T> values = managedObject.getPropertyValues(pd);
            return values.contains(value);
        }
    // Private constructor.
    private Impl(PropertyDefinition<T> pd, T value)
        throws IllegalPropertyValueStringException {
      this.pd = pd;
      this.value = value;
        /**
         * {@inheritDoc}
         */
        public boolean evaluate(ServerManagedObject<?> managedObject) throws ConfigException {
            SortedSet<T> values = managedObject.getPropertyValues(pd);
            return values.contains(value);
        }
        /**
         * {@inheritDoc}
         */
        public void initialize(AbstractManagedObjectDefinition<?, ?> d) throws Exception {
            // Not used.
        }
        // Private implementation of fix() method.
        private void setPropertyValue(ManagedObject<?> managedObject) {
            managedObject.setPropertyValue(pd, value);
        }
    }
    // The strongly typed private implementation.
    private Impl<?> impl = null;
    // The property name.
    private final String propertyName;
    // The string representation of the required property value.
    private final String propertyStringValue;
    /**
     * Creates a new contains value condition.
     *
     * @param propertyName
     *            The property name.
     * @param stringValue
     *            The string representation of the required property value.
     */
    public ContainsCondition(String propertyName, String stringValue) {
        Validator.ensureNotNull(propertyName, stringValue);
        this.propertyName = propertyName;
        this.propertyStringValue = stringValue;
    }
    /**
     * {@inheritDoc}
     */
    public boolean evaluate(ManagementContext context,
        ManagedObject<?> managedObject) throws AuthorizationException,
        CommunicationException {
      SortedSet<T> values = managedObject.getPropertyValues(pd);
      return values.contains(value);
    public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws AuthorizationException,
            CommunicationException {
        return impl.evaluate(context, managedObject);
    }
    /**
     * {@inheritDoc}
     */
    public boolean evaluate(ServerManagedObject<?> managedObject)
        throws ConfigException {
      SortedSet<T> values = managedObject.getPropertyValues(pd);
      return values.contains(value);
    public boolean evaluate(ServerManagedObject<?> managedObject) throws ConfigException {
        return impl.evaluate(managedObject);
    }
    /**
     * Modifies the provided managed object so that it has the property value
     * associated with this condition.
     *
     * @param managedObject
     *            The managed object.
     */
    public void setPropertyValue(ManagedObject<?> managedObject) {
        impl.setPropertyValue(managedObject);
    }
    /**
     * {@inheritDoc}
     */
    public void initialize(AbstractManagedObjectDefinition<?, ?> d)
        throws Exception {
      // Not used.
    public void initialize(AbstractManagedObjectDefinition<?, ?> d) throws Exception {
        // Decode the property.
        buildImpl(d.getPropertyDefinition(propertyName));
    }
    // Private implementation of fix() method.
    private void setPropertyValue(ManagedObject<?> managedObject) {
      managedObject.setPropertyValue(pd, value);
    // Creates the new private implementation.
    private <T> void buildImpl(PropertyDefinition<T> pd) throws IllegalPropertyValueStringException {
        T value = pd.decodeValue(propertyStringValue);
        this.impl = new Impl<T>(pd, value);
    }
  }
    /**
     * Returns the property definition associated with this condition.
     *
     * @return the property definition associated with this condition.
     */
    public PropertyDefinition<?> getPropertyDefinition() {
        return impl.pd;
    }
  // The strongly typed private implementation.
  private Impl<?> impl = null;
  // The property name.
  private final String propertyName;
  // The string representation of the required property value.
  private final String propertyStringValue;
  /**
   * Creates a new contains value condition.
   *
   * @param propertyName
   *          The property name.
   * @param stringValue
   *          The string representation of the required property
   *          value.
   */
  public ContainsCondition(String propertyName, String stringValue) {
    Validator.ensureNotNull(propertyName, stringValue);
    this.propertyName = propertyName;
    this.propertyStringValue = stringValue;
  }
  /**
   * {@inheritDoc}
   */
  public boolean evaluate(ManagementContext context,
      ManagedObject<?> managedObject) throws AuthorizationException,
      CommunicationException {
    return impl.evaluate(context, managedObject);
  }
  /**
   * {@inheritDoc}
   */
  public boolean evaluate(ServerManagedObject<?> managedObject)
      throws ConfigException {
    return impl.evaluate(managedObject);
  }
  /**
   * Modifies the provided managed object so that it has the property
   * value associated with this condition.
   *
   * @param managedObject
   *          The managed object.
   */
  public void setPropertyValue(ManagedObject<?> managedObject) {
    impl.setPropertyValue(managedObject);
  }
  /**
   * {@inheritDoc}
   */
  public void initialize(AbstractManagedObjectDefinition<?, ?> d)
      throws Exception {
    // Decode the property.
    buildImpl(d.getPropertyDefinition(propertyName));
  }
  // Creates the new private implementation.
  private <T> void buildImpl(PropertyDefinition<T> pd)
      throws IllegalPropertyValueStringException {
    T value = pd.decodeValue(propertyStringValue);
    this.impl = new Impl<T>(pd, value);
  }
  /**
   * Returns the property definition associated with this condition.
   * @return the property definition associated with this condition.
   */
  public PropertyDefinition<?> getPropertyDefinition()
  {
    return impl.pd;
  }
  /**
   * Returns the value that must be set for this condition to be fulfilled.
   * @return the value that must be set for this condition to be fulfilled.
   */
  public Object getValue()
  {
    return impl.value;
  }
    /**
     * Returns the value that must be set for this condition to be fulfilled.
     *
     * @return the value that must be set for this condition to be fulfilled.
     */
    public Object getValue() {
        return impl.value;
    }
}
opendj-admin/src/main/java/org/opends/server/admin/condition/IsPresentCondition.java
@@ -26,8 +26,6 @@
 */
package org.opends.server.admin.condition;
import java.util.SortedSet;
import org.opends.server.admin.AbstractManagedObjectDefinition;
@@ -38,67 +36,55 @@
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>true</code> if and only if a
 * particular property has any values specified.
 * A condition which evaluates to <code>true</code> if and only if a particular
 * property has any values specified.
 */
public final class IsPresentCondition implements Condition {
  // The property name.
  private final String propertyName;
    // The property name.
    private final String propertyName;
  // The property definition.
  private PropertyDefinition<?> pd;
    // The property definition.
    private PropertyDefinition<?> pd;
    /**
     * Creates a new is present condition.
     *
     * @param propertyName
     *            The property name.
     */
    public IsPresentCondition(String propertyName) {
        Validator.ensureNotNull(propertyName);
        this.propertyName = propertyName;
    }
    /**
     * {@inheritDoc}
     */
    public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws AuthorizationException,
            CommunicationException {
        SortedSet<?> values = managedObject.getPropertyValues(pd);
        return !values.isEmpty();
    }
  /**
   * Creates a new is present condition.
   *
   * @param propertyName
   *          The property name.
   */
  public IsPresentCondition(String propertyName) {
    Validator.ensureNotNull(propertyName);
    this.propertyName = propertyName;
  }
    /**
     * {@inheritDoc}
     */
    public boolean evaluate(ServerManagedObject<?> managedObject) throws ConfigException {
        SortedSet<?> values = managedObject.getPropertyValues(pd);
        return !values.isEmpty();
    }
  /**
   * {@inheritDoc}
   */
  public boolean evaluate(ManagementContext context,
      ManagedObject<?> managedObject) throws AuthorizationException,
      CommunicationException {
    SortedSet<?> values = managedObject.getPropertyValues(pd);
    return !values.isEmpty();
  }
  /**
   * {@inheritDoc}
   */
  public boolean evaluate(ServerManagedObject<?> managedObject)
      throws ConfigException {
    SortedSet<?> values = managedObject.getPropertyValues(pd);
    return !values.isEmpty();
  }
  /**
   * {@inheritDoc}
   */
  public void initialize(AbstractManagedObjectDefinition<?, ?> d)
      throws Exception {
    // Decode the property.
    this.pd = d.getPropertyDefinition(propertyName);
  }
    /**
     * {@inheritDoc}
     */
    public void initialize(AbstractManagedObjectDefinition<?, ?> d) throws Exception {
        // Decode the property.
        this.pd = d.getPropertyDefinition(propertyName);
    }
}
opendj-admin/src/main/java/org/opends/server/admin/condition/NOTCondition.java
@@ -26,8 +26,6 @@
 */
package org.opends.server.admin.condition;
import org.opends.server.admin.AbstractManagedObjectDefinition;
import org.opends.server.admin.client.AuthorizationException;
import org.opends.server.admin.client.CommunicationException;
@@ -35,63 +33,50 @@
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>true</code> if the
 * sub-condition is <code>false</code>, or <code>false</code> if
 * the sub-condition is <code>true</code>.
 * A condition which evaluates to <code>true</code> if the sub-condition is
 * <code>false</code>, or <code>false</code> if the sub-condition is
 * <code>true</code>.
 */
public final class NOTCondition implements Condition {
  // The single sub-condition.
  private final Condition condition;
    // The single sub-condition.
    private final Condition condition;
    /**
     * Creates a new logical NOT condition with the provided sub-condition.
     *
     * @param condition
     *            The sub-condition which will be inverted.
     */
    public NOTCondition(Condition condition) {
        Validator.ensureNotNull(condition);
        this.condition = condition;
    }
    /**
     * {@inheritDoc}
     */
    public boolean evaluate(ManagementContext context, ManagedObject<?> managedObject) throws AuthorizationException,
            CommunicationException {
        return !condition.evaluate(context, managedObject);
    }
  /**
   * Creates a new logical NOT condition with the provided
   * sub-condition.
   *
   * @param condition
   *          The sub-condition which will be inverted.
   */
  public NOTCondition(Condition condition) {
    Validator.ensureNotNull(condition);
    this.condition = condition;
  }
    /**
     * {@inheritDoc}
     */
    public boolean evaluate(ServerManagedObject<?> managedObject) throws ConfigException {
        return !condition.evaluate(managedObject);
    }
  /**
   * {@inheritDoc}
   */
  public boolean evaluate(ManagementContext context,
      ManagedObject<?> managedObject) throws AuthorizationException,
      CommunicationException {
    return !condition.evaluate(context, managedObject);
  }
  /**
   * {@inheritDoc}
   */
  public boolean evaluate(ServerManagedObject<?> managedObject)
      throws ConfigException {
    return !condition.evaluate(managedObject);
  }
  /**
   * {@inheritDoc}
   */
  public void initialize(AbstractManagedObjectDefinition<?, ?> d)
      throws Exception {
    condition.initialize(d);
  }
    /**
     * {@inheritDoc}
     */
    public void initialize(AbstractManagedObjectDefinition<?, ?> d) throws Exception {
        condition.initialize(d);
    }
}
opendj-admin/src/main/java/org/opends/server/admin/condition/ORCondition.java
@@ -26,8 +26,6 @@
 */
package org.opends.server.admin.condition;
import java.util.Arrays;
import java.util.List;
@@ -38,75 +36,61 @@
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);
        }
    }
}
opendj-admin/src/main/java/org/opends/server/admin/condition/package-info.java
@@ -31,6 +31,4 @@
 * This package contains interfaces for building and evaluating
 * arbitrary logical conditions which can be used with constraints.
 */
@org.opends.server.types.PublicAPI(
    stability = org.opends.server.types.StabilityLevel.PRIVATE)
package org.opends.server.admin.condition;