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

Nicolas Capponi
04.13.2013 e538344449d345daa6e5ecb9b05ceba5427408e9
OpenDJ 3 : config framework

Reducing compilation errors in org.opends.server.admin packages

* Changes in org.opends.server.admin.server package
** Replace use of custom logging classes and methods by slf4j logger and i18n framework
** Replace use of DN server class and methods by SDK DN class and methods
** Other minor changes

* Add i18n-slf4j dependency to pom.xml
15 files modified
2320 ■■■■■ changed files
opendj-admin/pom.xml 58 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/AdministratorAction.java 2 ●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigAddListenerAdaptor.java 21 ●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigChangeListenerAdaptor.java 200 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigDeleteListenerAdaptor.java 106 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigExceptionFactory.java 62 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigurationChangeListener.java 29 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigurationDeleteListener.java 28 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ConstraintViolationException.java 79 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/DNBuilder.java 35 ●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/DelayedConfigAddListener.java 83 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ServerConstraintHandler.java 142 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagedObject.java 982 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagedObjectDecodingException.java 61 ●●●●● patch | view | raw | blame | history
opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagementContext.java 432 ●●●●● patch | view | raw | blame | history
opendj-admin/pom.xml
@@ -32,6 +32,10 @@
      <artifactId>i18n-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.forgerock.commons</groupId>
      <artifactId>i18n-slf4j</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>
@@ -423,60 +427,6 @@
      </plugin>
    </plugins>
    <pluginManagement>
      <plugins>
        <!--This plugin's configuration is used to store Eclipse m2e settings
          only. It has no influence on the Maven build itself. -->
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <versionRange>[1.8,)</versionRange>
                    <goals>
                      <goal>parse-version</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <ignore></ignore>
                  </action>
                </pluginExecution>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>templating-maven-plugin</artifactId>
                    <versionRange>[1.0-alpha-3,)</versionRange>
                    <goals>
                      <goal>filter-sources</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <ignore></ignore>
                  </action>
                </pluginExecution>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>xml-maven-plugin</artifactId>
                    <versionRange>[1.0,)</versionRange>
                    <goals>
                      <goal>transform</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <ignore></ignore>
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
  <reporting>
opendj-admin/src/main/java/org/opends/server/admin/AdministratorAction.java
@@ -150,7 +150,7 @@
        ManagedObjectDefinitionI18NResource resource = ManagedObjectDefinitionI18NResource.getInstance();
        String property = "property." + propertyName + ".requires-admin-action.synopsis";
        try {
            return resource.getLocalizableMessage(definition, property, locale);
            return resource.getMessage(definition, property, locale);
        } catch (MissingResourceException e) {
            return null;
        }
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigAddListenerAdaptor.java
@@ -28,8 +28,6 @@
import static org.opends.server.loggers.debug.DebugLogger.*;
import java.util.LinkedList;
import java.util.List;
@@ -46,14 +44,12 @@
import org.opends.server.admin.SetRelationDefinition;
import org.opends.server.admin.DefinitionDecodingException.Reason;
import org.opends.server.api.ConfigAddListener;
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.ConfigChangeResult;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DebugLogLevel;
import org.opends.server.types.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.forgerock.opendj.ldap.ResultCode;
@@ -68,10 +64,7 @@
final class ConfigAddListenerAdaptor<S extends Configuration> extends
    AbstractConfigListenerAdaptor implements ConfigAddListener {
  /**
   * The tracer object for the debug logger.
   */
  private static final DebugTracer TRACER = getTracer();
  private static final Logger debugLogger = LoggerFactory.getLogger(ConfigAddListenerAdaptor.class);
  // Cached managed object between accept/apply callbacks.
  private ServerManagedObject<? extends S> cachedManagedObject;
@@ -196,9 +189,7 @@
          try {
            handler.performPostAdd(cachedManagedObject);
          } catch (ConfigException e) {
            if (debugEnabled()) {
              TRACER.debugCaught(DebugLogLevel.ERROR, e);
            }
              debugLogger.trace("Unable to perform post add", e);
          }
        }
      }
@@ -257,7 +248,7 @@
    }
    // Let the add listener decide.
    List<LocalizableMessage> reasons = new LinkedList<Message>();
    List<LocalizableMessage> reasons = new LinkedList<LocalizableMessage>();
    if (listener.isConfigurationAddAcceptable(cachedManagedObject, reasons)) {
      return true;
    } else {
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigChangeListenerAdaptor.java
@@ -26,9 +26,7 @@
 */
package org.opends.server.admin.server;
import static org.opends.server.loggers.debug.DebugLogger.*;
import static com.forgerock.opendj.ldap.AdminMessages.*;
import java.util.Collection;
import java.util.HashSet;
@@ -36,9 +34,12 @@
import java.util.List;
import java.util.Set;
import org.opends.messages.AdminMessages;
import com.forgerock.opendj.ldap.AdminMessages;
import com.forgerock.opendj.util.StaticUtils;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.admin.AbsoluteInheritedDefaultBehaviorProvider;
import org.opends.server.admin.AbstractManagedObjectDefinition;
import org.opends.server.admin.AliasDefaultBehaviorProvider;
@@ -55,40 +56,35 @@
import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
import org.opends.server.api.ConfigChangeListener;
import org.opends.server.api.ConfigDeleteListener;
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
import org.opends.server.loggers.ErrorLogger;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.types.ConfigChangeResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DebugLogLevel;
import org.opends.server.types.ResultCode;
import org.opends.server.util.StaticUtils;
import org.forgerock.opendj.ldap.ResultCode;
/**
 * An adaptor class which converts {@link ConfigChangeListener}
 * call-backs to {@link ServerManagedObjectChangeListener}
 * call-backs.
 * An adaptor class which converts {@link ConfigChangeListener} call-backs to
 * {@link ServerManagedObjectChangeListener} call-backs.
 *
 * @param <S>
 *          The type of server configuration handled by the change
 *          listener.
 *            The type of server configuration handled by the change listener.
 */
final class ConfigChangeListenerAdaptor<S extends Configuration> extends
    AbstractConfigListenerAdaptor implements ConfigChangeListener {
final class ConfigChangeListenerAdaptor<S extends Configuration> extends AbstractConfigListenerAdaptor implements
        ConfigChangeListener {
    private static final Logger debugLogger = LoggerFactory.getLogger(ConfigChangeListenerAdaptor.class);
    private static final LocalizedLogger adminLogger = LocalizedLogger.getLocalizedLogger(
            ERR_ADMIN_MANAGED_OBJECT_DOES_NOT_EXIST.get("").resourceName());
  /**
   * A default behavior visitor used for determining the set of
   * dependencies.
     * A default behavior visitor used for determining the set of dependencies.
   *
   * @param <T>
   *          The type of property.
   */
  private static final class Visitor<T> implements
      DefaultBehaviorProviderVisitor<T, Void, ManagedObjectPath<?, ?>> {
    private static final class Visitor<T> implements DefaultBehaviorProviderVisitor<T, Void, ManagedObjectPath<?, ?>> {
    /**
     * Finds the dependencies associated with the provided property
@@ -96,15 +92,13 @@
     *
     * @param <T>
     * @param path
     *          The current base path used for relative name
     *          resolution.
         *            The current base path used for relative name resolution.
     * @param pd
     *          The property definition.
     * @param dependencies
     *          Add dependencies names to this collection.
     */
    public static <T> void find(ManagedObjectPath<?, ?> path,
        PropertyDefinition<T> pd, Collection<DN> dependencies) {
        public static <T> void find(ManagedObjectPath<?, ?> path, PropertyDefinition<T> pd, Collection<DN> dependencies) {
      Visitor<T> v = new Visitor<T>(dependencies);
      DefaultBehaviorProvider<T> db = pd.getDefaultBehaviorProvider();
      db.accept(v, path);
@@ -113,93 +107,67 @@
    // The names of entries that this change listener depends on.
    private final Collection<DN> dependencies;
    // Prevent instantiation.
    private Visitor(Collection<DN> dependencies) {
      this.dependencies = dependencies;
    }
    /**
     * {@inheritDoc}
     */
    public Void visitAbsoluteInherited(
        AbsoluteInheritedDefaultBehaviorProvider<T> d,
        ManagedObjectPath<?, ?> p) {
        public Void visitAbsoluteInherited(AbsoluteInheritedDefaultBehaviorProvider<T> d, ManagedObjectPath<?, ?> p) {
      ManagedObjectPath<?, ?> next = d.getManagedObjectPath();
      dependencies.add(DNBuilder.create(next));
      // If the dependent property uses inherited defaults then
      // recursively get those as well.
      String propertyName = d.getPropertyName();
      AbstractManagedObjectDefinition<?, ?> mod = d
          .getManagedObjectDefinition();
            AbstractManagedObjectDefinition<?, ?> mod = d.getManagedObjectDefinition();
      PropertyDefinition<?> pd = mod.getPropertyDefinition(propertyName);
      find(next, pd, dependencies);
      return null;
    }
    /**
     * {@inheritDoc}
     */
    public Void visitAlias(AliasDefaultBehaviorProvider<T> d,
        ManagedObjectPath<?, ?> p) {
        public Void visitAlias(AliasDefaultBehaviorProvider<T> d, ManagedObjectPath<?, ?> p) {
      return null;
    }
    /**
     * {@inheritDoc}
     */
    public Void visitDefined(DefinedDefaultBehaviorProvider<T> d,
        ManagedObjectPath<?, ?> p) {
        public Void visitDefined(DefinedDefaultBehaviorProvider<T> d, ManagedObjectPath<?, ?> p) {
      return null;
    }
    /**
     * {@inheritDoc}
     */
    public Void visitRelativeInherited(
        RelativeInheritedDefaultBehaviorProvider<T> d,
        ManagedObjectPath<?, ?> p) {
        public Void visitRelativeInherited(RelativeInheritedDefaultBehaviorProvider<T> d, ManagedObjectPath<?, ?> p) {
      ManagedObjectPath<?, ?> next = d.getManagedObjectPath(p);
      dependencies.add(DNBuilder.create(next));
      // If the dependent property uses inherited defaults then
      // recursively get those as well.
      String propertyName = d.getPropertyName();
      AbstractManagedObjectDefinition<?, ?> mod = d
          .getManagedObjectDefinition();
            AbstractManagedObjectDefinition<?, ?> mod = d.getManagedObjectDefinition();
      PropertyDefinition<?> pd = mod.getPropertyDefinition(propertyName);
      find(next, pd, dependencies);
      return null;
    }
    /**
     * {@inheritDoc}
     */
    public Void visitUndefined(UndefinedDefaultBehaviorProvider<T> d,
        ManagedObjectPath<?, ?> p) {
        public Void visitUndefined(UndefinedDefaultBehaviorProvider<T> d, ManagedObjectPath<?, ?> p) {
      return null;
    }
  }
  /**
   * The tracer object for the debug logger.
   */
  private static final DebugTracer TRACER = getTracer();
  // Cached managed object between accept/apply call-backs.
  private ServerManagedObject<? extends S> cachedManagedObject;
@@ -223,8 +191,6 @@
  // The managed object path.
  private final ManagedObjectPath<?, S> path;
  /**
   * Create a new configuration change listener adaptor.
   *
@@ -246,12 +212,10 @@
    this.dependencies = new HashSet<DN>();
    this.dependencyListener = new ConfigChangeListener() {
      public ConfigChangeResult applyConfigurationChange(
          ConfigEntry configEntry) {
            public ConfigChangeResult applyConfigurationChange(ConfigEntry configEntry) {
        ConfigEntry dependentConfigEntry = getConfigEntry(dn);
        if (dependentConfigEntry != null) {
          return ConfigChangeListenerAdaptor.this
              .applyConfigurationChange(dependentConfigEntry);
                    return ConfigChangeListenerAdaptor.this.applyConfigurationChange(dependentConfigEntry);
        } else {
          // The dependent entry was not found.
          configEntry.deregisterChangeListener(this);
@@ -259,14 +223,12 @@
        }
      }
      public boolean configChangeIsAcceptable(ConfigEntry configEntry,
          LocalizableMessageBuilder unacceptableReason) {
        ConfigEntry dependentConfigEntry = getConfigEntry(dn);
        if (dependentConfigEntry != null) {
          return ConfigChangeListenerAdaptor.this.configChangeIsAcceptable(
              dependentConfigEntry, unacceptableReason, configEntry);
                    return ConfigChangeListenerAdaptor.this.configChangeIsAcceptable(dependentConfigEntry,
                            unacceptableReason, configEntry);
        } else {
          // The dependent entry was not found.
          configEntry.deregisterChangeListener(this);
@@ -297,8 +259,7 @@
    // entry is removed.
    this.cleanerListener = new ConfigDeleteListener() {
      public ConfigChangeResult applyConfigurationDelete(
          ConfigEntry configEntry) {
            public ConfigChangeResult applyConfigurationDelete(ConfigEntry configEntry) {
        // Perform finalization if the deleted entry is the monitored
        // entry.
        if (configEntry.getDN().equals(dn)) {
@@ -307,8 +268,6 @@
        return new ConfigChangeResult(ResultCode.SUCCESS, false);
      }
      public boolean configDeleteIsAcceptable(ConfigEntry configEntry,
          LocalizableMessageBuilder unacceptableReason) {
        // Always acceptable.
@@ -317,17 +276,15 @@
    };
    DN parent = dn.getParent();
        DN parent = dn.parent();
    if (parent != null) {
      ConfigEntry configEntry = getConfigEntry(dn.getParent());
            ConfigEntry configEntry = getConfigEntry(dn.parent();
      if (configEntry != null) {
        configEntry.registerDeleteListener(cleanerListener);
      }
    }
  }
  /**
   * {@inheritDoc}
   */
@@ -339,22 +296,17 @@
    // listener lists.
    cachedManagedObject.setConfigEntry(configEntry);
    ConfigChangeResult result = listener
        .applyConfigurationChange(cachedManagedObject);
        ConfigChangeResult result = listener.applyConfigurationChange(cachedManagedObject);
    // Now apply post constraint call-backs.
    if (result.getResultCode() == ResultCode.SUCCESS) {
      ManagedObjectDefinition<?, ?> d = cachedManagedObject
          .getManagedObjectDefinition();
            ManagedObjectDefinition<?, ?> d = cachedManagedObject.getManagedObjectDefinition();
      for (Constraint constraint : d.getAllConstraints()) {
        for (ServerConstraintHandler handler : constraint
            .getServerConstraintHandlers()) {
                for (ServerConstraintHandler handler : constraint.getServerConstraintHandlers()) {
          try {
            handler.performPostModify(cachedManagedObject);
          } catch (ConfigException e) {
            if (debugEnabled()) {
              TRACER.debugCaught(DebugLogLevel.ERROR, e);
            }
                        debugLogger.trace("Unable to perform post modify", e);
          }
        }
      }
@@ -363,40 +315,32 @@
    return result;
  }
  /**
   * {@inheritDoc}
   */
  public boolean configChangeIsAcceptable(ConfigEntry configEntry,
      LocalizableMessageBuilder unacceptableReason) {
    return configChangeIsAcceptable(configEntry, unacceptableReason,
        configEntry);
    public boolean configChangeIsAcceptable(ConfigEntry configEntry, LocalizableMessageBuilder unacceptableReason) {
        return configChangeIsAcceptable(configEntry, unacceptableReason, configEntry);
  }
  /**
   * Indicates whether the configuration entry that will result from a
   * proposed modification is acceptable to this change listener.
   *
   * @param configEntry
   *          The configuration entry that will result from the
   *          requested update.
     *            The configuration entry that will result from the requested
     *            update.
   * @param unacceptableReason
   *          A buffer to which this method can append a
   *          human-readable message explaining why the proposed
   *          change is not acceptable.
     *            A buffer to which this method can append a human-readable
     *            message explaining why the proposed change is not acceptable.
   * @param newConfigEntry
   *          The configuration entry that caused the notification
   *          (will be different from <code>configEntry</code> if a
   *          dependency was modified).
   * @return <CODE>true</CODE> if the proposed entry contains an
   *         acceptable configuration, or <CODE>false</CODE> if it
   *         does not.
     *            The configuration entry that caused the notification (will be
     *            different from <code>configEntry</code> if a dependency was
     *            modified).
     * @return <CODE>true</CODE> if the proposed entry contains an acceptable
     *         configuration, or <CODE>false</CODE> if it does not.
   */
  public boolean configChangeIsAcceptable(ConfigEntry configEntry,
      LocalizableMessageBuilder unacceptableReason, ConfigEntry newConfigEntry) {
    public boolean configChangeIsAcceptable(ConfigEntry configEntry, LocalizableMessageBuilder unacceptableReason,
            ConfigEntry newConfigEntry) {
    try {
      ServerManagementContext context = ServerManagementContext.getInstance();
      cachedManagedObject = context.decode(path, configEntry, newConfigEntry);
@@ -414,7 +358,7 @@
    }
    // Let the change listener decide.
    List<LocalizableMessage> reasons = new LinkedList<Message>();
        List<LocalizableMessage> reasons = new LinkedList<LocalizableMessage>();
    if (listener.isConfigurationChangeAcceptable(cachedManagedObject,reasons)) {
      return true;
    } else {
@@ -423,11 +367,9 @@
    }
  }
  /**
   * Finalizes this configuration change listener adaptor. This method
   * must be called before this change listener is removed.
     * Finalizes this configuration change listener adaptor. This method must be
     * called before this change listener is removed.
   */
  public void finalizeChangeListener() {
    // Remove the dependency listeners.
@@ -440,29 +382,24 @@
    // Now remove the cleaner listener as it will no longer be
    // needed.
    ConfigEntry parentConfigEntry = getConfigEntry(dn.getParent());
        ConfigEntry parentConfigEntry = getConfigEntry(dn.parent();
    if (parentConfigEntry != null) {
      parentConfigEntry.deregisterDeleteListener(cleanerListener);
    }
  }
  /**
   * Get the server managed object change listener associated with
   * this adaptor.
     * Get the server managed object change listener associated with this
     * adaptor.
   *
   * @return Returns the server managed object change listener
   *         associated with this adaptor.
     * @return Returns the server managed object change listener associated with
     *         this adaptor.
   */
  ServerManagedObjectChangeListener<? super S>
  getServerManagedObjectChangeListener() {
    ServerManagedObjectChangeListener<? super S> getServerManagedObjectChangeListener() {
    return listener;
  }
  // Returns the named configuration entry or null if it could not be
  // retrieved.
  private ConfigEntry getConfigEntry(DN dn) {
@@ -471,19 +408,12 @@
      if (configEntry != null) {
        return configEntry;
      } else {
        LocalizableMessage message = AdminMessages.ERR_ADMIN_MANAGED_OBJECT_DOES_NOT_EXIST
            .get(String.valueOf(dn));
        ErrorLogger.logError(message);
                adminLogger.error(ERR_ADMIN_MANAGED_OBJECT_DOES_NOT_EXIST, String.valueOf(dn));
      }
    } catch (ConfigException e) {
      // The dependent entry could not be retrieved.
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }
      LocalizableMessage message = AdminMessages.ERR_ADMIN_CANNOT_GET_MANAGED_OBJECT.get(
          String.valueOf(dn), StaticUtils.getExceptionMessage(e));
      ErrorLogger.logError(message);
            debugLogger.trace("The dependent entry could not be retrieved", e);
            adminLogger.error(ERR_ADMIN_CANNOT_GET_MANAGED_OBJECT, String.valueOf(dn),
                    StaticUtils.getExceptionMessage(e));
    }
    return null;
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigDeleteListenerAdaptor.java
@@ -26,16 +26,14 @@
 */
package org.opends.server.admin.server;
import static com.forgerock.opendj.ldap.AdminMessages.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
import java.util.LinkedList;
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.server.admin.Configuration;
import org.opends.server.admin.Constraint;
import org.opends.server.admin.DecodingException;
@@ -47,32 +45,24 @@
import org.opends.server.admin.SetRelationDefinition;
import org.opends.server.admin.DefinitionDecodingException.Reason;
import org.opends.server.api.ConfigDeleteListener;
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.ConfigChangeResult;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DebugLogLevel;
import org.opends.server.types.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.forgerock.opendj.ldap.ResultCode;
/**
 * An adaptor class which converts {@link ConfigDeleteListener}
 * callbacks to {@link ServerManagedObjectDeleteListener} callbacks.
 * An adaptor class which converts {@link ConfigDeleteListener} callbacks to
 * {@link ServerManagedObjectDeleteListener} callbacks.
 *
 * @param <S>
 *          The type of server configuration handled by the delete
 *          listener.
 *            The type of server configuration handled by the delete listener.
 */
final class ConfigDeleteListenerAdaptor<S extends Configuration> extends
    AbstractConfigListenerAdaptor implements ConfigDeleteListener {
final class ConfigDeleteListenerAdaptor<S extends Configuration> extends AbstractConfigListenerAdaptor implements
        ConfigDeleteListener {
  /**
   * The tracer object for the debug logger.
   */
  private static final DebugTracer TRACER = getTracer();
    private static final Logger debugLogger = LoggerFactory.getLogger(ConfigDeleteListenerAdaptor.class);
  // Cached managed object between accept/apply callbacks.
  private ServerManagedObject<? extends S> cachedManagedObject;
@@ -92,11 +82,9 @@
  // The managed object path of the parent.
  private final ManagedObjectPath<?, ?> path;
  /**
   * Create a new configuration delete listener adaptor for an
   * instantiable relation.
     * Create a new configuration delete listener adaptor for an instantiable
     * relation.
   *
   * @param path
   *          The managed object path of the parent.
@@ -105,8 +93,7 @@
   * @param listener
   *          The underlying delete listener.
   */
  public ConfigDeleteListenerAdaptor(ManagedObjectPath<?, ?> path,
      InstantiableRelationDefinition<?, S> relation,
    public ConfigDeleteListenerAdaptor(ManagedObjectPath<?, ?> path, InstantiableRelationDefinition<?, S> relation,
      ServerManagedObjectDeleteListener<S> listener) {
    this.path = path;
    this.optionalRelation = null;
@@ -116,11 +103,9 @@
    this.cachedManagedObject = null;
  }
  /**
   * Create a new configuration delete listener adaptor for an
   * optional relation.
     * Create a new configuration delete listener adaptor for an optional
     * relation.
   *
   * @param path
   *          The managed object path of the parent.
@@ -129,8 +114,7 @@
   * @param listener
   *          The underlying delete listener.
   */
  public ConfigDeleteListenerAdaptor(ManagedObjectPath<?, ?> path,
      OptionalRelationDefinition<?, S> relation,
    public ConfigDeleteListenerAdaptor(ManagedObjectPath<?, ?> path, OptionalRelationDefinition<?, S> relation,
      ServerManagedObjectDeleteListener<S> listener) {
    this.path = path;
    this.optionalRelation = relation;
@@ -140,11 +124,8 @@
    this.cachedManagedObject = null;
  }
  /**
   * Create a new configuration delete listener adaptor for an
   * set relation.
     * Create a new configuration delete listener adaptor for an set relation.
   *
   * @param path
   *          The managed object path of the parent.
@@ -153,8 +134,7 @@
   * @param listener
   *          The underlying delete listener.
   */
  public ConfigDeleteListenerAdaptor(ManagedObjectPath<?, ?> path,
      SetRelationDefinition<?, S> relation,
    public ConfigDeleteListenerAdaptor(ManagedObjectPath<?, ?> path, SetRelationDefinition<?, S> relation,
      ServerManagedObjectDeleteListener<S> listener) {
    this.path = path;
    this.optionalRelation = null;
@@ -164,8 +144,6 @@
    this.cachedManagedObject = null;
  }
  /**
   * {@inheritDoc}
   */
@@ -184,22 +162,17 @@
    // Cached objects are guaranteed to be from previous acceptable
    // callback.
    ConfigChangeResult result = listener
        .applyConfigurationDelete(cachedManagedObject);
        ConfigChangeResult result = listener.applyConfigurationDelete(cachedManagedObject);
    // Now apply post constraint call-backs.
    if (result.getResultCode() == ResultCode.SUCCESS) {
      ManagedObjectDefinition<?, ?> d = cachedManagedObject
          .getManagedObjectDefinition();
            ManagedObjectDefinition<?, ?> d = cachedManagedObject.getManagedObjectDefinition();
      for (Constraint constraint : d.getAllConstraints()) {
        for (ServerConstraintHandler handler : constraint
            .getServerConstraintHandlers()) {
                for (ServerConstraintHandler handler : constraint.getServerConstraintHandlers()) {
          try {
            handler.performPostDelete(cachedManagedObject);
          } catch (ConfigException e) {
            if (debugEnabled()) {
              TRACER.debugCaught(DebugLogLevel.ERROR, e);
            }
                        debugLogger.trace("Unable to perform post delete", e);
          }
        }
      }
@@ -208,15 +181,12 @@
    return result;
  }
  /**
   * {@inheritDoc}
   */
  public boolean configDeleteIsAcceptable(ConfigEntry configEntry,
      LocalizableMessageBuilder unacceptableReason) {
    public boolean configDeleteIsAcceptable(ConfigEntry configEntry, LocalizableMessageBuilder unacceptableReason) {
    DN dn = configEntry.getDN();
    AttributeValue av = dn.getRDN().getAttributeValue(0);
        AttributeValue av = dn.rdn().getAttributeValue(0);
    String name = av.getValue().toString().trim();
    try {
@@ -227,8 +197,8 @@
        try {
          childPath = path.child(setRelation, name);
        } catch (IllegalArgumentException e) {
          throw new DefinitionDecodingException(setRelation
              .getChildDefinition(), Reason.WRONG_TYPE_INFORMATION);
                    throw new DefinitionDecodingException(setRelation.getChildDefinition(),
                            Reason.WRONG_TYPE_INFORMATION);
        }
      } else {
        // Optional managed objects are located directly beneath the
@@ -249,22 +219,19 @@
      return false;
    }
    List<LocalizableMessage> reasons = new LinkedList<Message>();
        List<LocalizableMessage> reasons = new LinkedList<LocalizableMessage>();
    // Enforce any constraints.
    boolean isDeleteAllowed = true;
    ManagedObjectDefinition<?, ?> d = cachedManagedObject
        .getManagedObjectDefinition();
        ManagedObjectDefinition<?, ?> d = cachedManagedObject.getManagedObjectDefinition();
    for (Constraint constraint : d.getAllConstraints()) {
      for (ServerConstraintHandler handler : constraint
          .getServerConstraintHandlers()) {
            for (ServerConstraintHandler handler : constraint.getServerConstraintHandlers()) {
        try {
          if (!handler.isDeleteAllowed(cachedManagedObject, reasons)) {
            isDeleteAllowed = false;
          }
        } catch (ConfigException e) {
          LocalizableMessage message = ERR_SERVER_CONSTRAINT_EXCEPTION.get(e
              .getMessageObject());
                    LocalizableMessage message = ERR_SERVER_CONSTRAINT_EXCEPTION.get(e.getMessageObject());
          reasons.add(message);
          isDeleteAllowed = false;
        }
@@ -278,8 +245,7 @@
    }
    // Let the delete listener decide.
    if (listener.isConfigurationDeleteAcceptable(cachedManagedObject,
        reasons)) {
        if (listener.isConfigurationDeleteAcceptable(cachedManagedObject, reasons)) {
      return true;
    } else {
      generateUnacceptableReason(reasons, unacceptableReason);
@@ -287,14 +253,12 @@
    }
  }
  /**
   * Get the server managed object delete listener associated with
   * this adaptor.
     * Get the server managed object delete listener associated with this
     * adaptor.
   *
   * @return Returns the server managed object delete listener
   *         associated with this adaptor.
     * @return Returns the server managed object delete listener associated with
     *         this adaptor.
   */
  ServerManagedObjectDeleteListener<S> getServerManagedObjectDeleteListener() {
    return listener;
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigExceptionFactory.java
@@ -25,37 +25,32 @@
 *      Copyright 2008 Sun Microsystems, Inc.
 */
package org.opends.server.admin.server;
import org.forgerock.i18n.LocalizableMessage;
import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
import static com.forgerock.opendj.util.StaticUtils.*;
import org.opends.server.admin.DefinitionDecodingException;
import org.opends.server.config.ConfigException;
import org.opends.messages.AdminMessages;
import org.opends.server.util.DynamicConstants;
import com.forgerock.opendj.ldap.AdminMessages;
import org.forgerock.opendj.ldap.DN;
/**
 * A utility class for converting admin exceptions to config exceptions.
 */
final class ConfigExceptionFactory {
  // The singleton instance.
  private static final ConfigExceptionFactory INSTANCE =
    new ConfigExceptionFactory();
    private static final ConfigExceptionFactory INSTANCE = new ConfigExceptionFactory();
  // Prevent instantiation.
  private ConfigExceptionFactory() {
    // Do nothing.
  }
  /**
   * Get the configuration exception factory instance.
   *
@@ -65,8 +60,6 @@
    return INSTANCE;
  }
  /**
   * Create a configuration exception from a definition decoding exception.
   *
@@ -76,15 +69,12 @@
   *          The definition decoding exception
   * @return Returns the configuration exception.
   */
  public ConfigException createDecodingExceptionAdaptor(DN dn,
      DefinitionDecodingException e) {
    LocalizableMessage message = AdminMessages.ERR_ADMIN_MANAGED_OBJECT_DECODING_PROBLEM.
        get(String.valueOf(dn), stackTraceToSingleLineString(e));
    public ConfigException createDecodingExceptionAdaptor(DN dn, DefinitionDecodingException e) {
        LocalizableMessage message = AdminMessages.ERR_ADMIN_MANAGED_OBJECT_DECODING_PROBLEM.get(String.valueOf(dn),
                stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD));
    return new ConfigException(message, e);
  }
  /**
   * Create a configuration exception from a server managed object decoding
   * exception.
@@ -94,36 +84,28 @@
   * @return Returns the configuration exception.
   */
  public ConfigException createDecodingExceptionAdaptor(
      ServerManagedObjectDecodingException e) {
    public ConfigException createDecodingExceptionAdaptor(ServerManagedObjectDecodingException e) {
    DN dn = e.getPartialManagedObject().getDN();
    LocalizableMessage message =
            AdminMessages.ERR_ADMIN_MANAGED_OBJECT_DECODING_PROBLEM.get(
                    String.valueOf(dn),
        stackTraceToSingleLineString(e));
        LocalizableMessage message = AdminMessages.ERR_ADMIN_MANAGED_OBJECT_DECODING_PROBLEM.get(String.valueOf(dn),
                stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD));
    return new ConfigException(message, e);
  }
  /**
   * Create a configuration exception from a constraints violation
   * decoding exception.
     * Create a configuration exception from a constraints violation decoding
     * exception.
   *
   * @param e
   *          The constraints violation decoding exception.
   * @return Returns the configuration exception.
   */
  public ConfigException createDecodingExceptionAdaptor(
      ConstraintViolationException e) {
    public ConfigException createDecodingExceptionAdaptor(ConstraintViolationException e) {
    DN dn = e.getManagedObject().getDN();
    LocalizableMessage message = AdminMessages.ERR_ADMIN_MANAGED_OBJECT_DECODING_PROBLEM
        .get(String.valueOf(dn), stackTraceToSingleLineString(e));
        LocalizableMessage message = AdminMessages.ERR_ADMIN_MANAGED_OBJECT_DECODING_PROBLEM.get(String.valueOf(dn),
                stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD));
    return new ConfigException(message, e);
  }
  /**
   * Create an exception that describes a problem that occurred when
   * attempting to load and instantiate a class.
@@ -138,11 +120,9 @@
   * @return Returns the configuration exception.
   */
  public ConfigException createClassLoadingExceptionAdaptor(DN dn,
      String className, Exception e) {
    LocalizableMessage message = AdminMessages.ERR_ADMIN_CANNOT_INSTANTIATE_CLASS.
        get(String.valueOf(className), String.valueOf(dn),
            stackTraceToSingleLineString(e));
    public ConfigException createClassLoadingExceptionAdaptor(DN dn, String className, Exception e) {
        LocalizableMessage message = AdminMessages.ERR_ADMIN_CANNOT_INSTANTIATE_CLASS.get(String.valueOf(className),
                String.valueOf(dn), stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD));
    return new ConfigException(message, e);
  }
}
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigurationChangeListener.java
@@ -25,45 +25,38 @@
 *      Copyright 2007-2008 Sun Microsystems, Inc.
 */
package org.opends.server.admin.server;
import org.forgerock.i18n.LocalizableMessage;
import java.util.List;
import org.opends.server.admin.Configuration;
import org.opends.server.types.ConfigChangeResult;
/**
 * This interface defines the methods that a Directory Server
 * configurable component should implement if it wishes to be able to
 * receive notifications when a its associated configuration is
 * changed.
 * This interface defines the methods that a Directory Server configurable
 * component should implement if it wishes to be able to receive notifications
 * when a its associated configuration is changed.
 *
 * @param <T>
 *          The type of configuration that this listener should be
 *          notified about.
 *            The type of configuration that this listener should be notified
 *            about.
 */
public interface ConfigurationChangeListener<T extends Configuration> {
  /**
   * Indicates whether the proposed change to the configuration is
   * acceptable to this change listener.
     * Indicates whether the proposed change to the configuration is acceptable
     * to this change listener.
   *
   * @param configuration
   *          The new configuration containing the changes.
   * @param unacceptableReasons
   *          A list that can be used to hold messages about why the
   *          provided configuration is not acceptable.
   * @return Returns <code>true</code> if the proposed change is
   *         acceptable, or <code>false</code> if it is not.
     * @return Returns <code>true</code> if the proposed change is acceptable,
     *         or <code>false</code> if it is not.
   */
  public boolean isConfigurationChangeAcceptable(T configuration,
      List<LocalizableMessage> unacceptableReasons);
    public boolean isConfigurationChangeAcceptable(T configuration, List<LocalizableMessage> unacceptableReasons);
  /**
   * Applies the configuration changes to this change listener.
opendj-admin/src/main/java/org/opends/server/admin/server/ConfigurationDeleteListener.java
@@ -25,44 +25,38 @@
 *      Copyright 2007-2008 Sun Microsystems, Inc.
 */
package org.opends.server.admin.server;
import org.forgerock.i18n.LocalizableMessage;
import java.util.List;
import org.opends.server.admin.Configuration;
import org.opends.server.types.ConfigChangeResult;
/**
 * This interface defines the methods that a Directory Server
 * configurable component should implement if it wishes to be able to
 * receive notifications when an existing configuration is deleted.
 * This interface defines the methods that a Directory Server configurable
 * component should implement if it wishes to be able to receive notifications
 * when an existing configuration is deleted.
 *
 * @param <T>
 *          The type of configuration that this listener should be
 *          notified about.
 *            The type of configuration that this listener should be notified
 *            about.
 */
public interface ConfigurationDeleteListener<T extends Configuration> {
  /**
   * Indicates whether the proposed deletion of an existing
   * configuration is acceptable to this delete listener.
     * Indicates whether the proposed deletion of an existing configuration is
     * acceptable to this delete listener.
   *
   * @param configuration
   *          The configuration that will be deleted.
   * @param unacceptableReasons
   *          A list that can be used to hold messages about why the
   *          provided configuration is not acceptable.
   * @return Returns <code>true</code> if the proposed deletion is
   *         acceptable, or <code>false</code> if it is not.
     * @return Returns <code>true</code> if the proposed deletion is acceptable,
     *         or <code>false</code> if it is not.
   */
  public boolean isConfigurationDeleteAcceptable(T configuration,
      List<LocalizableMessage> unacceptableReasons);
    public boolean isConfigurationDeleteAcceptable(T configuration, List<LocalizableMessage> unacceptableReasons);
  /**
   * Deletes an existing configuration from this delete listener.
opendj-admin/src/main/java/org/opends/server/admin/server/ConstraintViolationException.java
@@ -24,12 +24,10 @@
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 */
package org.opends.server.admin.server;
import static com.forgerock.opendj.ldap.AdminMessages.*;
import static com.forgerock.opendj.util.Validator.*;
import java.util.ArrayList;
import java.util.Collection;
@@ -38,14 +36,10 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.opends.server.admin.DecodingException;
import static com.forgerock.opendj.util.Validator.*;
/**
 * This exception is thrown when the server refuses to use or delete a
 * managed object due to one or more constraints that cannot be
 * satisfied.
 * This exception is thrown when the server refuses to use or delete a managed
 * object due to one or more constraints that cannot be satisfied.
 */
public class ConstraintViolationException extends DecodingException {
@@ -57,30 +51,24 @@
  // The server managed object.
  private final ServerManagedObject<?> managedObject;
  // Gets the default message.
  private static LocalizableMessage getDefaultMessage(Collection<Message> messages) {
    Validator.ensureNotNull(messages);
    Validator.ensureTrue(!messages.isEmpty());
    private static LocalizableMessage getDefaultMessage(Collection<LocalizableMessage> messages) {
        ensureNotNull(messages);
        ensureTrue(!messages.isEmpty(), "messages should not be empty");
    if (messages.size() == 1) {
      return ERR_CONSTRAINT_VIOLATION_EXCEPTION_SINGLE.get(messages.iterator()
          .next());
            return ERR_CONSTRAINT_VIOLATION_EXCEPTION_SINGLE.get(messages.iterator().next());
    } else {
      return ERR_CONSTRAINT_VIOLATION_EXCEPTION_PLURAL
          .get(getSingleMessage(messages));
            return ERR_CONSTRAINT_VIOLATION_EXCEPTION_PLURAL.get(getSingleMessage(messages));
    }
  }
  // Merge the messages into a single message.
  private static LocalizableMessage getSingleMessage(Collection<Message> messages) {
    private static LocalizableMessage getSingleMessage(Collection<LocalizableMessage> messages) {
    if (messages.size() == 1) {
      return messages.iterator().next();
    } else {
      LocalizableMessageBuilder builder = new MessageBuilder();
            LocalizableMessageBuilder builder = new LocalizableMessageBuilder();
      boolean isFirst = true;
      for (LocalizableMessage m : messages) {
@@ -98,51 +86,39 @@
  // The messages describing the constraint violations that occurred.
  private final Collection<LocalizableMessage> messages;
  /**
   * Creates a new constraint violation exception with the provided
   * messages.
     * Creates a new constraint violation exception with the provided messages.
   *
   * @param managedObject
   *          The server managed object which caused the constraint
   *          violations.
   * @param messages
   *          The messages describing the constraint violations that
   *          occurred (must be non-<code>null</code> and
   *          non-empty).
     *            occurred (must be non-<code>null</code> and non-empty).
   */
  public ConstraintViolationException(ServerManagedObject<?> managedObject,
      Collection<LocalizableMessage> messages) {
    public ConstraintViolationException(ServerManagedObject<?> managedObject, Collection<LocalizableMessage> messages) {
    super(getDefaultMessage(messages));
    this.managedObject = managedObject;
    this.messages = new ArrayList<LocalizableMessage>(messages);
  }
  /**
   * Creates a new constraint violation exception with the provided
   * message.
     * Creates a new constraint violation exception with the provided message.
   *
   * @param managedObject
   *          The server managed object which caused the constraint
   *          violations.
   * @param message
   *          The message describing the constraint violation that
   *          occurred.
     *            The message describing the constraint violation that occurred.
   */
  public ConstraintViolationException(ServerManagedObject<?> managedObject,
      LocalizableMessage message) {
    public ConstraintViolationException(ServerManagedObject<?> managedObject, LocalizableMessage message) {
    this(managedObject, Collections.singleton(message));
  }
  /**
   * Gets an unmodifiable collection view of the messages describing
   * the constraint violations that occurred.
     * Gets an unmodifiable collection view of the messages describing the
     * constraint violations that occurred.
   *
   * @return Returns an unmodifiable collection view of the messages
   *         describing the constraint violations that occurred.
@@ -151,27 +127,22 @@
    return Collections.unmodifiableCollection(messages);
  }
  /**
   * Creates a single message listing all the messages combined into a
   * single list separated by semi-colons.
     * Creates a single message listing all the messages combined into a single
     * list separated by semi-colons.
   *
   * @return Returns a single message listing all the messages
   *         combined into a single list separated by semi-colons.
     * @return Returns a single message listing all the messages combined into a
     *         single list separated by semi-colons.
   */
  public LocalizableMessage getMessagesAsSingleMessage() {
    return getSingleMessage(messages);
  }
  /**
   * Gets the server managed object which caused the constraint
   * violations.
     * Gets the server managed object which caused the constraint violations.
   *
   * @return Returns the server managed object which caused the
   *         constraint violations.
     * @return Returns the server managed object which caused the constraint
     *         violations.
   */
  public ServerManagedObject<?> getManagedObject() {
    return managedObject;
opendj-admin/src/main/java/org/opends/server/admin/server/DNBuilder.java
@@ -27,19 +27,13 @@
package org.opends.server.admin.server;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.admin.LDAPProfile;
import org.opends.server.admin.ManagedObjectPath;
import org.opends.server.admin.RelationDefinition;
import org.opends.server.types.DirectoryException;
/**
 * A factory class for creating <code>DN</code>s from managed
 * object paths.
 * A factory class for creating <code>DN</code>s from managed object paths.
 */
final class DNBuilder {
@@ -48,40 +42,29 @@
   *
   * @param path
   *          The managed object path.
   * @return Returns a new DN representing the specified managed
   *         object path.
     * @return Returns a new DN representing the specified managed object path.
   */
  public static DN create(ManagedObjectPath<?, ?> path) {
    return path.toDN();
  }
  /**
   * Creates a new DN representing the specified managed object path
   * and relation.
     * Creates a new DN representing the specified managed object path and
     * relation.
   *
   * @param path
   *          The managed object path.
   * @param relation
   *          The child relation.
   * @return Returns a new DN representing the specified managed
   *         object path and relation.
     * @return Returns a new DN representing the specified managed object path
     *         and relation.
   */
  public static DN create(ManagedObjectPath<?, ?> path,
      RelationDefinition<?, ?> relation) {
    public static DN create(ManagedObjectPath<?, ?> path, RelationDefinition<?, ?> relation) {
    DN dn = path.toDN();
    try {
      LDAPProfile profile = LDAPProfile.getInstance();
      DN localName = DN.decode(profile.getRelationRDNSequence(relation));
      return dn.concat(localName);
    } catch (DirectoryException e) {
      throw new RuntimeException(e);
        DN localName = DN.valueOf(profile.getRelationRDNSequence(relation));
        return dn.child(localName);
    }
  }
  // Prevent instantiation.
  private DNBuilder() {
opendj-admin/src/main/java/org/opends/server/admin/server/DelayedConfigAddListener.java
@@ -26,35 +26,25 @@
 */
package org.opends.server.admin.server;
import static org.opends.server.loggers.debug.DebugLogger.*;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.api.ConfigAddListener;
import org.opends.server.api.ConfigDeleteListener;
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.ConfigChangeResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DebugLogLevel;
import org.opends.server.types.ResultCode;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.i18n.LocalizableMessageBuilder;
/**
 * A configuration add listener which will monitor a parent entry to
 * see when a specified child entry has been added. When the child
 * entry is added the add listener will automatically register its
 * "delayed" add or delete listener.
 * A configuration add listener which will monitor a parent entry to see when a
 * specified child entry has been added. When the child entry is added the add
 * listener will automatically register its "delayed" add or delete listener.
 */
final class DelayedConfigAddListener implements ConfigAddListener {
  /**
   * The tracer object for the debug logger.
   */
  private static final DebugTracer TRACER = getTracer();
    private static final Logger debugLogger = LoggerFactory.getLogger(DelayedConfigAddListener.class);
  // The name of the parent entry.
  private final DN parent;
@@ -72,49 +62,42 @@
  // registered).
  private final ConfigDeleteListener delayedDeleteListener;
  /**
   * Create a new delayed add listener which will register an add
   * listener with the specified entry when it is added.
     * Create a new delayed add listener which will register an add listener
     * with the specified entry when it is added.
   *
   * @param child
   *          The name of the subordinate entry which should have an
   *          add listener registered with it when it is created.
     *            The name of the subordinate entry which should have an add
     *            listener registered with it when it is created.
   * @param addListener
   *          The add listener to be added to the subordinate entry
   *          when it is added.
     *            The add listener to be added to the subordinate entry when it
     *            is added.
   */
  public DelayedConfigAddListener(DN child, ConfigAddListener addListener) {
    this.parent = child.getParent();
        this.parent = child.parent();
    this.child = child;
    this.delayedAddListener = addListener;
    this.delayedDeleteListener = null;
  }
  /**
   * Create a new delayed add listener which will register a delete
   * listener with the specified entry when it is added.
     * Create a new delayed add listener which will register a delete listener
     * with the specified entry when it is added.
   *
   * @param child
   *          The name of the subordinate entry which should have a
   *          delete listener registered with it when it is created.
     *            The name of the subordinate entry which should have a delete
     *            listener registered with it when it is created.
   * @param deleteListener
   *          The delete listener to be added to the subordinate entry
   *          when it is added.
     *            The delete listener to be added to the subordinate entry when
     *            it is added.
   */
  public DelayedConfigAddListener(DN child,
      ConfigDeleteListener deleteListener) {
    this.parent = child.getParent();
    public DelayedConfigAddListener(DN child, ConfigDeleteListener deleteListener) {
        this.parent = child.parent();
    this.child = child;
    this.delayedAddListener = null;
    this.delayedDeleteListener = deleteListener;
  }
  /**
   * {@inheritDoc}
   */
@@ -137,10 +120,7 @@
          myEntry.deregisterAddListener(this);
        }
      } catch (ConfigException e) {
        if (debugEnabled()) {
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }
                debugLogger.trace("Unable to deregister add listener", e);
        // Ignore this error as it implies that this listener has
        // already been deregistered.
      }
@@ -149,40 +129,33 @@
    return new ConfigChangeResult(ResultCode.SUCCESS, false);
  }
  /**
   * {@inheritDoc}
   */
  public boolean configAddIsAcceptable(ConfigEntry configEntry,
      LocalizableMessageBuilder unacceptableReason) {
    public boolean configAddIsAcceptable(ConfigEntry configEntry, LocalizableMessageBuilder unacceptableReason) {
    // Always acceptable.
    return true;
  }
  /**
   * Gets the delayed add listener.
   * <p>
   * This method is provided for unit-testing.
   *
   * @return Returns the delayed add listener, or <code>null</code>
   *         if this listener is delaying a delete listener.
     * @return Returns the delayed add listener, or <code>null</code> if this
     *         listener is delaying a delete listener.
   */
  ConfigAddListener getDelayedAddListener() {
    return delayedAddListener;
  }
  /**
   * Gets the delayed delete listener.
   * <p>
   * This method is provided for unit-testing.
   *
   * @return Returns the delayed delete listener, or <code>null</code>
   *         if this listener is delaying a add listener.
     * @return Returns the delayed delete listener, or <code>null</code> if this
     *         listener is delaying a add listener.
   */
  ConfigDeleteListener getDelayedDeleteListener() {
    return delayedDeleteListener;
opendj-admin/src/main/java/org/opends/server/admin/server/ServerConstraintHandler.java
@@ -26,32 +26,26 @@
 */
package org.opends.server.admin.server;
import java.util.Collection;
import org.forgerock.i18n.LocalizableMessage;
import org.opends.server.config.ConfigException;
/**
 * An interface for performing server-side constraint validation.
 * <p>
 * Constraints are evaluated immediately before and after write
 * operations are performed. Server-side constraints are evaluated in
 * two phases: the first phase determines if the proposed add, delete,
 * or modification is acceptable according to the constraint. If one
 * or more constraints fails, the write write operation is refused,
 * and the client will receive an
 * <code>OperationRejectedException</code> exception. The second
 * phase is invoked once the add, delete, or modification request has
 * been allowed and any changes applied. The second phase gives the
 * constraint handler a chance to register listener call-backs if
 * required.
 * Constraints are evaluated immediately before and after write operations are
 * performed. Server-side constraints are evaluated in two phases: the first
 * phase determines if the proposed add, delete, or modification is acceptable
 * according to the constraint. If one or more constraints fails, the write
 * write operation is refused, and the client will receive an
 * <code>OperationRejectedException</code> exception. The second phase is
 * invoked once the add, delete, or modification request has been allowed and
 * any changes applied. The second phase gives the constraint handler a chance
 * to register listener call-backs if required.
 * <p>
 * A server constraint handler must override at least one of the
 * provided methods.
 * A server constraint handler must override at least one of the provided
 * methods.
 *
 * @see org.opends.server.admin.Constraint
 */
@@ -64,130 +58,114 @@
    // No implementation required.
  }
  /**
   * Determines whether or not the existing managed object can be
   * deleted from the server's configuration. For example, an
   * implementation might enforce referential integrity by preventing
   * referenced managed objects from being deleted.
     * Determines whether or not the existing managed object can be deleted from
     * the server's configuration. For example, an implementation might enforce
     * referential integrity by preventing referenced managed objects from being
     * deleted.
   * <p>
   * If the constraint is not satisfied, the implementation must
   * return <code>false</code> and add a message describing why the
   * managed object cannot be deleted.
     * If the constraint is not satisfied, the implementation must return
     * <code>false</code> and add a message describing why the managed object
     * cannot be deleted.
   * <p>
   * The default implementation is to return <code>true</code>.
   *
   * @param managedObject
   *          The managed object which is about to be deleted.
   * @param unacceptableReasons
   *          A list of messages to which error messages should be
   *          added.
   * @return Returns <code>true</code> if this constraint is
   *         satisfied, or <code>false</code> if it is not and the
   *         managed object cannot be deleted.
     *            A list of messages to which error messages should be added.
     * @return Returns <code>true</code> if this constraint is satisfied, or
     *         <code>false</code> if it is not and the managed object cannot be
     *         deleted.
   * @throws ConfigException
   *           If an configuration exception prevented this constraint
   *           from being evaluated.
     *             If an configuration exception prevented this constraint from
     *             being evaluated.
   */
  public boolean isDeleteAllowed(ServerManagedObject<?> managedObject,
      Collection<LocalizableMessage> unacceptableReasons) throws ConfigException {
    return true;
  }
  /**
   * Determines whether or not the provided managed object can be used
   * by the server. This method is invoked each time a managed object
   * is decoded by the administration framework: when an attempt is
   * made to add a new configuration, modify an existing
   * configuration, or during server initialization. If the constraint
   * is not satisfied the managed object will be rejected.
     * Determines whether or not the provided managed object can be used by the
     * server. This method is invoked each time a managed object is decoded by
     * the administration framework: when an attempt is made to add a new
     * configuration, modify an existing configuration, or during server
     * initialization. If the constraint is not satisfied the managed object
     * will be rejected.
   * <p>
   * If the constraint is not satisfied, the implementation must
   * return <code>false</code> and add a message describing why the
   * managed object is not usable.
     * If the constraint is not satisfied, the implementation must return
     * <code>false</code> and add a message describing why the managed object is
     * not usable.
   * <p>
   * The default implementation is to return <code>true</code>.
   *
   * @param managedObject
   *          The new managed object.
   * @param unacceptableReasons
   *          A list of messages to which error messages should be
   *          added.
   * @return Returns <code>true</code> if this constraint is
   *         satisfied, or <code>false</code> if it is not and the
   *         managed object cannot be used.
     *            A list of messages to which error messages should be added.
     * @return Returns <code>true</code> if this constraint is satisfied, or
     *         <code>false</code> if it is not and the managed object cannot be
     *         used.
   * @throws ConfigException
   *           If an configuration exception prevented this constraint
   *           from being evaluated.
     *             If an configuration exception prevented this constraint from
     *             being evaluated.
   */
  public boolean isUsable(ServerManagedObject<?> managedObject,
      Collection<LocalizableMessage> unacceptableReasons) throws ConfigException {
    public boolean isUsable(ServerManagedObject<?> managedObject, Collection<LocalizableMessage> unacceptableReasons)
            throws ConfigException {
    return true;
  }
  /**
   * Performs any post-add processing required by this constraint.
   * This method is invoked after a new managed object has been
   * accepted for use by the administration framework. This might
   * occur during initialization or when a managed object is added at
   * run-time.
     * Performs any post-add processing required by this constraint. This method
     * is invoked after a new managed object has been accepted for use by the
     * administration framework. This might occur during initialization or when
     * a managed object is added at run-time.
   * <p>
   * The default implementation is to do nothing.
   *
   * @param managedObject
   *          The managed object which has just been added to the
   *          server's configuration.
     *            The managed object which has just been added to the server's
     *            configuration.
   * @throws ConfigException
   *           If the post-add processing fails due to a configuration
   *           exception.
   */
  public void performPostAdd(ServerManagedObject<?> managedObject)
      throws ConfigException {
    public void performPostAdd(ServerManagedObject<?> managedObject) throws ConfigException {
    // Do nothing.
  }
  /**
   * Performs any post-delete processing required by this constraint.
   * This method is invoked after a managed object has been accepted
   * for deletion from the server's configuration.
     * Performs any post-delete processing required by this constraint. This
     * method is invoked after a managed object has been accepted for deletion
     * from the server's configuration.
   * <p>
   * The default implementation is to do nothing.
   *
   * @param managedObject
   *          The managed object which was deleted.
   * @throws ConfigException
   *           If the post-delete processing fails due to a
   *           configuration exception.
     *             If the post-delete processing fails due to a configuration
     *             exception.
   */
  public void performPostDelete(ServerManagedObject<?> managedObject)
      throws ConfigException {
    public void performPostDelete(ServerManagedObject<?> managedObject) throws ConfigException {
    // Do nothing.
  }
  /**
   * Performs any post-modify processing required by this constraint.
   * This method is invoked after changes to an existing managed
   * object have been accepted.
     * Performs any post-modify processing required by this constraint. This
     * method is invoked after changes to an existing managed object have been
     * accepted.
   * <p>
   * The default implementation is to do nothing.
   *
   * @param managedObject
   *          The managed object which was modified.
   * @throws ConfigException
   *           If the post-modify processing fails due to a
   *           configuration exception.
     *             If the post-modify processing fails due to a configuration
     *             exception.
   */
  public void performPostModify(ServerManagedObject<?> managedObject)
      throws ConfigException {
    public void performPostModify(ServerManagedObject<?> managedObject) throws ConfigException {
    // Do nothing.
  }
}
opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagedObject.java
@@ -27,7 +27,8 @@
package org.opends.server.admin.server;
import static com.forgerock.opendj.ldap.AdminMessages.*;
import static com.forgerock.opendj.util.StaticUtils.*;
import java.util.Collections;
import java.util.LinkedList;
@@ -36,6 +37,7 @@
import java.util.Set;
import java.util.SortedSet;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.admin.Configuration;
import org.opends.server.admin.Constraint;
@@ -52,31 +54,27 @@
import org.opends.server.api.ConfigChangeListener;
import org.opends.server.api.ConfigDeleteListener;
import org.opends.server.config.ConfigException;
import org.opends.server.util.DynamicConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * A server-side managed object.
 *
 * @param <S>
 *          The type of server configuration represented by the server
 *          managed object.
 *            The type of server configuration represented by the server managed
 *            object.
 */
public final class ServerManagedObject<S extends Configuration> implements
    PropertyProvider {
public final class ServerManagedObject<S extends Configuration> implements PropertyProvider {
  /**
   * The tracer object for the debug logger.
   */
  private static final DebugTracer TRACER = getTracer();
    private static final Logger logger = LoggerFactory.getLogger(ServerManagedObject.class);
  // The configuration entry associated with this server managed
  // object (null if root).
  private ConfigEntry configEntry;
  // The management context.
  private final ServerManagementContext context = ServerManagementContext
      .getInstance();
    private final ServerManagementContext context = ServerManagementContext.getInstance();
  // The managed object's definition.
  private final ManagedObjectDefinition<?, S> definition;
@@ -88,8 +86,6 @@
  // The managed object's properties.
  private final Map<PropertyDefinition<?>, SortedSet<?>> properties;
  /**
   * Creates an new server side managed object.
   *
@@ -100,21 +96,16 @@
   * @param properties
   *          The managed object's properties.
   * @param configEntry
   *          The configuration entry associated with the managed
   *          object.
     *            The configuration entry associated with the managed object.
   */
  ServerManagedObject(ManagedObjectPath<?, S> path,
      ManagedObjectDefinition<?, S> d,
      Map<PropertyDefinition<?>, SortedSet<?>> properties,
      ConfigEntry configEntry) {
    ServerManagedObject(ManagedObjectPath<?, S> path, ManagedObjectDefinition<?, S> d,
            Map<PropertyDefinition<?>, SortedSet<?>> properties, ConfigEntry configEntry) {
    this.definition = d;
    this.path = path;
    this.properties = properties;
    this.configEntry = configEntry;
  }
  /**
   * Deregisters an existing configuration add listener.
   *
@@ -125,11 +116,10 @@
   * @param listener
   *          The configuration add listener.
   * @throws IllegalArgumentException
   *           If the instantiable relation definition is not
   *           associated with this managed object's definition.
     *             If the instantiable relation definition is not associated
     *             with this managed object's definition.
   */
  public <M extends Configuration> void deregisterAddListener(
      InstantiableRelationDefinition<?, M> d,
    public <M extends Configuration> void deregisterAddListener(InstantiableRelationDefinition<?, M> d,
      ConfigurationAddListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
@@ -137,8 +127,6 @@
    deregisterAddListener(baseDN, listener);
  }
  /**
   * Deregisters an existing server managed object add listener.
   *
@@ -149,21 +137,17 @@
   * @param listener
   *          The server managed object add listener.
   * @throws IllegalArgumentException
   *           If the instantiable relation definition is not
   *           associated with this managed object's definition.
     *             If the instantiable relation definition is not associated
     *             with this managed object's definition.
   */
  public <M extends Configuration> void deregisterAddListener(
      InstantiableRelationDefinition<?, M> d,
      ServerManagedObjectAddListener<M> listener)
      throws IllegalArgumentException {
    public <M extends Configuration> void deregisterAddListener(InstantiableRelationDefinition<?, M> d,
            ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d);
    deregisterAddListener(baseDN, listener);
  }
  /**
   * Deregisters an existing configuration add listener.
   *
@@ -174,20 +158,17 @@
   * @param listener
   *          The configuration add listener.
   * @throws IllegalArgumentException
   *           If the optional relation definition is not associated
   *           with this managed object's definition.
     *             If the optional relation definition is not associated with
     *             this managed object's definition.
   */
  public <M extends Configuration> void deregisterAddListener(
      OptionalRelationDefinition<?, M> d, ConfigurationAddListener<M> listener)
      throws IllegalArgumentException {
    public <M extends Configuration> void deregisterAddListener(OptionalRelationDefinition<?, M> d,
            ConfigurationAddListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d).getParent();
        DN baseDN = DNBuilder.create(path, d).parent();
    deregisterAddListener(baseDN, listener);
  }
  /**
   * Deregisters an existing server managed object add listener.
   *
@@ -198,21 +179,17 @@
   * @param listener
   *          The server managed object add listener.
   * @throws IllegalArgumentException
   *           If the optional relation definition is not associated
   *           with this managed object's definition.
     *             If the optional relation definition is not associated with
     *             this managed object's definition.
   */
  public <M extends Configuration> void deregisterAddListener(
      OptionalRelationDefinition<?, M> d,
      ServerManagedObjectAddListener<M> listener)
      throws IllegalArgumentException {
    public <M extends Configuration> void deregisterAddListener(OptionalRelationDefinition<?, M> d,
            ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d).getParent();
        DN baseDN = DNBuilder.create(path, d).parent();
    deregisterAddListener(baseDN, listener);
  }
  /**
   * Deregisters an existing configuration add listener.
   *
@@ -223,11 +200,10 @@
   * @param listener
   *          The configuration add listener.
   * @throws IllegalArgumentException
   *           If the set relation definition is not
   *           associated with this managed object's definition.
     *             If the set relation definition is not associated with this
     *             managed object's definition.
   */
  public <M extends Configuration> void deregisterAddListener(
      SetRelationDefinition<?, M> d,
    public <M extends Configuration> void deregisterAddListener(SetRelationDefinition<?, M> d,
      ConfigurationAddListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
@@ -235,8 +211,6 @@
    deregisterAddListener(baseDN, listener);
  }
  /**
   * Deregisters an existing server managed object add listener.
   *
@@ -247,35 +221,28 @@
   * @param listener
   *          The server managed object add listener.
   * @throws IllegalArgumentException
   *           If the set relation definition is not
   *           associated with this managed object's definition.
     *             If the set relation definition is not associated with this
     *             managed object's definition.
   */
  public <M extends Configuration> void deregisterAddListener(
      SetRelationDefinition<?, M> d,
      ServerManagedObjectAddListener<M> listener)
      throws IllegalArgumentException {
    public <M extends Configuration> void deregisterAddListener(SetRelationDefinition<?, M> d,
            ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d);
    deregisterAddListener(baseDN, listener);
  }
  /**
   * Deregisters an existing configuration change listener.
   *
   * @param listener
   *          The configuration change listener.
   */
  public void deregisterChangeListener(
      ConfigurationChangeListener<? super S> listener) {
    public void deregisterChangeListener(ConfigurationChangeListener<? super S> listener) {
    for (ConfigChangeListener l : configEntry.getChangeListeners()) {
      if (l instanceof ConfigChangeListenerAdaptor) {
        ConfigChangeListenerAdaptor<?> adaptor =
          (ConfigChangeListenerAdaptor<?>) l;
        ServerManagedObjectChangeListener<?> l2 = adaptor
            .getServerManagedObjectChangeListener();
                ConfigChangeListenerAdaptor<?> adaptor = (ConfigChangeListenerAdaptor<?>) l;
                ServerManagedObjectChangeListener<?> l2 = adaptor.getServerManagedObjectChangeListener();
        if (l2 instanceof ServerManagedObjectChangeListenerAdaptor<?>) {
          ServerManagedObjectChangeListenerAdaptor<?> adaptor2 =
            (ServerManagedObjectChangeListenerAdaptor<?>) l2;
@@ -288,20 +255,16 @@
    }
  }
  /**
   * Deregisters an existing server managed object change listener.
   *
   * @param listener
   *          The server managed object change listener.
   */
  public void deregisterChangeListener(
      ServerManagedObjectChangeListener<? super S> listener) {
    public void deregisterChangeListener(ServerManagedObjectChangeListener<? super S> listener) {
    for (ConfigChangeListener l : configEntry.getChangeListeners()) {
      if (l instanceof ConfigChangeListenerAdaptor) {
        ConfigChangeListenerAdaptor<?> adaptor =
          (ConfigChangeListenerAdaptor<?>) l;
                ConfigChangeListenerAdaptor<?> adaptor = (ConfigChangeListenerAdaptor<?>) l;
        if (adaptor.getServerManagedObjectChangeListener() == listener) {
          adaptor.finalizeChangeListener();
          configEntry.deregisterChangeListener(adaptor);
@@ -310,8 +273,6 @@
    }
  }
  /**
   * Deregisters an existing configuration delete listener.
   *
@@ -322,11 +283,10 @@
   * @param listener
   *          The configuration delete listener.
   * @throws IllegalArgumentException
   *           If the instantiable relation definition is not
   *           associated with this managed object's definition.
     *             If the instantiable relation definition is not associated
     *             with this managed object's definition.
   */
  public <M extends Configuration> void deregisterDeleteListener(
      InstantiableRelationDefinition<?, M> d,
    public <M extends Configuration> void deregisterDeleteListener(InstantiableRelationDefinition<?, M> d,
      ConfigurationDeleteListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
@@ -334,8 +294,6 @@
    deregisterDeleteListener(baseDN, listener);
  }
  /**
   * Deregisters an existing server managed object delete listener.
   *
@@ -346,21 +304,17 @@
   * @param listener
   *          The server managed object delete listener.
   * @throws IllegalArgumentException
   *           If the instantiable relation definition is not
   *           associated with this managed object's definition.
     *             If the instantiable relation definition is not associated
     *             with this managed object's definition.
   */
  public <M extends Configuration> void deregisterDeleteListener(
      InstantiableRelationDefinition<?, M> d,
      ServerManagedObjectDeleteListener<M> listener)
      throws IllegalArgumentException {
    public <M extends Configuration> void deregisterDeleteListener(InstantiableRelationDefinition<?, M> d,
            ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d);
    deregisterDeleteListener(baseDN, listener);
  }
  /**
   * Deregisters an existing configuration delete listener.
   *
@@ -371,20 +325,17 @@
   * @param listener
   *          The configuration delete listener.
   * @throws IllegalArgumentException
   *           If the optional relation definition is not associated
   *           with this managed object's definition.
     *             If the optional relation definition is not associated with
     *             this managed object's definition.
   */
  public <M extends Configuration> void deregisterDeleteListener(
      OptionalRelationDefinition<?, M> d,
    public <M extends Configuration> void deregisterDeleteListener(OptionalRelationDefinition<?, M> d,
      ConfigurationDeleteListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d).getParent();
        DN baseDN = DNBuilder.create(path, d).parent();
    deregisterDeleteListener(baseDN, listener);
  }
  /**
   * Deregisters an existing server managed object delete listener.
   *
@@ -395,21 +346,17 @@
   * @param listener
   *          The server managed object delete listener.
   * @throws IllegalArgumentException
   *           If the optional relation definition is not associated
   *           with this managed object's definition.
     *             If the optional relation definition is not associated with
     *             this managed object's definition.
   */
  public <M extends Configuration> void deregisterDeleteListener(
      OptionalRelationDefinition<?, M> d,
      ServerManagedObjectDeleteListener<M> listener)
      throws IllegalArgumentException {
    public <M extends Configuration> void deregisterDeleteListener(OptionalRelationDefinition<?, M> d,
            ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d).getParent();
        DN baseDN = DNBuilder.create(path, d).parent();
    deregisterDeleteListener(baseDN, listener);
  }
  /**
   * Deregisters an existing configuration delete listener.
   *
@@ -420,11 +367,10 @@
   * @param listener
   *          The configuration delete listener.
   * @throws IllegalArgumentException
   *           If the set relation definition is not
   *           associated with this managed object's definition.
     *             If the set relation definition is not associated with this
     *             managed object's definition.
   */
  public <M extends Configuration> void deregisterDeleteListener(
      SetRelationDefinition<?, M> d,
    public <M extends Configuration> void deregisterDeleteListener(SetRelationDefinition<?, M> d,
      ConfigurationDeleteListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
@@ -432,8 +378,6 @@
    deregisterDeleteListener(baseDN, listener);
  }
  /**
   * Deregisters an existing server managed object delete listener.
   *
@@ -444,21 +388,17 @@
   * @param listener
   *          The server managed object delete listener.
   * @throws IllegalArgumentException
   *           If the set relation definition is not
   *           associated with this managed object's definition.
     *             If the set relation definition is not associated with this
     *             managed object's definition.
   */
  public <M extends Configuration> void deregisterDeleteListener(
      SetRelationDefinition<?, M> d,
      ServerManagedObjectDeleteListener<M> listener)
      throws IllegalArgumentException {
    public <M extends Configuration> void deregisterDeleteListener(SetRelationDefinition<?, M> d,
            ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d);
    deregisterDeleteListener(baseDN, listener);
  }
  /**
   * Retrieve an instantiable child managed object.
   *
@@ -474,18 +414,15 @@
   *           If the relation definition is not associated with this
   *           managed object's definition.
   * @throws ConfigException
   *           If the child managed object could not be found or if it
   *           could not be decoded.
     *             If the child managed object could not be found or if it could
     *             not be decoded.
   */
  public <M extends Configuration> ServerManagedObject<? extends M> getChild(
      InstantiableRelationDefinition<?, M> d, String name)
      throws IllegalArgumentException, ConfigException {
    public <M extends Configuration> ServerManagedObject<? extends M> getChild(InstantiableRelationDefinition<?, M> d,
            String name) throws IllegalArgumentException, ConfigException {
    validateRelationDefinition(d);
    return context.getManagedObject(path.child(d, name));
  }
  /**
   * Retrieve an optional child managed object.
   *
@@ -496,21 +433,18 @@
   *          The optional relation definition.
   * @return Returns the optional child managed object.
   * @throws IllegalArgumentException
   *           If the optional relation definition is not associated
   *           with this managed object's definition.
     *             If the optional relation definition is not associated with
     *             this managed object's definition.
   * @throws ConfigException
   *           If the child managed object could not be found or if it
   *           could not be decoded.
     *             If the child managed object could not be found or if it could
     *             not be decoded.
   */
  public <M extends Configuration> ServerManagedObject<? extends M> getChild(
      OptionalRelationDefinition<?, M> d) throws IllegalArgumentException,
      ConfigException {
    public <M extends Configuration> ServerManagedObject<? extends M> getChild(OptionalRelationDefinition<?, M> d)
            throws IllegalArgumentException, ConfigException {
    validateRelationDefinition(d);
    return context.getManagedObject(path.child(d));
  }
  /**
   * Retrieve a set child managed object.
   *
@@ -524,24 +458,20 @@
   * @return Returns the set child managed object.
   * @throws IllegalArgumentException
   *           If the relation definition is not associated with this
   *           managed object's definition or if {@code name} specifies
   *           a managed object definition which is not a sub-type of
   *           the relation's child definition.
     *             managed object's definition or if {@code name} specifies a
     *             managed object definition which is not a sub-type of the
     *             relation's child definition.
   * @throws ConfigException
   *           If the child managed object could not be found or if it
   *           could not be decoded.
     *             If the child managed object could not be found or if it could
     *             not be decoded.
   */
  public <M extends Configuration> ServerManagedObject<? extends M> getChild(
      SetRelationDefinition<?, M> d, String name)
      throws IllegalArgumentException, ConfigException
  {
    public <M extends Configuration> ServerManagedObject<? extends M> getChild(SetRelationDefinition<?, M> d,
            String name) throws IllegalArgumentException, ConfigException {
    validateRelationDefinition(d);
    return context.getManagedObject(path.child(d, name));
  }
  /**
   * Retrieve a singleton child managed object.
   *
@@ -555,60 +485,48 @@
   *           If the relation definition is not associated with this
   *           managed object's definition.
   * @throws ConfigException
   *           If the child managed object could not be found or if it
   *           could not be decoded.
     *             If the child managed object could not be found or if it could
     *             not be decoded.
   */
  public <M extends Configuration> ServerManagedObject<? extends M> getChild(
      SingletonRelationDefinition<?, M> d) throws IllegalArgumentException,
      ConfigException {
    public <M extends Configuration> ServerManagedObject<? extends M> getChild(SingletonRelationDefinition<?, M> d)
            throws IllegalArgumentException, ConfigException {
    validateRelationDefinition(d);
    return context.getManagedObject(path.child(d));
  }
  /**
   * Creates a server configuration view of this managed object.
   *
   * @return Returns the server configuration view of this managed
   *         object.
     * @return Returns the server configuration view of this managed object.
   */
  public S getConfiguration() {
    return definition.createServerConfiguration(this);
  }
  /**
   * Get the DN of the LDAP entry associated with this server managed
   * object.
     * Get the DN of the LDAP entry associated with this server managed object.
   *
   * @return Returns the DN of the LDAP entry associated with this
   *         server managed object, or an null DN if this is the root
   *         managed object.
     * @return Returns the DN of the LDAP entry associated with this server
     *         managed object, or an null DN if this is the root managed object.
   */
  public DN getDN() {
    if (configEntry != null) {
      return configEntry.getDN();
    } else {
      return DN.nullDN();
            return DN.rootDN();
    }
  }
  /**
   * Get the definition associated with this server managed object.
   *
   * @return Returns the definition associated with this server
   *         managed object.
     * @return Returns the definition associated with this server managed
     *         object.
   */
  public ManagedObjectDefinition<?, S> getManagedObjectDefinition() {
    return definition;
  }
  /**
   * Get the path of this server managed object.
   *
@@ -618,28 +536,23 @@
    return path;
  }
  /**
   * Get the effective value of the specified property. If the
   * property is multi-valued then just the first value is returned.
   * If the property does not have a value then its default value is
   * returned if it has one, or <code>null</code> indicating that
   * any default behavior is applicable.
     * Get the effective value of the specified property. If the property is
     * multi-valued then just the first value is returned. If the property does
     * not have a value then its default value is returned if it has one, or
     * <code>null</code> indicating that any default behavior is applicable.
   *
   * @param <T>
   *          The type of the property to be retrieved.
   * @param d
   *          The property to be retrieved.
   * @return Returns the property's effective value, or
   *         <code>null</code> indicating that any default behavior
   *         is applicable.
     * @return Returns the property's effective value, or <code>null</code>
     *         indicating that any default behavior is applicable.
   * @throws IllegalArgumentException
   *           If the property definition is not associated with this
   *           managed object's definition.
   */
  public <T> T getPropertyValue(PropertyDefinition<T> d)
      throws IllegalArgumentException {
    public <T> T getPropertyValue(PropertyDefinition<T> d) throws IllegalArgumentException {
    Set<T> values = getPropertyValues(d);
    if (values.isEmpty()) {
      return null;
@@ -648,57 +561,47 @@
    }
  }
  /**
   * Get the effective values of the specified property. If the
   * property does not have any values then its default values are
   * returned if it has any, or an empty set indicating that any
   * default behavior is applicable.
     * Get the effective values of the specified property. If the property does
     * not have any values then its default values are returned if it has any,
     * or an empty set indicating that any default behavior is applicable.
   *
   * @param <T>
   *          The type of the property to be retrieved.
   * @param d
   *          The property to be retrieved.
   * @return Returns an unmodifiable set containing the property's
   *         effective values. An empty set indicates that the
   *         property has no default values defined and any default
   *         behavior is applicable.
     * @return Returns an unmodifiable set containing the property's effective
     *         values. An empty set indicates that the property has no default
     *         values defined and any default behavior is applicable.
   * @throws IllegalArgumentException
   *           If the property definition is not associated with this
   *           managed object's definition.
   */
  @SuppressWarnings("unchecked")
  public <T> SortedSet<T> getPropertyValues(PropertyDefinition<T> d)
      throws IllegalArgumentException {
    public <T> SortedSet<T> getPropertyValues(PropertyDefinition<T> d) throws IllegalArgumentException {
    if (!properties.containsKey(d)) {
      throw new IllegalArgumentException("Unknown property " + d.getName());
    }
    return Collections.unmodifiableSortedSet((SortedSet<T>) properties.get(d));
  }
  /**
   * Determines whether or not the optional managed object associated
   * with the specified optional relations exists.
     * Determines whether or not the optional managed object associated with the
     * specified optional relations exists.
   *
   * @param d
   *          The optional relation definition.
   * @return Returns <code>true</code> if the optional managed
   *         object exists, <code>false</code> otherwise.
     * @return Returns <code>true</code> if the optional managed object exists,
     *         <code>false</code> otherwise.
   * @throws IllegalArgumentException
   *           If the optional relation definition is not associated
   *           with this managed object's definition.
     *             If the optional relation definition is not associated with
     *             this managed object's definition.
   */
  public boolean hasChild(OptionalRelationDefinition<?, ?> d)
      throws IllegalArgumentException {
    public boolean hasChild(OptionalRelationDefinition<?, ?> d) throws IllegalArgumentException {
    validateRelationDefinition(d);
    return context.managedObjectExists(path.child(d));
  }
  /**
   * Lists the child managed objects associated with the specified
   * instantiable relation.
@@ -710,17 +613,14 @@
   *           If the relation definition is not associated with this
   *           managed object's definition.
   */
  public String[] listChildren(InstantiableRelationDefinition<?, ?> d)
      throws IllegalArgumentException {
    public String[] listChildren(InstantiableRelationDefinition<?, ?> d) throws IllegalArgumentException {
    validateRelationDefinition(d);
    return context.listManagedObjects(path, d);
  }
  /**
   * Lists the child managed objects associated with the specified
   * set relation.
     * Lists the child managed objects associated with the specified set
     * relation.
   *
   * @param d
   *          The set relation definition.
@@ -729,16 +629,35 @@
   *           If the relation definition is not associated with this
   *           managed object's definition.
   */
  public String[] listChildren(SetRelationDefinition<?, ?> d)
      throws IllegalArgumentException {
    public String[] listChildren(SetRelationDefinition<?, ?> d) throws IllegalArgumentException {
    validateRelationDefinition(d);
    return context.listManagedObjects(path, d);
  }
    /**
     * Register to be notified when new child configurations are added beneath
     * an instantiable relation.
     *
     * @param <M>
     *            The type of the child server configuration object.
     * @param d
     *            The instantiable relation definition.
     * @param listener
     *            The configuration add listener.
     * @throws IllegalArgumentException
     *             If the instantiable relation definition is not associated
     *             with this managed object's definition.
     * @throws ConfigException
     *             If the configuration entry associated with the instantiable
     *             relation could not be retrieved.
     */
    public <M extends Configuration> void registerAddListener(InstantiableRelationDefinition<?, M> d,
            ConfigurationAddListener<M> listener) throws IllegalArgumentException, ConfigException {
        registerAddListener(d, new ServerManagedObjectAddListenerAdaptor<M>(listener));
    }
  /**
   * Register to be notified when new child configurations are added
     * Register to be notified when new child server managed object are added
   * beneath an instantiable relation.
   *
   * @param <M>
@@ -746,56 +665,46 @@
   * @param d
   *          The instantiable relation definition.
   * @param listener
   *          The configuration add listener.
     *            The server managed object add listener.
   * @throws IllegalArgumentException
   *           If the instantiable relation definition is not
   *           associated with this managed object's definition.
     *             If the instantiable relation definition is not associated
     *             with this managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the
   *           instantiable relation could not be retrieved.
     *             If the configuration entry associated with the instantiable
     *             relation could not be retrieved.
   */
  public <M extends Configuration> void registerAddListener(
      InstantiableRelationDefinition<?, M> d,
      ConfigurationAddListener<M> listener) throws IllegalArgumentException,
      ConfigException {
    registerAddListener(d, new ServerManagedObjectAddListenerAdaptor<M>(
        listener));
    public <M extends Configuration> void registerAddListener(InstantiableRelationDefinition<?, M> d,
            ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException, ConfigException {
        validateRelationDefinition(d);
        DN baseDN = DNBuilder.create(path, d);
        ConfigAddListener adaptor = new ConfigAddListenerAdaptor<M>(path, d, listener);
        registerAddListener(baseDN, adaptor);
  }
  /**
   * Register to be notified when new child server managed object are
   * added beneath an instantiable relation.
     * Register to be notified when a new child configurations is added beneath
     * an optional relation.
   *
   * @param <M>
   *          The type of the child server configuration object.
   * @param d
   *          The instantiable relation definition.
     *            The optional relation definition.
   * @param listener
   *          The server managed object add listener.
     *            The configuration add listener.
   * @throws IllegalArgumentException
   *           If the instantiable relation definition is not
   *           associated with this managed object's definition.
     *             If the optional relation definition is not associated with
     *             this managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the
   *           instantiable relation could not be retrieved.
     *             If the configuration entry associated with the optional
     *             relation could not be retrieved.
   */
  public <M extends Configuration> void registerAddListener(
      InstantiableRelationDefinition<?, M> d,
      ServerManagedObjectAddListener<M> listener)
      throws IllegalArgumentException, ConfigException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d);
    ConfigAddListener adaptor = new ConfigAddListenerAdaptor<M>(path, d,
        listener);
    registerAddListener(baseDN, adaptor);
    public <M extends Configuration> void registerAddListener(OptionalRelationDefinition<?, M> d,
            ConfigurationAddListener<M> listener) throws IllegalArgumentException, ConfigException {
        registerAddListener(d, new ServerManagedObjectAddListenerAdaptor<M>(listener));
  }
  /**
   * Register to be notified when a new child configurations is added
     * Register to be notified when a new child server managed object is added
   * beneath an optional relation.
   *
   * @param <M>
@@ -803,55 +712,46 @@
   * @param d
   *          The optional relation definition.
   * @param listener
   *          The configuration add listener.
     *            The server managed object add listener.
   * @throws IllegalArgumentException
   *           If the optional relation definition is not associated
   *           with this managed object's definition.
     *             If the optional relation definition is not associated with
     *             this managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the optional
   *           relation could not be retrieved.
   */
  public <M extends Configuration> void registerAddListener(
      OptionalRelationDefinition<?, M> d, ConfigurationAddListener<M> listener)
      throws IllegalArgumentException, ConfigException {
    registerAddListener(d, new ServerManagedObjectAddListenerAdaptor<M>(
        listener));
    public <M extends Configuration> void registerAddListener(OptionalRelationDefinition<?, M> d,
            ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException, ConfigException {
        validateRelationDefinition(d);
        DN baseDN = DNBuilder.create(path, d).parent();
        ConfigAddListener adaptor = new ConfigAddListenerAdaptor<M>(path, d, listener);
        registerAddListener(baseDN, adaptor);
  }
  /**
   * Register to be notified when a new child server managed object is
   * added beneath an optional relation.
     * Register to be notified when new child configurations are added beneath a
     * set relation.
   *
   * @param <M>
   *          The type of the child server configuration object.
   * @param d
   *          The optional relation definition.
     *            The set relation definition.
   * @param listener
   *          The server managed object add listener.
     *            The configuration add listener.
   * @throws IllegalArgumentException
   *           If the optional relation definition is not associated
   *           with this managed object's definition.
     *             If the set relation definition is not associated with this
     *             managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the optional
   *           relation could not be retrieved.
     *             If the configuration entry associated with the set relation
     *             could not be retrieved.
   */
  public <M extends Configuration> void registerAddListener(
      OptionalRelationDefinition<?, M> d,
      ServerManagedObjectAddListener<M> listener)
      throws IllegalArgumentException, ConfigException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d).getParent();
    ConfigAddListener adaptor = new ConfigAddListenerAdaptor<M>(path, d,
        listener);
    registerAddListener(baseDN, adaptor);
    public <M extends Configuration> void registerAddListener(SetRelationDefinition<?, M> d,
            ConfigurationAddListener<M> listener) throws IllegalArgumentException, ConfigException {
        registerAddListener(d, new ServerManagedObjectAddListenerAdaptor<M>(listener));
  }
  /**
   * Register to be notified when new child configurations are added
     * Register to be notified when new child server managed object are added
   * beneath a set relation.
   *
   * @param <M>
@@ -859,80 +759,40 @@
   * @param d
   *          The set relation definition.
   * @param listener
   *          The configuration add listener.
   * @throws IllegalArgumentException
   *           If the set relation definition is not
   *           associated with this managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the
   *           set relation could not be retrieved.
   */
  public <M extends Configuration> void registerAddListener(
      SetRelationDefinition<?, M> d,
      ConfigurationAddListener<M> listener) throws IllegalArgumentException,
      ConfigException {
    registerAddListener(d, new ServerManagedObjectAddListenerAdaptor<M>(
        listener));
  }
  /**
   * Register to be notified when new child server managed object are
   * added beneath a set relation.
   *
   * @param <M>
   *          The type of the child server configuration object.
   * @param d
   *          The set relation definition.
   * @param listener
   *          The server managed object add listener.
   * @throws IllegalArgumentException
   *           If the set relation definition is not
   *           associated with this managed object's definition.
     *             If the set relation definition is not associated with this
     *             managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the
   *           set relation could not be retrieved.
     *             If the configuration entry associated with the set relation
     *             could not be retrieved.
   */
  public <M extends Configuration> void registerAddListener(
      SetRelationDefinition<?, M> d,
      ServerManagedObjectAddListener<M> listener)
      throws IllegalArgumentException, ConfigException {
    public <M extends Configuration> void registerAddListener(SetRelationDefinition<?, M> d,
            ServerManagedObjectAddListener<M> listener) throws IllegalArgumentException, ConfigException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d);
    ConfigAddListener adaptor = new ConfigAddListenerAdaptor<M>(path, d,
        listener);
        ConfigAddListener adaptor = new ConfigAddListenerAdaptor<M>(path, d, listener);
    registerAddListener(baseDN, adaptor);
  }
  /**
   * Register to be notified when this server managed object is
   * changed.
     * Register to be notified when this server managed object is changed.
   *
   * @param listener
   *          The configuration change listener.
   */
  public void registerChangeListener(
      ConfigurationChangeListener<? super S> listener) {
    registerChangeListener(new ServerManagedObjectChangeListenerAdaptor<S>(
        listener));
    public void registerChangeListener(ConfigurationChangeListener<? super S> listener) {
        registerChangeListener(new ServerManagedObjectChangeListenerAdaptor<S>(listener));
  }
  /**
   * Register to be notified when this server managed object is
   * changed.
     * Register to be notified when this server managed object is changed.
   *
   * @param listener
   *          The server managed object change listener.
   */
  public void registerChangeListener(
      ServerManagedObjectChangeListener<? super S> listener) {
    ConfigChangeListener adaptor = new ConfigChangeListenerAdaptor<S>(path,
        listener);
    public void registerChangeListener(ServerManagedObjectChangeListener<? super S> listener) {
        ConfigChangeListener adaptor = new ConfigChangeListenerAdaptor<S>(path, listener);
    configEntry.registerChangeListener(adaptor);
    // Change listener registration usually signifies that a managed
@@ -942,24 +802,19 @@
    // FIXME: we should prevent multiple invocations in the case where
    // multiple change listeners are registered for the same object.
    for (Constraint constraint : definition.getAllConstraints()) {
      for (ServerConstraintHandler handler : constraint
          .getServerConstraintHandlers()) {
            for (ServerConstraintHandler handler : constraint.getServerConstraintHandlers()) {
        try {
          handler.performPostAdd(this);
        } catch (ConfigException e) {
          if (debugEnabled()) {
            TRACER.debugCaught(DebugLogLevel.ERROR, e);
                    logger.trace("Unable to perform post add", e);
          }
        }
      }
    }
  }
  /**
   * Register to be notified when existing child configurations are
   * deleted beneath an instantiable relation.
     * Register to be notified when existing child configurations are deleted
     * beneath an instantiable relation.
   *
   * @param <M>
   *          The type of the child server configuration object.
@@ -968,25 +823,20 @@
   * @param listener
   *          The configuration delete listener.
   * @throws IllegalArgumentException
   *           If the instantiable relation definition is not
   *           associated with this managed object's definition.
     *             If the instantiable relation definition is not associated
     *             with this managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the
   *           instantiable relation could not be retrieved.
     *             If the configuration entry associated with the instantiable
     *             relation could not be retrieved.
   */
  public <M extends Configuration> void registerDeleteListener(
      InstantiableRelationDefinition<?, M> d,
      ConfigurationDeleteListener<M> listener) throws IllegalArgumentException,
      ConfigException {
    registerDeleteListener(d, new ServerManagedObjectDeleteListenerAdaptor<M>(
        listener));
    public <M extends Configuration> void registerDeleteListener(InstantiableRelationDefinition<?, M> d,
            ConfigurationDeleteListener<M> listener) throws IllegalArgumentException, ConfigException {
        registerDeleteListener(d, new ServerManagedObjectDeleteListenerAdaptor<M>(listener));
  }
  /**
   * Register to be notified when existing child server managed
   * objects are deleted beneath an instantiable relation.
     * Register to be notified when existing child server managed objects are
     * deleted beneath an instantiable relation.
   *
   * @param <M>
   *          The type of the child server configuration object.
@@ -995,28 +845,23 @@
   * @param listener
   *          The server managed objects delete listener.
   * @throws IllegalArgumentException
   *           If the instantiable relation definition is not
   *           associated with this managed object's definition.
     *             If the instantiable relation definition is not associated
     *             with this managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the
   *           instantiable relation could not be retrieved.
     *             If the configuration entry associated with the instantiable
     *             relation could not be retrieved.
   */
  public <M extends Configuration> void registerDeleteListener(
      InstantiableRelationDefinition<?, M> d,
      ServerManagedObjectDeleteListener<M> listener)
      throws IllegalArgumentException, ConfigException {
    public <M extends Configuration> void registerDeleteListener(InstantiableRelationDefinition<?, M> d,
            ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException, ConfigException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d);
    ConfigDeleteListener adaptor = new ConfigDeleteListenerAdaptor<M>(path, d,
        listener);
        ConfigDeleteListener adaptor = new ConfigDeleteListenerAdaptor<M>(path, d, listener);
    registerDeleteListener(baseDN, adaptor);
  }
  /**
   * Register to be notified when an existing child configuration is
   * deleted beneath an optional relation.
     * Register to be notified when an existing child configuration is deleted
     * beneath an optional relation.
   *
   * @param <M>
   *          The type of the child server configuration object.
@@ -1025,25 +870,20 @@
   * @param listener
   *          The configuration delete listener.
   * @throws IllegalArgumentException
   *           If the optional relation definition is not associated
   *           with this managed object's definition.
     *             If the optional relation definition is not associated with
     *             this managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the optional
   *           relation could not be retrieved.
   */
  public <M extends Configuration> void registerDeleteListener(
      OptionalRelationDefinition<?, M> d,
      ConfigurationDeleteListener<M> listener) throws IllegalArgumentException,
      ConfigException {
    registerDeleteListener(d, new ServerManagedObjectDeleteListenerAdaptor<M>(
        listener));
    public <M extends Configuration> void registerDeleteListener(OptionalRelationDefinition<?, M> d,
            ConfigurationDeleteListener<M> listener) throws IllegalArgumentException, ConfigException {
        registerDeleteListener(d, new ServerManagedObjectDeleteListenerAdaptor<M>(listener));
  }
  /**
   * Register to be notified when an existing child server managed
   * object is deleted beneath an optional relation.
     * Register to be notified when an existing child server managed object is
     * deleted beneath an optional relation.
   *
   * @param <M>
   *          The type of the child server configuration object.
@@ -1052,28 +892,23 @@
   * @param listener
   *          The server managed object delete listener.
   * @throws IllegalArgumentException
   *           If the optional relation definition is not associated
   *           with this managed object's definition.
     *             If the optional relation definition is not associated with
     *             this managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the optional
   *           relation could not be retrieved.
   */
  public <M extends Configuration> void registerDeleteListener(
      OptionalRelationDefinition<?, M> d,
      ServerManagedObjectDeleteListener<M> listener)
      throws IllegalArgumentException, ConfigException {
    public <M extends Configuration> void registerDeleteListener(OptionalRelationDefinition<?, M> d,
            ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException, ConfigException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d).getParent();
    ConfigDeleteListener adaptor = new ConfigDeleteListenerAdaptor<M>(path, d,
        listener);
        DN baseDN = DNBuilder.create(path, d).parent();
        ConfigDeleteListener adaptor = new ConfigDeleteListenerAdaptor<M>(path, d, listener);
    registerDeleteListener(baseDN, adaptor);
  }
  /**
   * Register to be notified when existing child configurations are
   * deleted beneath a set relation.
     * Register to be notified when existing child configurations are deleted
     * beneath a set relation.
   *
   * @param <M>
   *          The type of the child server configuration object.
@@ -1082,25 +917,20 @@
   * @param listener
   *          The configuration delete listener.
   * @throws IllegalArgumentException
   *           If the set relation definition is not
   *           associated with this managed object's definition.
     *             If the set relation definition is not associated with this
     *             managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the
   *           set relation could not be retrieved.
     *             If the configuration entry associated with the set relation
     *             could not be retrieved.
   */
  public <M extends Configuration> void registerDeleteListener(
      SetRelationDefinition<?, M> d,
      ConfigurationDeleteListener<M> listener) throws IllegalArgumentException,
      ConfigException {
    registerDeleteListener(d, new ServerManagedObjectDeleteListenerAdaptor<M>(
        listener));
    public <M extends Configuration> void registerDeleteListener(SetRelationDefinition<?, M> d,
            ConfigurationDeleteListener<M> listener) throws IllegalArgumentException, ConfigException {
        registerDeleteListener(d, new ServerManagedObjectDeleteListenerAdaptor<M>(listener));
  }
  /**
   * Register to be notified when existing child server managed
   * objects are deleted beneath a set relation.
     * Register to be notified when existing child server managed objects are
     * deleted beneath a set relation.
   *
   * @param <M>
   *          The type of the child server configuration object.
@@ -1109,25 +939,20 @@
   * @param listener
   *          The server managed objects delete listener.
   * @throws IllegalArgumentException
   *           If the set relation definition is not
   *           associated with this managed object's definition.
     *             If the set relation definition is not associated with this
     *             managed object's definition.
   * @throws ConfigException
   *           If the configuration entry associated with the
   *           set relation could not be retrieved.
     *             If the configuration entry associated with the set relation
     *             could not be retrieved.
   */
  public <M extends Configuration> void registerDeleteListener(
      SetRelationDefinition<?, M> d,
      ServerManagedObjectDeleteListener<M> listener)
      throws IllegalArgumentException, ConfigException {
    public <M extends Configuration> void registerDeleteListener(SetRelationDefinition<?, M> d,
            ServerManagedObjectDeleteListener<M> listener) throws IllegalArgumentException, ConfigException {
    validateRelationDefinition(d);
    DN baseDN = DNBuilder.create(path, d);
    ConfigDeleteListener adaptor = new ConfigDeleteListenerAdaptor<M>(path, d,
        listener);
        ConfigDeleteListener adaptor = new ConfigDeleteListenerAdaptor<M>(path, d, listener);
    registerDeleteListener(baseDN, adaptor);
  }
  /**
   * {@inheritDoc}
   */
@@ -1140,8 +965,7 @@
    builder.append(", DN=\"");
    builder.append(getDN());
    builder.append('\"');
    for (Map.Entry<PropertyDefinition<?>, SortedSet<?>> value : properties
        .entrySet()) {
        for (Map.Entry<PropertyDefinition<?>, SortedSet<?>> value : properties.entrySet()) {
      builder.append(", ");
      builder.append(value.getKey().getName());
      builder.append('=');
@@ -1152,11 +976,8 @@
    return builder.toString();
  }
  /**
   * Determines whether or not this managed object can be used by the
   * server.
     * Determines whether or not this managed object can be used by the server.
   *
   * @throws ConstraintViolationException
   *           If one or more constraints determined that this managed
@@ -1165,17 +986,15 @@
  void ensureIsUsable() throws ConstraintViolationException {
    // Enforce any constraints.
    boolean isUsable = true;
    List<LocalizableMessage> reasons = new LinkedList<Message>();
        List<LocalizableMessage> reasons = new LinkedList<LocalizableMessage>();
    for (Constraint constraint : definition.getAllConstraints()) {
      for (ServerConstraintHandler handler : constraint
          .getServerConstraintHandlers()) {
            for (ServerConstraintHandler handler : constraint.getServerConstraintHandlers()) {
        try {
          if (!handler.isUsable(this, reasons)) {
            isUsable = false;
          }
        } catch (ConfigException e) {
          LocalizableMessage message = ERR_SERVER_CONSTRAINT_EXCEPTION.get(e
              .getMessageObject());
                    LocalizableMessage message = ERR_SERVER_CONSTRAINT_EXCEPTION.get(e.getMessageObject());
          reasons.add(message);
          isUsable = false;
        }
@@ -1187,13 +1006,10 @@
    }
  }
  /**
   * Update the config entry associated with this server managed
   * object. This is only intended to be used by change listener call
   * backs in order to update the managed object with the correct
   * config entry.
     * Update the config entry associated with this server managed object. This
     * is only intended to be used by change listener call backs in order to
     * update the managed object with the correct config entry.
   *
   * @param configEntry
   *          The configuration entry.
@@ -1202,20 +1018,15 @@
    this.configEntry = configEntry;
  }
  // Deregister an add listener.
  private <M extends Configuration> void deregisterAddListener(DN baseDN,
      ConfigurationAddListener<M> listener) {
    private <M extends Configuration> void deregisterAddListener(DN baseDN, ConfigurationAddListener<M> listener) {
    try {
      ConfigEntry configEntry = getListenerConfigEntry(baseDN);
      if (configEntry != null) {
        for (ConfigAddListener l : configEntry.getAddListeners()) {
          if (l instanceof ConfigAddListenerAdaptor) {
            ConfigAddListenerAdaptor<?> adaptor =
              (ConfigAddListenerAdaptor<?>) l;
            ServerManagedObjectAddListener<?> l2 = adaptor
                .getServerManagedObjectAddListener();
                        ConfigAddListenerAdaptor<?> adaptor = (ConfigAddListenerAdaptor<?>) l;
                        ServerManagedObjectAddListener<?> l2 = adaptor.getServerManagedObjectAddListener();
            if (l2 instanceof ServerManagedObjectAddListenerAdaptor<?>) {
              ServerManagedObjectAddListenerAdaptor<?> adaptor2 =
                (ServerManagedObjectAddListenerAdaptor<?>) l2;
@@ -1225,22 +1036,16 @@
            }
          }
        }
      }
      else
      {
            } else {
        // The relation entry does not exist so check for and deregister
        // delayed add listener.
        deregisterDelayedAddListener(baseDN, listener);
      }
    } catch (ConfigException e) {
      // Ignore the exception since this implies deregistration.
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
            logger.trace("Unable to deregister add listener", e);
      }
    }
  }
  // Deregister an add listener.
  private <M extends Configuration> void deregisterAddListener(DN baseDN,
@@ -1250,29 +1055,22 @@
      if (configEntry != null) {
        for (ConfigAddListener l : configEntry.getAddListeners()) {
          if (l instanceof ConfigAddListenerAdaptor) {
            ConfigAddListenerAdaptor<?> adaptor =
              (ConfigAddListenerAdaptor<?>) l;
                        ConfigAddListenerAdaptor<?> adaptor = (ConfigAddListenerAdaptor<?>) l;
            if (adaptor.getServerManagedObjectAddListener() == listener) {
              configEntry.deregisterAddListener(adaptor);
            }
          }
        }
      }
      else
      {
            } else {
        // The relation entry does not exist so check for and deregister
        // delayed add listener.
        deregisterDelayedAddListener(baseDN, listener);
      }
    } catch (ConfigException e) {
      // Ignore the exception since this implies deregistration.
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
            logger.trace("Unable to deregister add listener", e);
      }
    }
  }
  // Deregister a delete listener.
  private <M extends Configuration> void deregisterDeleteListener(DN baseDN,
@@ -1282,10 +1080,8 @@
      if (configEntry != null) {
        for (ConfigDeleteListener l : configEntry.getDeleteListeners()) {
          if (l instanceof ConfigDeleteListenerAdaptor) {
            ConfigDeleteListenerAdaptor<?> adaptor =
              (ConfigDeleteListenerAdaptor<?>) l;
            ServerManagedObjectDeleteListener<?> l2 = adaptor
                .getServerManagedObjectDeleteListener();
                        ConfigDeleteListenerAdaptor<?> adaptor = (ConfigDeleteListenerAdaptor<?>) l;
                        ServerManagedObjectDeleteListener<?> l2 = adaptor.getServerManagedObjectDeleteListener();
            if (l2 instanceof ServerManagedObjectDeleteListenerAdaptor<?>) {
              ServerManagedObjectDeleteListenerAdaptor<?> adaptor2 =
                (ServerManagedObjectDeleteListenerAdaptor<?>) l2;
@@ -1295,22 +1091,16 @@
            }
          }
        }
      }
      else
      {
            } else {
        // The relation entry does not exist so check for and deregister
        // delayed add listener.
        deregisterDelayedDeleteListener(baseDN, listener);
      }
    } catch (ConfigException e) {
      // Ignore the exception since this implies deregistration.
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
            logger.trace("Unable to deregister delete listener", e);
      }
    }
  }
  // Deregister a delete listener.
  private <M extends Configuration> void deregisterDeleteListener(DN baseDN,
@@ -1320,29 +1110,22 @@
      if (configEntry != null) {
        for (ConfigDeleteListener l : configEntry.getDeleteListeners()) {
          if (l instanceof ConfigDeleteListenerAdaptor) {
            ConfigDeleteListenerAdaptor<?> adaptor =
              (ConfigDeleteListenerAdaptor<?>) l;
                        ConfigDeleteListenerAdaptor<?> adaptor = (ConfigDeleteListenerAdaptor<?>) l;
            if (adaptor.getServerManagedObjectDeleteListener() == listener) {
              configEntry.deregisterDeleteListener(adaptor);
            }
          }
        }
      }
      else
      {
            } else {
        // The relation entry does not exist so check for and deregister
        // delayed add listener.
        deregisterDelayedDeleteListener(baseDN, listener);
      }
    } catch (ConfigException e) {
      // Ignore the exception since this implies deregistration.
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
            logger.trace("Unable to deregister delete listener", e);
      }
    }
  }
  // Gets a config entry required for a listener and throws a config
  // exception on failure or returns null if the entry does not exist.
@@ -1352,23 +1135,18 @@
    try {
      configEntry = DirectoryServer.getConfigEntry(dn);
    } catch (ConfigException e) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }
      LocalizableMessage message = ERR_ADMIN_CANNOT_GET_LISTENER_BASE.get(
          String.valueOf(dn), stackTraceToSingleLineString(e));
            logger.trace("Unable to get listener base entry", e);
            LocalizableMessage message = ERR_ADMIN_CANNOT_GET_LISTENER_BASE.get(String.valueOf(dn),
                    stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD));
      throw new ConfigException(message, e);
    }
    return configEntry;
  }
  // Register an instantiable or optional relation add listener.
  private void registerAddListener(DN baseDN, ConfigAddListener adaptor)
      throws IllegalArgumentException, ConfigException {
    private void registerAddListener(DN baseDN, ConfigAddListener adaptor) throws IllegalArgumentException,
            ConfigException {
    ConfigEntry relationEntry = getListenerConfigEntry(baseDN);
    if (relationEntry != null) {
@@ -1376,25 +1154,20 @@
    } else {
      // The relation entry does not exist yet so register a delayed
      // add listener.
      ConfigAddListener delayedListener = new DelayedConfigAddListener(baseDN,
          adaptor);
            ConfigAddListener delayedListener = new DelayedConfigAddListener(baseDN, adaptor);
      registerDelayedListener(baseDN, delayedListener);
    }
  }
  // Register a delayed listener with the nearest existing parent
  // entry to the provided base DN.
  private void registerDelayedListener(DN baseDN,
      ConfigAddListener delayedListener) throws ConfigException {
    DN parentDN = baseDN.getParent();
    private void registerDelayedListener(DN baseDN, ConfigAddListener delayedListener) throws ConfigException {
        DN parentDN = baseDN.parent();
    while (parentDN != null) {
      ConfigEntry relationEntry = getListenerConfigEntry(parentDN);
      if (relationEntry == null) {
        delayedListener = new DelayedConfigAddListener(parentDN,
            delayedListener);
        parentDN = parentDN.getParent();
                delayedListener = new DelayedConfigAddListener(parentDN, delayedListener);
                parentDN = parentDN.parent();
      } else {
        relationEntry.registerAddListener(delayedListener);
        return;
@@ -1402,61 +1175,50 @@
    }
    // No parent entry could be found.
    LocalizableMessage message = ERR_ADMIN_UNABLE_TO_REGISTER_LISTENER
        .get(String.valueOf(baseDN));
        LocalizableMessage message = ERR_ADMIN_UNABLE_TO_REGISTER_LISTENER.get(String.valueOf(baseDN));
    throw new ConfigException(message);
  }
  // Deregister a delayed listener with the nearest existing parent
  // entry to the provided base DN.
  private <M extends Configuration> void deregisterDelayedAddListener(DN baseDN,
      ConfigurationAddListener<M> listener) throws ConfigException {
    DN parentDN = baseDN.getParent();
            ConfigurationAddListener<M> listener)
            throws ConfigException {
        DN parentDN = baseDN.parent();
    int delayWrappers = 0;
    while (parentDN != null) {
      ConfigEntry relationEntry = getListenerConfigEntry(parentDN);
      if (relationEntry == null) {
        parentDN = parentDN.getParent();
                parentDN = parentDN.parent();
        delayWrappers++;
      } else {
        for (ConfigAddListener l : relationEntry.getAddListeners()) {
          if(l instanceof DelayedConfigAddListener)
          {
            DelayedConfigAddListener delayListener =
                (DelayedConfigAddListener) l;
                    if (l instanceof DelayedConfigAddListener) {
                        DelayedConfigAddListener delayListener = (DelayedConfigAddListener) l;
            ConfigAddListener wrappedListener;
            int i = delayWrappers;
            for(; i > 0; i--)
            {
                        for (; i > 0; i--) {
              wrappedListener = delayListener.getDelayedAddListener();
              if(wrappedListener != null &&
                  wrappedListener instanceof DelayedConfigAddListener)
              {
                            if (wrappedListener != null && wrappedListener instanceof DelayedConfigAddListener) {
                delayListener = (DelayedConfigAddListener) l;
              }
              else
              {
                            } else {
                break;
              }
            }
            if(i > 0)
            {
              // There are not enough level of wrapping so this can't be
                        if (i > 0) {
                            // There are not enough level of wrapping so this
                            // can't be
              // the listener we are looking for.
              continue;
            }
            ConfigAddListener delayedListener =
                delayListener.getDelayedAddListener();
                        ConfigAddListener delayedListener = delayListener.getDelayedAddListener();
            if (delayedListener != null &&
                 delayedListener instanceof ConfigAddListenerAdaptor) {
              ConfigAddListenerAdaptor<?> adaptor =
                  (ConfigAddListenerAdaptor<?>) delayedListener;
              ServerManagedObjectAddListener<?> l2 = adaptor
                  .getServerManagedObjectAddListener();
                        if (delayedListener != null && delayedListener instanceof ConfigAddListenerAdaptor) {
                            ConfigAddListenerAdaptor<?> adaptor = (ConfigAddListenerAdaptor<?>) delayedListener;
                            ServerManagedObjectAddListener<?> l2 = adaptor.getServerManagedObjectAddListener();
              if (l2 instanceof ServerManagedObjectAddListenerAdaptor<?>) {
                ServerManagedObjectAddListenerAdaptor<?> adaptor2 =
                    (ServerManagedObjectAddListenerAdaptor<?>) l2;
@@ -1472,58 +1234,45 @@
    }
  }
  // Deregister a delayed listener with the nearest existing parent
  // entry to the provided base DN.
  private <M extends Configuration> void deregisterDelayedDeleteListener(
      DN baseDN, ConfigurationDeleteListener<M> listener)
      throws ConfigException {
    DN parentDN = baseDN.getParent();
    private <M extends Configuration> void deregisterDelayedDeleteListener(DN baseDN,
            ConfigurationDeleteListener<M> listener) throws ConfigException {
        DN parentDN = baseDN.parent();
    int delayWrappers = 0;
    while (parentDN != null) {
      ConfigEntry relationEntry = getListenerConfigEntry(parentDN);
      if (relationEntry == null) {
        parentDN = parentDN.getParent();
                parentDN = parentDN.parent();
        delayWrappers++;
      } else {
        for (ConfigAddListener l : relationEntry.getAddListeners()) {
          if(l instanceof DelayedConfigAddListener)
          {
            DelayedConfigAddListener delayListener =
                (DelayedConfigAddListener) l;
                    if (l instanceof DelayedConfigAddListener) {
                        DelayedConfigAddListener delayListener = (DelayedConfigAddListener) l;
            ConfigAddListener wrappedListener;
            int i = delayWrappers;
            for(; i > 0; i--)
            {
                        for (; i > 0; i--) {
              wrappedListener = delayListener.getDelayedAddListener();
              if(wrappedListener != null &&
                  wrappedListener instanceof DelayedConfigAddListener)
              {
                            if (wrappedListener != null && wrappedListener instanceof DelayedConfigAddListener) {
                delayListener = (DelayedConfigAddListener) l;
              }
              else
              {
                            } else {
                break;
              }
            }
            if(i > 0)
            {
              // There are not enough level of wrapping so this can't be
                        if (i > 0) {
                            // There are not enough level of wrapping so this
                            // can't be
              // the listener we are looking for.
              continue;
            }
            ConfigDeleteListener delayedListener =
                delayListener.getDelayedDeleteListener();
                        ConfigDeleteListener delayedListener = delayListener.getDelayedDeleteListener();
            if (delayedListener != null &&
                delayedListener instanceof ConfigDeleteListenerAdaptor) {
              ConfigDeleteListenerAdaptor<?> adaptor =
                  (ConfigDeleteListenerAdaptor<?>) delayedListener;
              ServerManagedObjectDeleteListener<?> l2 = adaptor
                  .getServerManagedObjectDeleteListener();
                        if (delayedListener != null && delayedListener instanceof ConfigDeleteListenerAdaptor) {
                            ConfigDeleteListenerAdaptor<?> adaptor = (ConfigDeleteListenerAdaptor<?>) delayedListener;
                            ServerManagedObjectDeleteListener<?> l2 = adaptor.getServerManagedObjectDeleteListener();
              if (l2 instanceof ServerManagedObjectDeleteListenerAdaptor<?>) {
                ServerManagedObjectDeleteListenerAdaptor<?> adaptor2 =
                    (ServerManagedObjectDeleteListenerAdaptor<?>) l2;
@@ -1543,50 +1292,40 @@
  // entry to the provided base DN.
  private <M extends Configuration> void deregisterDelayedAddListener(DN baseDN,
      ServerManagedObjectAddListener<M> listener) throws ConfigException {
    DN parentDN = baseDN.getParent();
        DN parentDN = baseDN.parent();
    int delayWrappers = 0;
    while (parentDN != null) {
      ConfigEntry relationEntry = getListenerConfigEntry(parentDN);
      if (relationEntry == null) {
        parentDN = parentDN.getParent();
                parentDN = parentDN.parent();
        delayWrappers++;
      } else {
        for (ConfigAddListener l : relationEntry.getAddListeners()) {
          if(l instanceof DelayedConfigAddListener)
          {
            DelayedConfigAddListener delayListener =
                (DelayedConfigAddListener) l;
                    if (l instanceof DelayedConfigAddListener) {
                        DelayedConfigAddListener delayListener = (DelayedConfigAddListener) l;
            ConfigAddListener wrappedListener;
            int i = delayWrappers;
            for(; i > 0; i--)
            {
                        for (; i > 0; i--) {
              wrappedListener = delayListener.getDelayedAddListener();
              if(wrappedListener != null &&
                  wrappedListener instanceof DelayedConfigAddListener)
              {
                            if (wrappedListener != null && wrappedListener instanceof DelayedConfigAddListener) {
                delayListener = (DelayedConfigAddListener) l;
              }
              else
              {
                            } else {
                break;
              }
            }
            if(i > 0)
            {
              // There are not enough level of wrapping so this can't be
                        if (i > 0) {
                            // There are not enough level of wrapping so this
                            // can't be
              // the listener we are looking for.
              continue;
            }
            ConfigAddListener delayedListener =
                delayListener.getDelayedAddListener();
                        ConfigAddListener delayedListener = delayListener.getDelayedAddListener();
            if (delayedListener != null &&
                 delayedListener instanceof ConfigAddListenerAdaptor) {
              ConfigAddListenerAdaptor<?> adaptor =
                  (ConfigAddListenerAdaptor<?>) delayedListener;
                        if (delayedListener != null && delayedListener instanceof ConfigAddListenerAdaptor) {
                            ConfigAddListenerAdaptor<?> adaptor = (ConfigAddListenerAdaptor<?>) delayedListener;
              if (adaptor.getServerManagedObjectAddListener() == listener) {
                relationEntry.deregisterAddListener(l);
              }
@@ -1598,56 +1337,44 @@
    }
  }
  // Deregister a delayed listener with the nearest existing parent
  // entry to the provided base DN.
  private <M extends Configuration> void deregisterDelayedDeleteListener(
      DN baseDN, ServerManagedObjectDeleteListener<M> listener)
      throws ConfigException {
    DN parentDN = baseDN.getParent();
    private <M extends Configuration> void deregisterDelayedDeleteListener(DN baseDN,
            ServerManagedObjectDeleteListener<M> listener) throws ConfigException {
        DN parentDN = baseDN.parent();
    int delayWrappers = 0;
    while (parentDN != null) {
      ConfigEntry relationEntry = getListenerConfigEntry(parentDN);
      if (relationEntry == null) {
        parentDN = parentDN.getParent();
                parentDN = parentDN.parent();
        delayWrappers++;
      } else {
        for (ConfigAddListener l : relationEntry.getAddListeners()) {
          if(l instanceof DelayedConfigAddListener)
          {
            DelayedConfigAddListener delayListener =
                (DelayedConfigAddListener) l;
                    if (l instanceof DelayedConfigAddListener) {
                        DelayedConfigAddListener delayListener = (DelayedConfigAddListener) l;
            ConfigAddListener wrappedListener;
            int i = delayWrappers;
            for(; i > 0; i--)
            {
                        for (; i > 0; i--) {
              wrappedListener = delayListener.getDelayedAddListener();
              if(wrappedListener != null &&
                  wrappedListener instanceof DelayedConfigAddListener)
              {
                            if (wrappedListener != null && wrappedListener instanceof DelayedConfigAddListener) {
                delayListener = (DelayedConfigAddListener) l;
              }
              else
              {
                            } else {
                break;
              }
            }
            if(i > 0)
            {
              // There are not enough level of wrapping so this can't be
                        if (i > 0) {
                            // There are not enough level of wrapping so this
                            // can't be
              // the listener we are looking for.
              continue;
            }
            ConfigDeleteListener delayedListener =
                delayListener.getDelayedDeleteListener();
                        ConfigDeleteListener delayedListener = delayListener.getDelayedDeleteListener();
            if (delayedListener != null &&
                 delayedListener instanceof ConfigDeleteListenerAdaptor) {
              ConfigDeleteListenerAdaptor<?> adaptor =
                  (ConfigDeleteListenerAdaptor<?>) delayedListener;
                        if (delayedListener != null && delayedListener instanceof ConfigDeleteListenerAdaptor) {
                            ConfigDeleteListenerAdaptor<?> adaptor = (ConfigDeleteListenerAdaptor<?>) delayedListener;
              if (adaptor.getServerManagedObjectDeleteListener() == listener) {
                relationEntry.deregisterAddListener(l);
              }
@@ -1659,10 +1386,8 @@
    }
  }
  // Register an instantiable or optional relation delete listener.
  private void registerDeleteListener(DN baseDN, ConfigDeleteListener adaptor)
      throws ConfigException {
    private void registerDeleteListener(DN baseDN, ConfigDeleteListener adaptor) throws ConfigException {
    ConfigEntry relationEntry = getListenerConfigEntry(baseDN);
    if (relationEntry != null) {
@@ -1670,23 +1395,18 @@
    } else {
      // The relation entry does not exist yet so register a delayed
      // add listener.
      ConfigAddListener delayedListener = new DelayedConfigAddListener(baseDN,
          adaptor);
            ConfigAddListener delayedListener = new DelayedConfigAddListener(baseDN, adaptor);
      registerDelayedListener(baseDN, delayedListener);
    }
  }
  // Validate that a relation definition belongs to this managed
  // object.
  private void validateRelationDefinition(RelationDefinition<?, ?> rd)
      throws IllegalArgumentException {
    RelationDefinition<?, ?> tmp = definition.getRelationDefinition(rd
        .getName());
    private void validateRelationDefinition(RelationDefinition<?, ?> rd) throws IllegalArgumentException {
        RelationDefinition<?, ?> tmp = definition.getRelationDefinition(rd.getName());
    if (tmp != rd) {
      throw new IllegalArgumentException("The relation " + rd.getName()
          + " is not associated with a " + definition.getName());
            throw new IllegalArgumentException("The relation " + rd.getName() + " is not associated with a "
                    + definition.getName());
    }
  }
}
opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagedObjectDecodingException.java
@@ -27,8 +27,6 @@
package org.opends.server.admin.server;
import static com.forgerock.opendj.ldap.AdminMessages.*;
import java.util.Collection;
@@ -42,11 +40,9 @@
import org.opends.server.admin.PropertyException;
import static com.forgerock.opendj.util.Validator.*;
/**
 * The requested server managed object was found but one or more of
 * its properties could not be decoded successfully.
 * The requested server managed object was found but one or more of its
 * properties could not be decoded successfully.
 */
public class ServerManagedObjectDecodingException extends DecodingException {
@@ -55,34 +51,29 @@
   */
  private static final long serialVersionUID = 1598401431084729853L;
  // Create the message.
  private static LocalizableMessage createMessage(
      ServerManagedObject<?> partialManagedObject,
    private static LocalizableMessage createMessage(ServerManagedObject<?> partialManagedObject,
      Collection<PropertyException> causes) {
    ensureNotNull(causes);
    ensureTrue(!causes.isEmpty(), "causes should nnot be empty");
    ManagedObjectDefinition<?, ?> d = partialManagedObject
        .getManagedObjectDefinition();
        ManagedObjectDefinition<?, ?> d = partialManagedObject.getManagedObjectDefinition();
    if (causes.size() == 1) {
      return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(d
          .getUserFriendlyName(), causes.iterator().next().getMessageObject());
            return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_SINGLE.get(d.getUserFriendlyName(), causes.iterator().next()
                    .getLocalizableMessageObject());
    } else {
      LocalizableMessageBuilder builder = new MessageBuilder();
            LocalizableMessageBuilder builder = new LocalizableMessageBuilder();
      boolean isFirst = true;
      for (PropertyException cause : causes) {
        if (!isFirst) {
          builder.append("; ");
        }
        builder.append(cause.getMessageObject());
                builder.append(cause.getLocalizableMessageObject());
        isFirst = false;
      }
      return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_PLURAL.get(d
          .getUserFriendlyName(), builder.toMessage());
            return ERR_MANAGED_OBJECT_DECODING_EXCEPTION_PLURAL.get(d.getUserFriendlyName(), builder.toMessage());
    }
  }
@@ -92,54 +83,44 @@
  // The partially created server managed object.
  private final ServerManagedObject<?> partialManagedObject;
  /**
   * Create a new property decoding exception.
   *
   * @param partialManagedObject
   *          The partially created server managed object containing
   *          properties which were successfully decoded and empty
   *          properties for those which were not (this may include
   *          empty mandatory properties).
     *            properties for those which were not (this may include empty
     *            mandatory properties).
   * @param causes
   *          The exception(s) that caused this decoding exception.
   */
  public ServerManagedObjectDecodingException(
      ServerManagedObject<?> partialManagedObject,
    public ServerManagedObjectDecodingException(ServerManagedObject<?> partialManagedObject,
      Collection<PropertyException> causes) {
    super(createMessage(partialManagedObject, causes));
    this.partialManagedObject = partialManagedObject;
    this.causes = Collections
        .unmodifiableList(new LinkedList<PropertyException>(causes));
        this.causes = Collections.unmodifiableList(new LinkedList<PropertyException>(causes));
  }
  /**
   * Get an unmodifiable collection view of the causes of this
   * exception.
     * Get an unmodifiable collection view of the causes of this exception.
   *
   * @return Returns an unmodifiable collection view of the causes of
   *         this exception.
     * @return Returns an unmodifiable collection view of the causes of this
     *         exception.
   */
  public Collection<PropertyException> getCauses() {
    return causes;
  }
  /**
   * Get the partially created server managed object containing
     * Get the partially created server managed object containing properties
     * which were successfully decoded and empty properties for those which were
     * not (this may include empty mandatory properties).
     *
     * @return Returns the partially created server managed object containing
   * properties which were successfully decoded and empty properties
   * for those which were not (this may include empty mandatory
   * properties).
   *
   * @return Returns the partially created server managed object
   *         containing properties which were successfully decoded and
   *         empty properties for those which were not (this may
   *         include empty mandatory properties).
   */
  public ServerManagedObject<?> getPartialManagedObject() {
    return partialManagedObject;
opendj-admin/src/main/java/org/opends/server/admin/server/ServerManagementContext.java
@@ -27,11 +27,7 @@
package org.opends.server.admin.server;
import static com.forgerock.opendj.ldap.AdminMessages.*;
import static org.opends.server.loggers.debug.DebugLogger.*;
import static org.opends.server.util.StaticUtils.*;
import java.util.ArrayList;
import java.util.Collection;
@@ -76,35 +72,26 @@
import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
import org.opends.server.admin.UnknownPropertyDefinitionException;
import org.opends.server.admin.DefinitionDecodingException.Reason;
import org.opends.server.admin.std.meta.RootCfgDefn;
import org.opends.server.admin.std.server.RootCfg;
import org.opends.server.api.AttributeValueDecoder;
import org.opends.server.config.ConfigEntry;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeValue;
import org.forgerock.opendj.admin.meta.RootCfgDefn;
import org.forgerock.opendj.admin.server.RootCfg;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DebugLogLevel;
import org.opends.server.types.DirectoryException;
/**
 * Server management connection context.
 */
public final class ServerManagementContext {
  /**
   * A default behavior visitor used for retrieving the default values
   * of a property.
     * A default behavior visitor used for retrieving the default values of a
     * property.
   *
   * @param <T>
   *          The type of the property.
   */
  private class DefaultValueFinder<T> implements
      DefaultBehaviorProviderVisitor<T, Collection<T>, Void> {
    private class DefaultValueFinder<T> implements DefaultBehaviorProviderVisitor<T, Collection<T>, Void> {
    // Any exception that occurred whilst retrieving inherited default
    // values.
@@ -120,31 +107,24 @@
    // The next property whose default values were required.
    private PropertyDefinition<T> nextProperty = null;
    // Private constructor.
    private DefaultValueFinder(ConfigEntry newConfigEntry) {
      this.newConfigEntry = newConfigEntry;
    }
    /**
     * {@inheritDoc}
     */
    public Collection<T> visitAbsoluteInherited(
        AbsoluteInheritedDefaultBehaviorProvider<T> d, Void p) {
        public Collection<T> visitAbsoluteInherited(AbsoluteInheritedDefaultBehaviorProvider<T> d, Void p) {
      try {
        return getInheritedProperty(d.getManagedObjectPath(), d
            .getManagedObjectDefinition(), d.getPropertyName());
                return getInheritedProperty(d.getManagedObjectPath(), d.getManagedObjectDefinition(),
                        d.getPropertyName());
      } catch (DefaultBehaviorException e) {
        exception = e;
        return Collections.emptySet();
      }
    }
    /**
     * {@inheritDoc}
     */
@@ -152,13 +132,10 @@
      return Collections.emptySet();
    }
    /**
     * {@inheritDoc}
     */
    public Collection<T> visitDefined(DefinedDefaultBehaviorProvider<T> d,
        Void p) {
        public Collection<T> visitDefined(DefinedDefaultBehaviorProvider<T> d, Void p) {
      Collection<String> stringValues = d.getDefaultValues();
      List<T> values = new ArrayList<T>(stringValues.size());
@@ -174,69 +151,53 @@
      return values;
    }
    /**
     * {@inheritDoc}
     */
    public Collection<T> visitRelativeInherited(
        RelativeInheritedDefaultBehaviorProvider<T> d, Void p) {
        public Collection<T> visitRelativeInherited(RelativeInheritedDefaultBehaviorProvider<T> d, Void p) {
      try {
        return getInheritedProperty(d.getManagedObjectPath(nextPath), d
            .getManagedObjectDefinition(), d.getPropertyName());
                return getInheritedProperty(d.getManagedObjectPath(nextPath), d.getManagedObjectDefinition(),
                        d.getPropertyName());
      } catch (DefaultBehaviorException e) {
        exception = e;
        return Collections.emptySet();
      }
    }
    /**
     * {@inheritDoc}
     */
    public Collection<T> visitUndefined(UndefinedDefaultBehaviorProvider<T> d,
        Void p) {
        public Collection<T> visitUndefined(UndefinedDefaultBehaviorProvider<T> d, Void p) {
      return Collections.emptySet();
    }
    // Find the default values for the next path/property.
    private Collection<T> find(ManagedObjectPath<?, ?> p,
        PropertyDefinition<T> pd) throws DefaultBehaviorException {
        private Collection<T> find(ManagedObjectPath<?, ?> p, PropertyDefinition<T> pd) throws DefaultBehaviorException {
      nextPath = p;
      nextProperty = pd;
      Collection<T> values = nextProperty.getDefaultBehaviorProvider().accept(
          this, null);
            Collection<T> values = nextProperty.getDefaultBehaviorProvider().accept(this, null);
      if (exception != null) {
        throw exception;
      }
      if (values.size() > 1 && !pd.hasOption(PropertyOption.MULTI_VALUED)) {
        throw new DefaultBehaviorException(pd,
            new PropertyIsSingleValuedException(pd));
                throw new DefaultBehaviorException(pd, new PropertyIsSingleValuedException(pd));
      }
      return values;
    }
    // Get an inherited property value.
    @SuppressWarnings("unchecked")
    private Collection<T> getInheritedProperty(ManagedObjectPath target,
        AbstractManagedObjectDefinition<?, ?> d, String propertyName)
        throws DefaultBehaviorException {
        private Collection<T> getInheritedProperty(ManagedObjectPath target, AbstractManagedObjectDefinition<?, ?> d,
                String propertyName) throws DefaultBehaviorException {
      // First check that the requested type of managed object
      // corresponds to the path.
      AbstractManagedObjectDefinition<?, ?> supr = target
          .getManagedObjectDefinition();
            AbstractManagedObjectDefinition<?, ?> supr = target.getManagedObjectDefinition();
      if (!supr.isParentOf(d)) {
        throw new DefaultBehaviorException(
            nextProperty, new DefinitionDecodingException(supr,
                throw new DefaultBehaviorException(nextProperty, new DefinitionDecodingException(supr,
                Reason.WRONG_TYPE_INFORMATION));
      }
@@ -254,8 +215,7 @@
        }
        DefinitionResolver resolver = new MyDefinitionResolver(configEntry);
        ManagedObjectDefinition<?, ?> mod = d
            .resolveManagedObjectDefinition(resolver);
                ManagedObjectDefinition<?, ?> mod = d.resolveManagedObjectDefinition(resolver);
        PropertyDefinition<T> pd2;
        try {
@@ -299,26 +259,20 @@
    }
  }
  /**
   * A definition resolver that determines the managed object
   * definition from the object classes of a ConfigEntry.
     * A definition resolver that determines the managed object definition from
     * the object classes of a ConfigEntry.
   */
  private class MyDefinitionResolver implements DefinitionResolver {
    // The config entry.
    private final ConfigEntry entry;
    // Private constructor.
    private MyDefinitionResolver(ConfigEntry entry) {
      this.entry = entry;
    }
    /**
     * {@inheritDoc}
     */
@@ -328,13 +282,10 @@
    }
  }
  /**
   * A visitor which is used to decode property LDAP values.
   */
  private static final class ValueDecoder extends
      PropertyDefinitionVisitor<Object, String> {
    private static final class ValueDecoder extends PropertyDefinitionVisitor<Object, String> {
    /**
     * Decodes the provided property LDAP value.
@@ -347,74 +298,55 @@
     *          The LDAP string representation.
     * @return Returns the decoded LDAP value.
     * @throws IllegalPropertyValueStringException
     *           If the property value could not be decoded because it
     *           was invalid.
         *             If the property value could not be decoded because it was
         *             invalid.
     */
    public static <PD> PD decode(PropertyDefinition<PD> pd,
        AttributeValue value) throws IllegalPropertyValueStringException {
        public static <PD> PD decode(PropertyDefinition<PD> pd, AttributeValue value)
                throws IllegalPropertyValueStringException {
      String s = value.getValue().toString();
      return pd.castValue(pd.accept(new ValueDecoder(), s));
    }
    // Prevent instantiation.
    private ValueDecoder() {
      // No implementation required.
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public <C extends ConfigurationClient, S extends Configuration>
    Object visitAggregation(AggregationPropertyDefinition<C, S> d, String p) {
        public <C extends ConfigurationClient, S extends Configuration> Object visitAggregation(
                AggregationPropertyDefinition<C, S> d, String p) {
      // Aggregations values are stored as full DNs in LDAP, but
      // just their common name is exposed in the admin framework.
      try {
        Reference<C, S> reference = Reference.parseDN(d.getParentPath(), d
            .getRelationDefinition(), p);
                Reference<C, S> reference = Reference.parseDN(d.getParentPath(), d.getRelationDefinition(), p);
        return reference.getName();
      } catch (IllegalArgumentException e) {
        throw new IllegalPropertyValueStringException(d, p);
      }
    }
    /**
     * {@inheritDoc}
     */
    @Override
    public <T> Object visitUnknown(PropertyDefinition<T> d, String p)
        throws UnknownPropertyDefinitionException {
        public <T> Object visitUnknown(PropertyDefinition<T> d, String p) throws UnknownPropertyDefinitionException {
      // By default the property definition's decoder will do.
      return d.decodeValue(p);
    }
  }
  // Singleton instance.
  private final static ServerManagementContext INSTANCE =
    new ServerManagementContext();
    private final static ServerManagementContext INSTANCE = new ServerManagementContext();
  /**
   * The root server managed object.
   */
  private static final ServerManagedObject<RootCfg> ROOT =
    new ServerManagedObject<RootCfg>(
      ManagedObjectPath.emptyPath(), RootCfgDefn.getInstance(), Collections
          .<PropertyDefinition<?>, SortedSet<?>> emptyMap(), null);
  /**
   * The tracer object for the debug logger.
   */
  private static final DebugTracer TRACER = getTracer();
    private static final ServerManagedObject<RootCfg> ROOT = new ServerManagedObject<RootCfg>(
            ManagedObjectPath.emptyPath(), RootCfgDefn.getInstance(),
            Collections.<PropertyDefinition<?>, SortedSet<?>> emptyMap(), null);
  /**
   * Get the single server-side management context.
@@ -425,34 +357,29 @@
    return INSTANCE;
  }
  // Private constructor.
  private ServerManagementContext() {
    // No implementation required.
  }
  /**
   * Gets the named managed object.
   *
   * @param <C>
   *          The type of client managed object configuration that the
   *          path definition refers to.
     *            The type of client managed object configuration that the path
     *            definition refers to.
   * @param <S>
   *          The type of server managed object configuration that the
   *          path definition refers to.
     *            The type of server managed object configuration that the path
     *            definition refers to.
   * @param path
   *          The path of the managed object.
   * @return Returns the named managed object.
   * @throws ConfigException
   *           If the named managed object could not be found or if it
   *           could not be decoded.
     *             If the named managed object could not be found or if it could
     *             not be decoded.
   */
  @SuppressWarnings("unchecked")
  public <C extends ConfigurationClient, S extends Configuration>
  ServerManagedObject<? extends S> getManagedObject(
    public <C extends ConfigurationClient, S extends Configuration> ServerManagedObject<? extends S> getManagedObject(
      ManagedObjectPath<C, S> path) throws ConfigException {
    // Be careful to handle the root configuration.
    if (path.isEmpty()) {
@@ -471,51 +398,44 @@
      return managedObject;
    } catch (DefinitionDecodingException e) {
      throw ConfigExceptionFactory.getInstance()
          .createDecodingExceptionAdaptor(targetDN, e);
            throw ConfigExceptionFactory.getInstance().createDecodingExceptionAdaptor(targetDN, e);
    } catch (ServerManagedObjectDecodingException e) {
      throw ConfigExceptionFactory.getInstance()
          .createDecodingExceptionAdaptor(e);
            throw ConfigExceptionFactory.getInstance().createDecodingExceptionAdaptor(e);
    } catch (ConstraintViolationException e) {
      throw ConfigExceptionFactory.getInstance()
          .createDecodingExceptionAdaptor(e);
            throw ConfigExceptionFactory.getInstance().createDecodingExceptionAdaptor(e);
    }
  }
  /**
   * Gets the effective value of a property in the named managed
   * object.
     * Gets the effective value of a property in the named managed object.
   *
   * @param <C>
   *          The type of client managed object configuration that the
   *          path definition refers to.
     *            The type of client managed object configuration that the path
     *            definition refers to.
   * @param <S>
   *          The type of server managed object configuration that the
   *          path definition refers to.
     *            The type of server managed object configuration that the path
     *            definition refers to.
   * @param <PD>
   *          The type of the property to be retrieved.
   * @param path
   *          The path of the managed object containing the property.
   * @param pd
   *          The property to be retrieved.
   * @return Returns the property's effective value, or
   *         <code>null</code> if there are no values defined.
     * @return Returns the property's effective value, or <code>null</code> if
     *         there are no values defined.
   * @throws IllegalArgumentException
   *           If the property definition is not associated with the
   *           referenced managed object's definition.
   * @throws PropertyException
   *           If the managed object was found but the requested
   *           property could not be decoded.
   * @throws ConfigException
   *           If the named managed object could not be found or if it
     *             If the managed object was found but the requested property
   *           could not be decoded.
     * @throws ConfigException
     *             If the named managed object could not be found or if it could
     *             not be decoded.
   */
  public <C extends ConfigurationClient, S extends Configuration, PD>
  PD getPropertyValue(ManagedObjectPath<C, S> path,
      PropertyDefinition<PD> pd) throws IllegalArgumentException,
      ConfigException, PropertyException {
    public <C extends ConfigurationClient, S extends Configuration, PD> PD getPropertyValue(
            ManagedObjectPath<C, S> path, PropertyDefinition<PD> pd) throws IllegalArgumentException, ConfigException,
            PropertyException {
    SortedSet<PD> values = getPropertyValues(path, pd);
    if (values.isEmpty()) {
      return null;
@@ -524,48 +444,44 @@
    }
  }
  /**
   * Gets the effective values of a property in the named managed
   * object.
     * Gets the effective values of a property in the named managed object.
   *
   * @param <C>
   *          The type of client managed object configuration that the
   *          path definition refers to.
     *            The type of client managed object configuration that the path
     *            definition refers to.
   * @param <S>
   *          The type of server managed object configuration that the
   *          path definition refers to.
     *            The type of server managed object configuration that the path
     *            definition refers to.
   * @param <PD>
   *          The type of the property to be retrieved.
   * @param path
   *          The path of the managed object containing the property.
   * @param pd
   *          The property to be retrieved.
   * @return Returns the property's effective values, or an empty set
   *         if there are no values defined.
     * @return Returns the property's effective values, or an empty set if there
     *         are no values defined.
   * @throws IllegalArgumentException
   *           If the property definition is not associated with the
   *           referenced managed object's definition.
   * @throws PropertyException
   *           If the managed object was found but the requested
   *           property could not be decoded.
   * @throws ConfigException
   *           If the named managed object could not be found or if it
     *             If the managed object was found but the requested property
   *           could not be decoded.
     * @throws ConfigException
     *             If the named managed object could not be found or if it could
     *             not be decoded.
   */
  @SuppressWarnings("unchecked")
  public <C extends ConfigurationClient, S extends Configuration, PD>
  SortedSet<PD> getPropertyValues(ManagedObjectPath<C, S> path,
      PropertyDefinition<PD> pd) throws IllegalArgumentException,
      ConfigException, PropertyException {
    public <C extends ConfigurationClient, S extends Configuration, PD> SortedSet<PD> getPropertyValues(
            ManagedObjectPath<C, S> path, PropertyDefinition<PD> pd) throws IllegalArgumentException, ConfigException,
            PropertyException {
    // Check that the requested property is from the definition
    // associated with the path.
    AbstractManagedObjectDefinition<C, S> d = path.getManagedObjectDefinition();
    PropertyDefinition<?> tmp = d.getPropertyDefinition(pd.getName());
    if (tmp != pd) {
      throw new IllegalArgumentException("The property " + pd.getName()
          + " is not associated with a " + d.getName());
            throw new IllegalArgumentException("The property " + pd.getName() + " is not associated with a "
                    + d.getName());
    }
    // Determine the exact type of managed object referenced by the
@@ -579,8 +495,7 @@
    try {
      mod = d.resolveManagedObjectDefinition(resolver);
    } catch (DefinitionDecodingException e) {
      throw ConfigExceptionFactory.getInstance()
          .createDecodingExceptionAdaptor(dn, e);
            throw ConfigExceptionFactory.getInstance().createDecodingExceptionAdaptor(dn, e);
    }
    // Make sure we use the correct property definition, the
@@ -592,37 +507,30 @@
    return decodeProperty(path.asSubType(mod), pd, values, null);
  }
  /**
   * Get the root configuration manager associated with this
   * management context.
     * Get the root configuration manager associated with this management
     * context.
   *
   * @return Returns the root configuration manager associated with
   *         this management context.
     * @return Returns the root configuration manager associated with this
     *         management context.
   */
  public RootCfg getRootConfiguration() {
    return getRootConfigurationManagedObject().getConfiguration();
  }
  /**
   * Get the root configuration server managed object associated with
   * this management context.
     * Get the root configuration server managed object associated with this
     * management context.
   *
   * @return Returns the root configuration server managed object
   *         associated with this management context.
     * @return Returns the root configuration server managed object associated
     *         with this management context.
   */
  public ServerManagedObject<RootCfg> getRootConfigurationManagedObject() {
    return ROOT;
  }
  /**
   * Lists the child managed objects of the named parent managed
   * object.
     * Lists the child managed objects of the named parent managed object.
   *
   * @param <C>
   *          The type of client managed object configuration that the
@@ -636,13 +544,11 @@
   *          The instantiable relation definition.
   * @return Returns the names of the child managed objects.
   * @throws IllegalArgumentException
   *           If the relation definition is not associated with the
   *           parent managed object's definition.
     *             If the relation definition is not associated with the parent
     *             managed object's definition.
   */
  public <C extends ConfigurationClient, S extends Configuration>
  String[] listManagedObjects(
      ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd)
      throws IllegalArgumentException {
    public <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
            ManagedObjectPath<?, ?> parent, InstantiableRelationDefinition<C, S> rd) throws IllegalArgumentException {
    validateRelationDefinition(parent, rd);
    // Get the target entry.
@@ -663,18 +569,15 @@
    ArrayList<String> names = new ArrayList<String>(children.size());
    for (DN child : children) {
      // Assume that RDNs are single-valued and can be trimmed.
      AttributeValue av = child.getRDN().getAttributeValue(0);
            AttributeValue av = child.rdn().getAttributeValue(0);
      names.add(av.getValue().toString().trim());
    }
    return names.toArray(new String[names.size()]);
  }
  /**
   * Lists the child managed objects of the named parent managed
   * object.
     * Lists the child managed objects of the named parent managed object.
   *
   * @param <C>
   *          The type of client managed object configuration that the
@@ -688,13 +591,11 @@
   *          The set relation definition.
   * @return Returns the names of the child managed objects.
   * @throws IllegalArgumentException
   *           If the relation definition is not associated with the
   *           parent managed object's definition.
     *             If the relation definition is not associated with the parent
     *             managed object's definition.
   */
  public <C extends ConfigurationClient, S extends Configuration>
  String[] listManagedObjects(
      ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd)
      throws IllegalArgumentException {
    public <C extends ConfigurationClient, S extends Configuration> String[] listManagedObjects(
            ManagedObjectPath<?, ?> parent, SetRelationDefinition<C, S> rd) throws IllegalArgumentException {
    validateRelationDefinition(parent, rd);
    // Get the target entry.
@@ -715,22 +616,20 @@
    ArrayList<String> names = new ArrayList<String>(children.size());
    for (DN child : children) {
      // Assume that RDNs are single-valued and can be trimmed.
      AttributeValue av = child.getRDN().getAttributeValue(0);
            AttributeValue av = child.rdn().getAttributeValue(0);
      names.add(av.toString().trim());
    }
    return names.toArray(new String[names.size()]);
  }
  /**
   * Determines whether or not the named managed object exists.
   *
   * @param path
   *          The path of the named managed object.
   * @return Returns <code>true</code> if the named managed object
   *         exists, <code>false</code> otherwise.
     * @return Returns <code>true</code> if the named managed object exists,
     *         <code>false</code> otherwise.
   */
  public boolean managedObjectExists(ManagedObjectPath<?, ?> path) {
    // Get the configuration entry.
@@ -743,82 +642,73 @@
    }
  }
  /**
   * Decodes a configuration entry into the required type of server
   * managed object.
     * Decodes a configuration entry into the required type of server managed
     * object.
   *
   * @param <C>
   *          The type of client managed object configuration that the
   *          path definition refers to.
     *            The type of client managed object configuration that the path
     *            definition refers to.
   * @param <S>
   *          The type of server managed object configuration that the
   *          path definition refers to.
     *            The type of server managed object configuration that the path
     *            definition refers to.
   * @param path
   *          The location of the server managed object.
   * @param configEntry
   *          The configuration entry that should be decoded.
   * @return Returns the new server-side managed object from the
   *         provided definition and configuration entry.
     * @return Returns the new server-side managed object from the provided
     *         definition and configuration entry.
   * @throws DefinitionDecodingException
   *           If the managed object's type could not be determined.
   * @throws ServerManagedObjectDecodingException
   *           If one or more of the managed object's properties could
   *           not be decoded.
     *             If one or more of the managed object's properties could not
     *             be decoded.
   */
  <C extends ConfigurationClient, S extends Configuration>
  ServerManagedObject<? extends S> decode(
      ManagedObjectPath<C, S> path, ConfigEntry configEntry)
      throws DefinitionDecodingException, ServerManagedObjectDecodingException {
    <C extends ConfigurationClient, S extends Configuration> ServerManagedObject<? extends S> decode(
            ManagedObjectPath<C, S> path, ConfigEntry configEntry) throws DefinitionDecodingException,
            ServerManagedObjectDecodingException {
    return decode(path, configEntry, null);
  }
  /**
   * Decodes a configuration entry into the required type of server
   * managed object.
     * Decodes a configuration entry into the required type of server managed
     * object.
   *
   * @param <C>
   *          The type of client managed object configuration that the
   *          path definition refers to.
     *            The type of client managed object configuration that the path
     *            definition refers to.
   * @param <S>
   *          The type of server managed object configuration that the
   *          path definition refers to.
     *            The type of server managed object configuration that the path
     *            definition refers to.
   * @param path
   *          The location of the server managed object.
   * @param configEntry
   *          The configuration entry that should be decoded.
   * @param newConfigEntry
   *          Optional new configuration that does not exist yet in
   *          the configuration back-end. This will be used for
   *          resolving inherited default values.
   * @return Returns the new server-side managed object from the
   *         provided definition and configuration entry.
     *            Optional new configuration that does not exist yet in the
     *            configuration back-end. This will be used for resolving
     *            inherited default values.
     * @return Returns the new server-side managed object from the provided
     *         definition and configuration entry.
   * @throws DefinitionDecodingException
   *           If the managed object's type could not be determined.
   * @throws ServerManagedObjectDecodingException
   *           If one or more of the managed object's properties could
   *           not be decoded.
     *             If one or more of the managed object's properties could not
     *             be decoded.
   */
  <C extends ConfigurationClient, S extends Configuration>
  ServerManagedObject<? extends S> decode(
      ManagedObjectPath<C, S> path, ConfigEntry configEntry,
      ConfigEntry newConfigEntry) throws DefinitionDecodingException,
      ServerManagedObjectDecodingException {
    <C extends ConfigurationClient, S extends Configuration> ServerManagedObject<? extends S> decode(
            ManagedObjectPath<C, S> path, ConfigEntry configEntry, ConfigEntry newConfigEntry)
            throws DefinitionDecodingException, ServerManagedObjectDecodingException {
    // First determine the correct definition to use for the entry.
    // This could either be the provided definition, or one of its
    // sub-definitions.
    DefinitionResolver resolver = new MyDefinitionResolver(configEntry);
    AbstractManagedObjectDefinition<C, S> d = path.getManagedObjectDefinition();
    ManagedObjectDefinition<? extends C, ? extends S> mod = d
        .resolveManagedObjectDefinition(resolver);
        ManagedObjectDefinition<? extends C, ? extends S> mod = d.resolveManagedObjectDefinition(resolver);
    // Build the managed object's properties.
    List<PropertyException> exceptions = new LinkedList<PropertyException>();
    Map<PropertyDefinition<?>, SortedSet<?>> properties =
      new HashMap<PropertyDefinition<?>, SortedSet<?>>();
        Map<PropertyDefinition<?>, SortedSet<?>> properties = new HashMap<PropertyDefinition<?>, SortedSet<?>>();
    for (PropertyDefinition<?> pd : mod.getAllPropertyDefinitions()) {
      List<AttributeValue> values = getAttribute(mod, pd, configEntry);
      try {
@@ -831,8 +721,7 @@
    // If there were no decoding problems then return the managed
    // object, otherwise throw an operations exception.
    ServerManagedObject<? extends S> mo = decodeAux(path, mod, properties,
        configEntry);
        ServerManagedObject<? extends S> mo = decodeAux(path, mod, properties, configEntry);
    if (exceptions.isEmpty()) {
      return mo;
    } else {
@@ -840,25 +729,17 @@
    }
  }
  // Decode helper method required to avoid generics warning.
  private <C extends ConfigurationClient, S extends Configuration>
  ServerManagedObject<S> decodeAux(
      ManagedObjectPath<? super C, ? super S> path,
      ManagedObjectDefinition<C, S> d,
      Map<PropertyDefinition<?>, SortedSet<?>> properties,
      ConfigEntry configEntry) {
    private <C extends ConfigurationClient, S extends Configuration> ServerManagedObject<S> decodeAux(
            ManagedObjectPath<? super C, ? super S> path, ManagedObjectDefinition<C, S> d,
            Map<PropertyDefinition<?>, SortedSet<?>> properties, ConfigEntry configEntry) {
    ManagedObjectPath<C, S> newPath = path.asSubType(d);
    return new ServerManagedObject<S>(newPath, d, properties, configEntry);
  }
  // Create a property using the provided string values.
  private <T> SortedSet<T> decodeProperty(ManagedObjectPath<?, ?> path,
      PropertyDefinition<T> pd, List<AttributeValue> values,
      ConfigEntry newConfigEntry) throws PropertyException {
    private <T> SortedSet<T> decodeProperty(ManagedObjectPath<?, ?> path, PropertyDefinition<T> pd,
            List<AttributeValue> values, ConfigEntry newConfigEntry) throws PropertyException {
    PropertyException exception = null;
    SortedSet<T> pvalues = new TreeSet<T>(pd);
@@ -902,21 +783,17 @@
    }
  }
  // Gets the attribute associated with a property from a ConfigEntry.
  private List<AttributeValue> getAttribute(ManagedObjectDefinition<?, ?> d,
      PropertyDefinition<?> pd, ConfigEntry configEntry) {
    private List<AttributeValue> getAttribute(ManagedObjectDefinition<?, ?> d, PropertyDefinition<?> pd,
            ConfigEntry configEntry) {
    // TODO: we create a default attribute type if it is
    // undefined. We should log a warning here if this is the case
    // since the attribute should have been defined.
    String attrID = LDAPProfile.getInstance().getAttributeName(d, pd);
    AttributeType type = DirectoryServer.getAttributeType(attrID, true);
    AttributeValueDecoder<AttributeValue> decoder =
      new AttributeValueDecoder<AttributeValue>() {
        AttributeValueDecoder<AttributeValue> decoder = new AttributeValueDecoder<AttributeValue>() {
      public AttributeValue decode(AttributeValue value)
          throws DirectoryException {
            public AttributeValue decode(AttributeValue value) throws DirectoryException {
        return value;
      }
    };
@@ -931,22 +808,16 @@
    return values;
  }
  // Get the default values for the specified property.
  private <T> Collection<T> getDefaultValues(ManagedObjectPath<?, ?> p,
      PropertyDefinition<T> pd, ConfigEntry newConfigEntry)
      throws DefaultBehaviorException {
    private <T> Collection<T> getDefaultValues(ManagedObjectPath<?, ?> p, PropertyDefinition<T> pd,
            ConfigEntry newConfigEntry) throws DefaultBehaviorException {
    DefaultValueFinder<T> v = new DefaultValueFinder<T>(newConfigEntry);
    return v.find(p, pd);
  }
  // Gets a config entry required for a managed object and throws a
  // config exception on failure.
  private ConfigEntry getManagedObjectConfigEntry(
      DN dn) throws ConfigException {
    private ConfigEntry getManagedObjectConfigEntry(DN dn) throws ConfigException {
    ConfigEntry configEntry;
    try {
      configEntry = DirectoryServer.getConfigEntry(dn);
@@ -955,32 +826,29 @@
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }
      LocalizableMessage message = ERR_ADMIN_CANNOT_GET_MANAGED_OBJECT.get(
          String.valueOf(dn), stackTraceToSingleLineString(e));
            LocalizableMessage message = ERR_ADMIN_CANNOT_GET_MANAGED_OBJECT.get(String.valueOf(dn),
                    stackTraceToSingleLineString(e));
      throw new ConfigException(message, e);
    }
    // The configuration handler is free to return null indicating
    // that the entry does not exist.
    if (configEntry == null) {
      LocalizableMessage message = ERR_ADMIN_MANAGED_OBJECT_DOES_NOT_EXIST
          .get(String.valueOf(dn));
            LocalizableMessage message = ERR_ADMIN_MANAGED_OBJECT_DOES_NOT_EXIST.get(String.valueOf(dn));
      throw new ConfigException(message);
    }
    return configEntry;
  }
  // Validate that a relation definition belongs to the path.
  private void validateRelationDefinition(ManagedObjectPath<?, ?> path,
      RelationDefinition<?, ?> rd) throws IllegalArgumentException {
    private void validateRelationDefinition(ManagedObjectPath<?, ?> path, RelationDefinition<?, ?> rd)
            throws IllegalArgumentException {
    AbstractManagedObjectDefinition<?, ?> d = path.getManagedObjectDefinition();
    RelationDefinition<?, ?> tmp = d.getRelationDefinition(rd.getName());
    if (tmp != rd) {
      throw new IllegalArgumentException("The relation " + rd.getName()
          + " is not associated with a " + d.getName());
            throw new IllegalArgumentException("The relation " + rd.getName() + " is not associated with a "
                    + d.getName());
    }
  }
}