From 6fa0b021682d98ef9f908dfa248985a8507c6fa0 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Mon, 17 Sep 2007 15:43:08 +0000
Subject: [PATCH] Implement a new configuration definition called "TopCfgDefn" which acts as the parent of all other configuration definitions. This is analogous to the the "top" object class in LDAP.

---
 opends/src/server/org/opends/server/admin/AbstractManagedObjectDefinition.java |   83 +++++++++++++++++++++++++++++++++++------
 1 files changed, 70 insertions(+), 13 deletions(-)

diff --git a/opends/src/server/org/opends/server/admin/AbstractManagedObjectDefinition.java b/opends/src/server/org/opends/server/admin/AbstractManagedObjectDefinition.java
index 67e8249..960ff99 100644
--- a/opends/src/server/org/opends/server/admin/AbstractManagedObjectDefinition.java
+++ b/opends/src/server/org/opends/server/admin/AbstractManagedObjectDefinition.java
@@ -43,6 +43,7 @@
 
 import org.opends.messages.Message;
 import org.opends.server.admin.DefinitionDecodingException.Reason;
+import org.opends.server.util.Validator;
 
 
 
@@ -108,11 +109,24 @@
    * @param name
    *          The name of the definition.
    * @param parent
-   *          The parent definition, or <code>null</code> if there is no
-   *          parent.
+   *          The parent definition, or <code>null</code> if there
+   *          is no parent (only the {@link TopCfgDefn} should have a
+   *          <code>null</code> parent}.
    */
   protected AbstractManagedObjectDefinition(String name,
       AbstractManagedObjectDefinition<? super C, ? super S> parent) {
+    // Perform sanity checks.
+    if (this.getClass() == TopCfgDefn.class) {
+      Validator.ensureTrue(name.equals("top"),
+          "TopCfgDefn should have the name 'top'");
+      Validator.ensureTrue(parent == null,
+          "TopCfgDefn should not have a parent");
+    } else {
+      Validator.ensureTrue(!name.equals("top"),
+          "Only the TopCfgDefn should have the name 'top'");
+      Validator.ensureTrue(parent != null, "No parent defined");
+    }
+
     this.name = name;
     this.parent = parent;
     this.constraints = new LinkedList<Constraint>();
@@ -309,8 +323,11 @@
    * @return Returns the description of this managed object definition
    *         in the default locale, or <code>null</code> if there is
    *         no description.
+   * @throws UnsupportedOperationException
+   *           If this managed object definition is the
+   *           {@link TopCfgDefn}.
    */
-  public final Message getDescription() {
+  public final Message getDescription() throws UnsupportedOperationException {
     return getDescription(Locale.getDefault());
   }
 
@@ -325,11 +342,15 @@
    * @return Returns the description of this managed object definition
    *         in the specified locale, or <code>null</code> if there
    *         is no description.
+   * @throws UnsupportedOperationException
+   *           If this managed object definition is the
+   *           {@link TopCfgDefn}.
    */
-  public final Message getDescription(Locale locale) {
+  public final Message getDescription(Locale locale)
+      throws UnsupportedOperationException {
     try {
       return ManagedObjectDefinitionI18NResource.getInstance()
-          .getMessage(this, "description", locale);
+        .getMessage(this, "description", locale);
     } catch (MissingResourceException e) {
       return null;
     }
@@ -352,8 +373,8 @@
    * Get the parent managed object definition, if applicable.
    *
    * @return Returns the parent of this managed object definition, or
-   *         <code>null</code> if this definition does not have a
-   *         parent.
+   *         <code>null</code> if this definition is the
+   *         {@link TopCfgDefn}.
    */
   public final AbstractManagedObjectDefinition<? super C,
       ? super S> getParent() {
@@ -459,8 +480,11 @@
    *
    * @return Returns the synopsis of this managed object definition in
    *         the default locale.
+   * @throws UnsupportedOperationException
+   *           If this managed object definition is the
+   *           {@link TopCfgDefn}.
    */
-  public final Message getSynopsis() {
+  public final Message getSynopsis() throws UnsupportedOperationException {
     return getSynopsis(Locale.getDefault());
   }
 
@@ -474,8 +498,12 @@
    *          The locale.
    * @return Returns the synopsis of this managed object definition in
    *         the specified locale.
+   * @throws UnsupportedOperationException
+   *           If this managed object definition is the
+   *           {@link TopCfgDefn}.
    */
-  public final Message getSynopsis(Locale locale) {
+  public final Message getSynopsis(Locale locale)
+      throws UnsupportedOperationException {
     return ManagedObjectDefinitionI18NResource.getInstance()
         .getMessage(this, "synopsis", locale);
   }
@@ -488,8 +516,12 @@
    *
    * @return Returns the user friendly name of this managed object
    *         definition in the default locale.
+   * @throws UnsupportedOperationException
+   *           If this managed object definition is the
+   *           {@link TopCfgDefn}.
    */
-  public final Message getUserFriendlyName() {
+  public final Message getUserFriendlyName()
+      throws UnsupportedOperationException {
     return getUserFriendlyName(Locale.getDefault());
   }
 
@@ -503,8 +535,12 @@
    *          The locale.
    * @return Returns the user friendly name of this managed object
    *         definition in the specified locale.
+   * @throws UnsupportedOperationException
+   *           If this managed object definition is the
+   *           {@link TopCfgDefn}.
    */
-  public final Message getUserFriendlyName(Locale locale) {
+  public final Message getUserFriendlyName(Locale locale)
+      throws UnsupportedOperationException {
     // TODO: have admin framework getMessage return a Message
     return Message.raw(ManagedObjectDefinitionI18NResource.getInstance()
         .getMessage(this, "user-friendly-name", locale));
@@ -518,8 +554,12 @@
    *
    * @return Returns the user friendly plural name of this managed
    *         object definition in the default locale.
+   * @throws UnsupportedOperationException
+   *           If this managed object definition is the
+   *           {@link TopCfgDefn}.
    */
-  public final Message getUserFriendlyPluralName() {
+  public final Message getUserFriendlyPluralName()
+      throws UnsupportedOperationException {
     return getUserFriendlyPluralName(Locale.getDefault());
   }
 
@@ -533,8 +573,12 @@
    *          The locale.
    * @return Returns the user friendly plural name of this managed
    *         object definition in the specified locale.
+   * @throws UnsupportedOperationException
+   *           If this managed object definition is the
+   *           {@link TopCfgDefn}.
    */
-  public final Message getUserFriendlyPluralName(Locale locale) {
+  public final Message getUserFriendlyPluralName(Locale locale)
+      throws UnsupportedOperationException {
     return ManagedObjectDefinitionI18NResource.getInstance()
         .getMessage(this, "user-friendly-plural-name", locale);
   }
@@ -616,6 +660,19 @@
 
 
   /**
+   * Determines whether or not this managed object definition is the
+   * {@link TopCfgDefn}.
+   *
+   * @return Returns <code>true</code> if this managed object
+   *         definition is the {@link TopCfgDefn}.
+   */
+  public final boolean isTop() {
+    return (this == TopCfgDefn.getInstance());
+  }
+
+
+
+  /**
    * Finds a sub-type of this managed object definition which most closely
    * corresponds to the matching criteria of the provided definition resolver.
    *

--
Gitblit v1.10.0