From a632fbfad0ddbe8b343c6abe8e28dc41e3df9b7e Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 10 Jul 2015 10:16:25 +0000
Subject: [PATCH] Code cleanup

---
 opendj-server-legacy/src/main/java/org/opends/server/schema/MatchingRuleUseSyntax.java |   63 +++++++++++--------------------
 1 files changed, 22 insertions(+), 41 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/schema/MatchingRuleUseSyntax.java b/opendj-server-legacy/src/main/java/org/opends/server/schema/MatchingRuleUseSyntax.java
index a3c5f53..4601b88 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/schema/MatchingRuleUseSyntax.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/schema/MatchingRuleUseSyntax.java
@@ -395,29 +395,9 @@
           {
             StringBuilder woidBuffer = new StringBuilder();
             pos = readWOID(lowerStr, woidBuffer, (pos));
+            attrs.add(getAttributeType(schema, allowUnknownElements, oid, woidBuffer));
 
-            AttributeType attr = schema.getAttributeType(woidBuffer.toString());
-            if (attr == null)
-            {
-              // This isn't good because it means that the matching rule use
-              // specifies an attribute type that we don't know anything about.
-              if (allowUnknownElements)
-              {
-                attr = DirectoryServer.getDefaultAttributeType(
-                                            woidBuffer.toString());
-              }
-              else
-              {
-                throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
-                    ERR_ATTR_SYNTAX_MRUSE_UNKNOWN_ATTR.get(oid, woidBuffer));
-              }
-            }
-
-            attrs.add(attr);
-
-
-            // The next character must be either a dollar sign or a closing
-            // parenthesis.
+            // The next character must be either a dollar sign or a closing parenthesis.
             c = valueStr.charAt(pos++);
             if (c == ')')
             {
@@ -436,25 +416,7 @@
         {
           StringBuilder woidBuffer = new StringBuilder();
           pos = readWOID(lowerStr, woidBuffer, (pos-1));
-
-          AttributeType attr = schema.getAttributeType(woidBuffer.toString());
-          if (attr == null)
-          {
-            // This isn't good because it means that the matching rule use
-            // specifies an attribute type that we don't know anything about.
-            if (allowUnknownElements)
-            {
-              attr = DirectoryServer.getDefaultAttributeType(
-                                          woidBuffer.toString());
-            }
-            else
-            {
-              throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
-                  ERR_ATTR_SYNTAX_MRUSE_UNKNOWN_ATTR.get(oid, woidBuffer));
-            }
-          }
-
-          attrs.add(attr);
+          attrs.add(getAttributeType(schema, allowUnknownElements, oid, woidBuffer));
         }
 
         attributes = new LinkedHashSet<>(attrs);
@@ -486,6 +448,25 @@
                                extraProperties);
   }
 
+  private static AttributeType getAttributeType(
+      Schema schema, boolean allowUnknownElements, String oid, StringBuilder woidBuffer) throws DirectoryException
+  {
+    String woidString = woidBuffer.toString();
+    AttributeType attr = schema.getAttributeType(woidString);
+    if (attr == null)
+    {
+      // This isn't good because it means that the matching rule use
+      // refers to an attribute type that we don't know anything about.
+      if (!allowUnknownElements)
+      {
+        throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
+            ERR_ATTR_SYNTAX_MRUSE_UNKNOWN_ATTR.get(oid, woidString));
+      }
+      attr = DirectoryServer.getDefaultAttributeType(woidString);
+    }
+    return attr;
+  }
+
   /**
    * Reads the next token name from the matching rule use definition, skipping
    * over any leading or trailing spaces, and appends it to the provided buffer.

--
Gitblit v1.10.0