From 138a3114de9e1b69a16c67f052d01270c05064d6 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 12 Dec 2013 14:27:12 +0000
Subject: [PATCH] Code cleanup in the virtual attributes.

---
 opends/src/server/org/opends/server/extensions/GoverningStructureRuleVirtualAttributeProvider.java |  114 ++++++++++++--------------------------------------------
 1 files changed, 25 insertions(+), 89 deletions(-)

diff --git a/opends/src/server/org/opends/server/extensions/GoverningStructureRuleVirtualAttributeProvider.java b/opends/src/server/org/opends/server/extensions/GoverningStructureRuleVirtualAttributeProvider.java
index 64e579a..9400a78 100644
--- a/opends/src/server/org/opends/server/extensions/GoverningStructureRuleVirtualAttributeProvider.java
+++ b/opends/src/server/org/opends/server/extensions/GoverningStructureRuleVirtualAttributeProvider.java
@@ -23,12 +23,10 @@
  *
  *
  *      Copyright 2009 Sun Microsystems, Inc.
- *      Portions Copyright 2012 ForgeRock AS
+ *      Portions Copyright 2012-2013 ForgeRock AS
  */
 package org.opends.server.extensions;
 
-
-
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
@@ -37,15 +35,12 @@
 import org.opends.server.admin.std.server.
         GoverningStructureRuleVirtualAttributeCfg;
 import org.opends.server.api.VirtualAttributeProvider;
-import org.opends.server.config.ConfigException;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.SearchOperation;
 import org.opends.server.types.*;
 
 import static org.opends.messages.ExtensionMessages.*;
 
-
-
 /**
  * This class implements a virtual attribute provider that is meant to serve
  * the governingStructuralRule operational attribute as described in RFC 4512.
@@ -65,35 +60,14 @@
     // initializeVirtualAttributeProvider method.
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override()
-  public void initializeVirtualAttributeProvider(
-                      GoverningStructureRuleVirtualAttributeCfg configuration)
-         throws ConfigException, InitializationException
-  {
-    // No initialization is required.
-  }
-
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public boolean isMultiValued()
   {
     return false;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public Set<AttributeValue> getValues(Entry entry,
                                        VirtualAttributeRule rule)
@@ -110,22 +84,14 @@
     return Collections.<AttributeValue>emptySet();
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public boolean hasValue(Entry entry, VirtualAttributeRule rule)
   {
     return getDITStructureRule(entry)!=null;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public ConditionResult matchesSubstring(Entry entry,
                                           VirtualAttributeRule rule,
@@ -137,11 +103,7 @@
     return ConditionResult.UNDEFINED;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public ConditionResult greaterThanOrEqualTo(Entry entry,
                               VirtualAttributeRule rule,
@@ -151,11 +113,7 @@
     return ConditionResult.UNDEFINED;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public ConditionResult lessThanOrEqualTo(Entry entry,
                               VirtualAttributeRule rule,
@@ -165,11 +123,7 @@
     return ConditionResult.UNDEFINED;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public ConditionResult approximatelyEqualTo(Entry entry,
                               VirtualAttributeRule rule,
@@ -179,11 +133,7 @@
     return ConditionResult.UNDEFINED;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public boolean isSearchable(VirtualAttributeRule rule,
                               SearchOperation searchOperation,
@@ -193,11 +143,7 @@
     return false;
   }
 
-
-
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override()
   public void processSearch(VirtualAttributeRule rule,
                             SearchOperation searchOperation)
@@ -209,9 +155,7 @@
     searchOperation.appendErrorMessage(message);
   }
 
-
-
-  //Checks if the entry matches the nameform.
+  /** Checks if the entry matches the nameform. */
   private boolean matchesNameForm(NameForm nameForm,
                        AcceptRejectWarn structuralPolicy,
                        Entry entry)
@@ -222,12 +166,10 @@
       // Make sure that all the required attributes are present.
       for (AttributeType t : nameForm.getRequiredAttributes())
       {
-        if (! rdn.hasAttributeType(t))
+        if (!rdn.hasAttributeType(t)
+            && structuralPolicy == AcceptRejectWarn.REJECT)
         {
-          if (structuralPolicy == AcceptRejectWarn.REJECT)
-          {
-            return false;
-          }
+          return false;
         }
       }
 
@@ -236,21 +178,17 @@
       for (int i = 0; i < numAVAs; i++)
       {
         AttributeType t = rdn.getAttributeType(i);
-        if (! nameForm.isRequiredOrOptional(t))
+        if (!nameForm.isRequiredOrOptional(t)
+            && structuralPolicy == AcceptRejectWarn.REJECT)
         {
-          if (structuralPolicy == AcceptRejectWarn.REJECT)
-          {
-            return false;
-          }
+          return false;
         }
        }
      }
     return true;
   }
 
-
-
-  //Finds the appropriate DIT structure rule for an entry.
+  /** Finds the appropriate DIT structure rule for an entry. */
   private DITStructureRule getDITStructureRule(Entry entry)
   {
     ObjectClass oc = entry.getStructuralObjectClass();
@@ -261,28 +199,26 @@
     //select the first one that matches. Since the entry exists, the same
     //algorithm should work fine to retrieve the nameform which was
     //applied while creating the entry.
-    if(listForms != null)
+    if (listForms != null)
     {
       boolean obsolete = true;
       AcceptRejectWarn structuralPolicy =
-         DirectoryServer.getSingleStructuralObjectClassPolicy();
-      for(NameForm nf : listForms)
+        DirectoryServer.getSingleStructuralObjectClassPolicy();
+      for (NameForm nf : listForms)
       {
-        if(!nf.isObsolete())
+        if (!nf.isObsolete())
         {
           obsolete = false;
-          if(matchesNameForm(nf,
-                  structuralPolicy, entry))
+          if (matchesNameForm(nf, structuralPolicy, entry))
           {
            nameForm = nf;
            break;
           }
         }
       }
-      if( nameForm != null && !obsolete)
+      if (nameForm != null && !obsolete)
       {
-        ditRule =
-                DirectoryServer.getDITStructureRule(nameForm);
+        ditRule = DirectoryServer.getDITStructureRule(nameForm);
       }
     }
     return ditRule;

--
Gitblit v1.10.0