From 2d7aad2c25507ea427980b54848c26594c607ae2 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 20 Feb 2014 11:20:22 +0000
Subject: [PATCH] OPENDJ-1308 Migrate schema support

---
 opendj3-server-dev/src/server/org/opends/server/schema/NumericStringSubstringMatchingRule.java |   43 ++++++++++++++++++++++++-------------------
 1 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/schema/NumericStringSubstringMatchingRule.java b/opendj3-server-dev/src/server/org/opends/server/schema/NumericStringSubstringMatchingRule.java
index 52870c2..d9bf586 100644
--- a/opendj3-server-dev/src/server/org/opends/server/schema/NumericStringSubstringMatchingRule.java
+++ b/opendj3-server-dev/src/server/org/opends/server/schema/NumericStringSubstringMatchingRule.java
@@ -35,10 +35,9 @@
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.opendj.ldap.ByteSequence;
 import org.forgerock.opendj.ldap.ByteString;
+import org.forgerock.opendj.ldap.DecodeException;
 import org.opends.server.api.SubstringMatchingRule;
 import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.DirectoryException;
-import org.forgerock.opendj.ldap.ResultCode;
 
 import static org.opends.messages.SchemaMessages.*;
 import static org.opends.server.schema.SchemaConstants.*;
@@ -127,12 +126,12 @@
    *
    * @return  The normalized version of the provided value.
    *
-   * @throws  DirectoryException  If the provided value is invalid according to
+   * @throws  DecodeException  If the provided value is invalid according to
    *                              the associated attribute syntax.
    */
   @Override
   public ByteString normalizeAttributeValue(ByteSequence value)
-         throws DirectoryException
+         throws DecodeException
   {
     StringBuilder buffer = new StringBuilder();
     prepareUnicode(buffer, value, TRIM, NO_CASE_FOLD);
@@ -153,19 +152,7 @@
           // This is an illegal character.  Either log it or reject it.
           LocalizableMessage message = WARN_ATTR_SYNTAX_NUMERIC_STRING_ILLEGAL_CHAR.get(
                   value, c, pos);
-
-          switch (DirectoryServer.getSyntaxEnforcementPolicy())
-          {
-            case REJECT:
-              throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX,
-                                           message);
-            case WARN:
-              if (! logged)
-              {
-                logger.error(message);
-                logged = true;
-              }
-          }
+          logged = reportInvalidSyntax(logged, message);
         }
       }
     }
@@ -178,6 +165,24 @@
 
 
 
+  private boolean reportInvalidSyntax(boolean logged, LocalizableMessage message)
+      throws DecodeException
+  {
+    switch (DirectoryServer.getSyntaxEnforcementPolicy())
+    {
+      case REJECT:
+        throw DecodeException.error(message);
+      case WARN:
+        if (! logged)
+        {
+          logger.error(message);
+          logged = true;
+        }
+        break;
+    }
+    return logged;
+  }
+
   /**
    * Normalizes the provided value fragment into a form that can be used to
    * efficiently compare values.
@@ -186,12 +191,12 @@
    *
    * @return  The normalized form of the value fragment.
    *
-   * @throws  DirectoryException  If the provided value fragment is not
+   * @throws  DecodeException  If the provided value fragment is not
    *                              acceptable according to the associated syntax.
    */
   @Override
   public ByteString normalizeSubstring(ByteSequence substring)
-         throws DirectoryException
+         throws DecodeException
   {
     return normalizeAttributeValue(substring);
   }

--
Gitblit v1.10.0