directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1083445 - in /directory: apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/ shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/ shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18...
Date Sun, 20 Mar 2011 14:04:18 GMT
Author: elecharny
Date: Sun Mar 20 14:04:17 2011
New Revision: 1083445

URL: http://svn.apache.org/viewvc?rev=1083445&view=rev
Log:
o Cleaned up the Ava class, removing some useless methods, adding some other
o Cleaned up the Rdn class, removing some useless constructors and methods, some renaming
o Added a LdapInvalidAvaException class
o Modified an error code

Added:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidAvaException.java
Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
    directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java
    directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java
    directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/SchemaAwareRdnTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapAuthenticationNotSupportedException.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidAttributeValueException.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidDnException.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapSchemaViolationException.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapServiceUnavailableException.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapUnwillingToPerformException.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
Sun Mar 20 14:04:17 2011
@@ -549,7 +549,7 @@ public class OperationalAttributeInterce
             {
                 String name = schemaManager.lookupAttributeTypeRegistry( rdn.getNormType()
).getName();
                 String value = rdn.getNormValue().getString();
-                newDn = newDn.add( new Rdn( name, name, value, value ) );
+                newDn = newDn.add( new Rdn( name, value ) );
                 continue;
             }
 

Modified: directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java (original)
+++ directory/shared/trunk/i18n/src/main/java/org/apache/directory/shared/i18n/I18n.java Sun
Mar 20 14:04:17 2011
@@ -274,7 +274,7 @@ public enum I18n
     ERR_04137( "ERR_04137" ),
     ERR_04138( "ERR_04138" ),
     ERR_04139( "ERR_04139" ),
-    ERR_04140( "ERR_04140" ),
+    ERR_04140_UNACCEPTABLE_RESUT_CODE( "ERR_04140_UNACCEPTABLE_RESUT_CODE" ),
     ERR_04141( "ERR_04141" ),
     ERR_04142( "ERR_04142" ),
     ERR_04143( "ERR_04143" ),

Modified: directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
URL: http://svn.apache.org/viewvc/directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
(original)
+++ directory/shared/trunk/i18n/src/main/resources/org/apache/directory/shared/i18n/errors.properties
Sun Mar 20 14:04:17 2011
@@ -262,7 +262,7 @@ ERR_04136=The AttributeType list should 
 ERR_04137=The attribute ''{0}'' does not exist in the entry
 ERR_04138=The removal of values for the missing ''{0}'' attribute is not possible
 ERR_04139=Cannot validate {0} with a null SyntaxChecker
-ERR_04140=Unexceptable result code for this exception type: {0}
+ERR_04140_UNACCEPTABLE_RESUT_CODE=Unacceptable result code for this exception type: {0}
 ERR_04141={0} is not an acceptable result code.
 ERR_04142=Only UNWILLING_TO_PERFORM and UNAVAILABLE_CRITICAL_EXTENSION result codes are allowed
to be used with this exception
 ERR_04143=Only the following LDAP result codes can be used: {0}

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/DnTest.java
Sun Mar 20 14:04:17 2011
@@ -37,10 +37,6 @@ import javax.naming.ldap.LdapName;
 
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
-import org.apache.directory.shared.ldap.model.name.Ava;
-import org.apache.directory.shared.ldap.model.name.Dn;
-import org.apache.directory.shared.ldap.model.name.DnParser;
-import org.apache.directory.shared.ldap.model.name.Rdn;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
 import org.apache.directory.shared.util.Strings;
@@ -906,7 +902,7 @@ public class DnTest
     {
         Dn dn = new Dn( "a=b, c=d,e = f" );
 
-        Dn res = dn.getAncestorOf( "a=z" );
+         dn.getAncestorOf( "a=z" );
     }
 
 
@@ -2612,7 +2608,7 @@ public class DnTest
         assertEquals( "cn=loopback+iphostnumber=127.0.0.1,ou=Hosts,dc=mygfs,dc=com", dn1.getNormName()
);
         assertEquals( "cn=loopback+ipHostNumber=127.0.0.1", dn1.getRdn().getName() );
         assertEquals( "cn=loopback+iphostnumber=127.0.0.1", dn1.getRdn().getNormName() );
-        assertEquals( "127.0.0.1", dn1.getRdn().getAttributeTypeAndValue( "ipHostNumber"
).getUpValue().get() );
+        assertEquals( "127.0.0.1", dn1.getRdn().getAva( "ipHostNumber" ).getUpValue().get()
);
 
         // numeric OID with suffix
         Dn dn2 = new Dn( "cn=loopback+ipHostNumber=X127.0.0.1,ou=Hosts,dc=mygfs,dc=com" );
@@ -2696,7 +2692,7 @@ public class DnTest
 
         assertEquals( "  ou  =  Example ", atav.getUpName() );
 
-        assertEquals( 2, rdn.getNbAtavs() );
+        assertEquals( 2, rdn.size() );
 
         // The second ATAV
         for ( Ava ava : rdn )
@@ -2781,7 +2777,7 @@ public class DnTest
         assertEquals( "Ex+mple", atav.getUpValue().get() );
         assertEquals( "Ex+mple", atav.getNormValue().get() );
 
-        assertEquals( 2, rdn.getNbAtavs() );
+        assertEquals( 2, rdn.size() );
 
         // The second ATAV
         for ( Ava ava : rdn )
@@ -2832,7 +2828,7 @@ public class DnTest
         assertEquals( "Ex+mple", atav.getUpValue().get() );
         assertEquals( "ex+mple", atav.getNormValue().get() );
 
-        assertEquals( 2, rdn.getNbAtavs() );
+        assertEquals( 2, rdn.size() );
 
         // The second ATAV
         for ( Ava ava : rdn )

Modified: directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/SchemaAwareRdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/SchemaAwareRdnTest.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/SchemaAwareRdnTest.java
(original)
+++ directory/shared/trunk/integ/src/test/java/org/apache/directory/shared/ldap/model/name/SchemaAwareRdnTest.java
Sun Mar 20 14:04:17 2011
@@ -303,7 +303,7 @@ public class SchemaAwareRdnTest
     @Test
     public void testRDNCloningOneNameComponent() throws LdapException
     {
-        Rdn rdn = new Rdn( schemaManager, "CN", "cn", "B", "b" );
+        Rdn rdn = new Rdn( schemaManager, "CN", "B" );
 
         Rdn rdnClone = (Rdn) rdn.clone();
 

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapAuthenticationNotSupportedException.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapAuthenticationNotSupportedException.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapAuthenticationNotSupportedException.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapAuthenticationNotSupportedException.java
Sun Mar 20 14:04:17 2011
@@ -82,7 +82,7 @@ public class LdapAuthenticationNotSuppor
                 return;
                 
             default:
-                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140, resultCode
) );
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESUT_CODE,
resultCode ) );
         }
     }
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidAttributeValueException.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidAttributeValueException.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidAttributeValueException.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidAttributeValueException.java
Sun Mar 20 14:04:17 2011
@@ -80,7 +80,7 @@ public class LdapInvalidAttributeValueEx
                 return;
                 
             default:
-                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140, resultCode
) );
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESUT_CODE,
resultCode ) );
         }
     }
 }

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidAvaException.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidAvaException.java?rev=1083445&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidAvaException.java
(added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidAvaException.java
Sun Mar 20 14:04:17 2011
@@ -0,0 +1,97 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.model.exception;
+
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+
+
+/**
+ * A subclass of {@link LdapOperationException} designed to hold an unequivocal LDAP
+ * result code. It's used to represent an error when dealing with a wrong Ava.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapInvalidAvaException extends LdapOperationException
+{
+    /** The serial version UUID */
+    static final long serialVersionUID = 1L;
+
+    
+    /**
+     * Creates a new instance of LdapInvalidAvaException.
+     * 
+     * @param message The exception message
+     */
+    public LdapInvalidAvaException( String message )
+    {
+        super( message );
+    }
+    
+    
+    /**
+     * Creates a new instance of LdapInvalidAvaException.
+     *
+     * @param resultCode the ResultCodeEnum for this exception
+     * @param message The exception message
+     */
+    public LdapInvalidAvaException(  ResultCodeEnum resultCode, String message )
+    {
+        super( message );
+        checkResultCode( resultCode );
+        this.resultCode = resultCode;
+    }
+
+
+    /**
+     * Creates a new instance of LdapInvalidAvaException.
+     * 
+     * @param resultCode the ResultCodeEnum for this exception
+     */
+    public LdapInvalidAvaException( ResultCodeEnum resultCode )
+    {
+        super( null );
+        checkResultCode( resultCode );
+        this.resultCode = resultCode;
+    }
+
+
+    /**
+     * Checks to make sure the resultCode value is right for this exception
+     * type.
+     * 
+     * @throws IllegalArgumentException
+     *             if the result code is not one of
+     *             {@link ResultCodeEnum#INVALID_DN_SYNTAX},
+     *             {@link ResultCodeEnum#NAMING_VIOLATION}.
+     */
+    private void checkResultCode( ResultCodeEnum resultCode )
+    {
+        switch ( resultCode )
+        {
+            case INVALID_DN_SYNTAX :
+            case NAMING_VIOLATION :
+                return;
+                
+            default:
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESUT_CODE,
resultCode ) );
+        }
+    }
+}

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidDnException.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidDnException.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidDnException.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapInvalidDnException.java
Sun Mar 20 14:04:17 2011
@@ -89,7 +89,7 @@ public class LdapInvalidDnException exte
                 return;
                 
             default:
-                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140, resultCode
) );
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESUT_CODE,
resultCode ) );
         }
     }
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapSchemaViolationException.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapSchemaViolationException.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapSchemaViolationException.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapSchemaViolationException.java
Sun Mar 20 14:04:17 2011
@@ -82,7 +82,7 @@ public class LdapSchemaViolationExceptio
                 return;
                 
             default:
-                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140, resultCode
) );
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESUT_CODE,
resultCode ) );
         }
     }
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapServiceUnavailableException.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapServiceUnavailableException.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapServiceUnavailableException.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapServiceUnavailableException.java
Sun Mar 20 14:04:17 2011
@@ -81,7 +81,7 @@ public class LdapServiceUnavailableExcep
                 return;
                 
             default:
-                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140, resultCode
) );
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESUT_CODE,
resultCode ) );
         }
     }
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapUnwillingToPerformException.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapUnwillingToPerformException.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapUnwillingToPerformException.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/exception/LdapUnwillingToPerformException.java
Sun Mar 20 14:04:17 2011
@@ -101,7 +101,7 @@ public class LdapUnwillingToPerformExcep
                 return;
 
             default:
-                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140, resultCode
) );
+                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESUT_CODE,
resultCode ) );
         }
     }
 }

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Ava.java
Sun Mar 20 14:04:17 2011
@@ -46,11 +46,9 @@ import org.slf4j.LoggerFactory;
  * and trailing spaces MUST have been trimmed before. The value MUST be in UTF8
  * format, according to RFC 2253. If the type is in OID form, then the value
  * must be a hexadecimal string prefixed by a '#' character. Otherwise, the
- * string must respect the RC 2253 grammar. No further normalization will be
- * done, because we don't have any knowledge of the Schema definition in the
- * parser.
+ * string must respect the RC 2253 grammar. 
  *
- * We will also keep a User Provided form of the atav (Attribute Type And Value),
+ * We will also keep a User Provided form of the AVA (Attribute Type And Value),
  * called upName.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -72,9 +70,6 @@ public final class Ava implements Extern
     /** The normalized Name type */
     private String normType;
     
-    /** The attributeType if the Ava is schemaAware */
-    private AttributeType attributeType;
-
     /** The user provided Name type */
     private String upType;
 
@@ -87,6 +82,9 @@ public final class Ava implements Extern
     /** The user provided Ava */
     private String upName;
 
+    /** The attributeType if the Ava is schemaAware */
+    private AttributeType attributeType;
+
     /** the schema manager */
     private SchemaManager schemaManager;
 
@@ -95,16 +93,14 @@ public final class Ava implements Extern
      */
     public Ava()
     {
-        normType = null;
-        upType = null;
-        normValue = null;
-        upValue = null;
-        upName = "";
+        this( null );
     }
 
     
     /**
-     * Constructs an empty schema aware Ava
+     * Constructs an empty schema aware Ava.
+     * 
+     * @param schemaManager The SchemaManager instance
      */
     public Ava( SchemaManager schemaManager )
     {
@@ -114,21 +110,37 @@ public final class Ava implements Extern
         upValue = null;
         upName = "";
         this.schemaManager = schemaManager;
+        this.attributeType = null;
+    }
+    
+    
+    /**
+     * Construct an Ava containing a binary value. 
+     * <p>
+     * Note that the upValue should <b>not</b> be null or empty, or resolve
+     * to an empty string after having trimmed it. 
+     *
+     * @param upType The User Provided type
+     * @param upValue The User Provided value
+     */
+    public Ava( String upType, byte[] upValue ) throws LdapInvalidDnException
+    {
+        this( null, upType, upValue );
     }
 
     
     /**
-     * Construct an Ava. The type and value are normalized :
-     * <li> the type is trimmed and lowercased </li>
-     * <li> the value is trimmed </li>
+     * Construct aschma aware Ava containing a binary value. The AttributeType
+     * and value will be normalized accordingly to the given SchemaManager.
      * <p>
-     * Note that the upValue should <b>not</b> be null or empty, or resolved
+     * Note that the upValue should <b>not</b> be null or empty, or resolve
      * to an empty string after having trimmed it. 
      *
+     * @param schemaManager The SchemaManager instance
      * @param upType The User Provided type
-     * @param normType The normalized type
      * @param upValue The User Provided value
-     * @param normValue The normalized value
+     * 
+     * @throws LdapInvalidAvaException If the given type or value are invalid
      */
     public Ava( SchemaManager schemaManager, String upType, byte[] upValue ) throws LdapInvalidDnException
     {
@@ -167,6 +179,25 @@ public final class Ava implements Extern
      * @param upValue The User Provided value
      * @param normValue The normalized value
      */
+    public Ava( String upType, String upValue ) throws LdapInvalidDnException
+    {
+        this( null, upType, upValue );
+    }
+    
+    
+    /**
+     * Construct an Ava. The type and value are normalized :
+     * <li> the type is trimmed and lowercased </li>
+     * <li> the value is trimmed </li>
+     * <p>
+     * Note that the upValue should <b>not</b> be null or empty, or resolved
+     * to an empty string after having trimmed it. 
+     *
+     * @param upType The User Provided type
+     * @param normType The normalized type
+     * @param upValue The User Provided value
+     * @param normValue The normalized value
+     */
     public Ava( SchemaManager schemaManager, String upType, String upValue ) throws LdapInvalidDnException
     {
         if ( schemaManager != null )
@@ -369,7 +400,7 @@ public final class Ava implements Extern
      * @param normValue The normalized value
      * @param upName The User Provided name (may be escaped)
      */
-    /* No qualifier */ Ava(String upType, String normType, Value<?> upValue, Value<?>
normValue, String upName)
+    /* No qualifier */ Ava( String upType, String normType, Value<?> upValue, Value<?>
normValue, String upName )
         throws LdapInvalidDnException
     {
         String upTypeTrimmed = Strings.trim(upType);
@@ -409,6 +440,58 @@ public final class Ava implements Extern
         this.upName = upName;
     }
 
+    
+    /**
+     * Apply a SchemaManager to the Ava. It will normalize the Ava.<br/>
+     * If the Ava already had a SchemaManager, then the new SchemaManager will be
+     * used instead.
+     * 
+     * @param schemaManager The SchemaManager instance to use
+     * @throws LdapInvalidDnException If the Ava can't be normalized accordingly
+     * to the given SchemaManager
+     */
+    public void applySchemaManager( SchemaManager schemaManager ) throws LdapInvalidDnException
+    {
+        if ( schemaManager != null )
+        { 
+            this.schemaManager = schemaManager;
+            
+            try
+            {
+                attributeType = schemaManager.lookupAttributeTypeRegistry( upType );
+            }
+            catch ( LdapException le )
+            {
+                String message =  I18n.err( I18n.ERR_04188 );
+                LOG.error( message );
+                throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, message
);
+            }
+            
+            normType = attributeType.getOid();
+
+            try
+            {
+                // We use the Equality matching rule to normalize the value
+                MatchingRule equalityMatchingRule = attributeType.getEquality();
+                
+                if ( equalityMatchingRule != null )
+                {
+                    this.normValue = equalityMatchingRule.getNormalizer().normalize( upValue
);
+                }
+                else
+                {
+                    this.normValue = upValue;
+                }
+            }
+            catch ( LdapException le )
+            {
+                String message =  I18n.err( I18n.ERR_04188 );
+                LOG.error( message );
+                throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, message
);
+            }
+        }
+    }
+    
 
     /**
      * Get the normalized type of a Ava
@@ -888,13 +971,13 @@ public final class Ava implements Extern
     
     
     /**
-     * Get the associated SchemaManager if any.
+     * Tells if the Ava is schema aware or not
      * 
-     * @return The SchemaManager
+     * @return true if the Ava is schema aware
      */
-    public SchemaManager getSchemaManager()
+    public boolean isSchemaAware()
     {
-        return schemaManager;
+        return attributeType != null;
     }
     
     

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
Sun Mar 20 14:04:17 2011
@@ -25,7 +25,6 @@ import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -272,58 +271,6 @@ public final class Rdn implements Clonea
     /**
      * A constructor that constructs a Rdn from a type and a value. Constructs
      * an Rdn from the given attribute type and value. The string attribute
-     * values are not interpreted as RFC 4514 formatted Rdn strings. That is,
-     * the values are used literally (not parsed) and assumed to be un-escaped.
-     *
-     * @param upType the user provided type of the Rdn
-     * @param upValue the user provided value of the Rdn
-     * @param normType the normalized provided type of the Rdn
-     * @param normValue the normalized provided value of the Rdn
-     * @param schemaManager the schema manager
-     * @throws LdapInvalidDnException if the Rdn is invalid
-     */
-    public Rdn( SchemaManager schemaManager, String upType, String normType, String upValue,
String normValue ) throws LdapInvalidDnException
-    {
-        this.schemaManager = schemaManager;
-
-        addAVA( schemaManager, upType, normType, new StringValue( upValue ), new StringValue(
normValue ) );
-
-        upName = upType + '=' + upValue;
-
-        // create the internal normalized form
-        normalize();
-
-        if( schemaManager != null )
-        {
-            normalized = true;
-        }
-        else
-        {
-            // As strange as it seems, the Rdn is *not* normalized against the schema at
this point
-            normalized = false;
-        }
-    }
-
-
-    /**
-     * A constructor that constructs a Rdn from a type and a value.
-     *
-     * @param upType the user provided type of the Rdn
-     * @param upValue the user provided value of the Rdn
-     * @param normType the normalized provided type of the Rdn
-     * @param normValue the normalized provided value of the Rdn
-     * @throws LdapInvalidDnException if the Rdn is invalid
-     * @see #Rdn(String, String, String, String, SchemaManager)
-     */
-    public Rdn( String upType, String normType, String upValue, String normValue ) throws
LdapInvalidDnException
-    {
-        this( null, upType, normType, upValue, normValue );
-    }
-
-
-    /**
-     * A constructor that constructs a Rdn from a type and a value. Constructs
-     * an Rdn from the given attribute type and value. The string attribute
      * values are not interpreted as RFC 414 formatted Rdn strings. That is,
      * the values are used literally (not parsed) and assumed to be un-escaped.
      *
@@ -377,12 +324,12 @@ public final class Rdn implements Clonea
      */
     public Rdn( Rdn rdn )
     {
-        nbAtavs = rdn.getNbAtavs();
+        nbAtavs = rdn.size();
         this.normName = rdn.normName;
         this.upName = rdn.getName();
         normalized = rdn.normalized;
 
-        switch ( rdn.getNbAtavs() )
+        switch ( rdn.size() )
         {
             case 0:
                 return;
@@ -494,43 +441,6 @@ public final class Rdn implements Clonea
     }
     
     
-    /* no qualifier */ Rdn( SchemaManager schemaManager, String upName, String normName,
Ava... atavs )
-    {
-        this.upName = upName;
-        this.normName = normName;
-        this.schemaManager = schemaManager;
-        this.normalized = (schemaManager != null );
-        
-        if ( atavs != null )
-        {
-            nbAtavs = atavs.length;
-            
-            switch ( nbAtavs )
-            {
-                case 0 :
-                    break;
-                    
-                case 1 :
-                    atav = atavs[ 0 ];
-                    atavTypes.put( atav.getUpType(), atav );
-                    atavTypes.put( atav.getNormType(), atav );
-                    break;
-                    
-                default :
-                    this.atavs = Arrays.asList( atavs );
-                    
-                    for ( Ava ava : atavs )
-                    {
-                        atavTypes.put( ava.getUpType(), ava );
-                        atavTypes.put( ava.getNormType(), ava );
-                    }
-                    
-                    break;
-            }
-        }
-    }
-
-
     /**
      * Add a AttributeTypeAndValue to the current Rdn
      *
@@ -657,7 +567,7 @@ public final class Rdn implements Clonea
     // WARNING : The protection level is left unspecified intentionally.
     // We need this method to be visible from the DnParser class, but not
     // from outside this package.
-    /* No protection */void clear()
+    /* No protection */ void clear()
     {
         atav = null;
         atavs = null;
@@ -745,7 +655,7 @@ public final class Rdn implements Clonea
      *            The type of the NameArgument to be returned
      * @return The AttributeTypeAndValue, of null if none is found.
      */
-    public Ava getAttributeTypeAndValue( String type )
+    public Ava getAva( String type )
     {
         // First, let's normalize the type
         String normalizedType = Strings.lowerCaseAscii(Strings.trim(type));
@@ -833,7 +743,7 @@ public final class Rdn implements Clonea
 
             // The AttributeTypeAndValue is immutable. We won't clone it
 
-            switch ( rdn.getNbAtavs() )
+            switch ( rdn.size() )
             {
                 case 0:
                     break;
@@ -898,15 +808,6 @@ public final class Rdn implements Clonea
 
 
     /**
-     * @return Returns the nbAtavs.
-     */
-    public int getNbAtavs()
-    {
-        return nbAtavs;
-    }
-
-
-    /**
      * Return the unique AttributeTypeAndValue, or the first one of we have more
      * than one
      *
@@ -1591,18 +1492,8 @@ public final class Rdn implements Clonea
     
     
     /**
-     * Get the associated SchemaManager if any.
-     * 
-     * @return The SchemaManager
-     */
-    public SchemaManager getSchemaManager()
-    {
-        return schemaManager;
-    }
-
-
-    /**
-     * @return a String representation of the Rdn
+     * @return a String representation of the Rdn. The caller will get back the user
+     * provided Rdn
      */
     public String toString()
     {

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java?rev=1083445&r1=1083444&r2=1083445&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
Sun Mar 20 14:04:17 2011
@@ -294,7 +294,7 @@ public class RdnTest
     @Test
     public void testRDNCloningOneNameComponent() throws LdapException
     {
-        Rdn rdn = new Rdn( "a", "a", "b", "b" );
+        Rdn rdn = new Rdn( "a", "b" );
 
         Rdn rdnClone = (Rdn) rdn.clone();
 



Mime
View raw message