You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2016/06/21 11:46:32 UTC

svn commit: r1749491 - /directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java

Author: elecharny
Date: Tue Jun 21 11:46:32 2016
New Revision: 1749491

URL: http://svn.apache.org/viewvc?rev=1749491&view=rev
Log:
o Added a Value() constructor that takes a normalized form, to avoid a costly nomalization

Modified:
    directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java

Modified: directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java?rev=1749491&r1=1749490&r2=1749491&view=diff
==============================================================================
--- directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java (original)
+++ directory/shared/branches/shared-value/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java Tue Jun 21 11:46:32 2016
@@ -262,6 +262,7 @@ public class Value implements Cloneable,
         {
             bytes = null;
         }
+        
         try
         {
             computeNormValue();
@@ -274,6 +275,70 @@ public class Value implements Cloneable,
         
         if ( !attributeType.isRelaxed() )
         {
+            // Check the value
+            if ( attributeType.getSyntax().getSyntaxChecker() != null )
+            {
+                if ( !attributeType.getSyntax().getSyntaxChecker().isValidSyntax( upValue ) )
+                {
+                    throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, "Invalid upValue per syntax" );
+                }
+            }
+            else
+            {
+                // We should always have a SyntaxChecker
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04139_NULL_SYNTAX_CHECKER, normValue ) );
+            }
+        }
+        
+        hashCode();
+    }
+    
+    
+    /**
+     * Creates a schema aware StringValue with an initial user provided String value and 
+     * its normalized Value
+     *
+     * @param attributeType the schema type associated with this StringValue
+     * @param upValue the value to wrap
+     * @param normValue the normalized value to wrap
+     * @throws LdapInvalidAttributeValueException If the added value is invalid accordingly
+     * to the schema
+     */
+    public Value( AttributeType attributeType, String upValue, String normValue ) throws LdapInvalidAttributeValueException
+    {
+        // The AttributeType must have a Syntax
+        if ( attributeType != null )
+        {
+            if ( attributeType.getSyntax() == null )
+            {
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04445_NO_SYNTAX ) );
+            }
+            else
+            {
+                isHR = attributeType.getSyntax().isHumanReadable();
+            }
+        }
+        else
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_04488_NULL_ATTRIBUTE_TYPE ) );
+        }
+
+        this.attributeType = attributeType;
+        this.upValue = upValue;
+        
+        if ( upValue != null )
+        {
+            bytes = Strings.getBytesUtf8( upValue );
+        }
+        else
+        {
+            bytes = null;
+        }
+        
+        this.normValue = normValue;
+        
+        if ( !attributeType.isRelaxed() )
+        {
             // Check the value
             if ( attributeType.getSyntax().getSyntaxChecker() != null )
             {