directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r898353 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/codec/ main/java/org/apache/directory/shared/ldap/codec/actions/ main/java/org/apache/directory/shared/ldap/name/ test/java/org/apache/directory/share...
Date Tue, 12 Jan 2010 15:04:23 GMT
Author: elecharny
Date: Tue Jan 12 15:04:23 2010
New Revision: 898353

URL: http://svn.apache.org/viewvc?rev=898353&view=rev
Log:
o Removed some of the LdapDN constructors
o Updated the tests and the code to reflect this change

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java?rev=898353&r1=898352&r2=898353&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/LdapMessageGrammar.java
Tue Jan 12 15:04:23 2010
@@ -369,14 +369,15 @@
                     else
                     {
                         byte[] dnBytes = tlv.getValue().getData();
+                        String dnStr = StringTools.utf8ToString( dnBytes );
 
                         try
                         {
-                            entry = new LdapDN( dnBytes );
+                            entry = new LdapDN( dnStr );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "The DN to delete : " + StringTools.utf8ToString(
dnBytes ) + " ("
+                            String msg = "The DN to delete : " + dnStr + " ("
                                 + StringTools.dumpBytes( dnBytes ) + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
 
@@ -598,15 +599,16 @@
                     else
                     {
                         byte[] dnBytes = tlv.getValue().getData();
+                        String dnStr = StringTools.utf8ToString( dnBytes );
 
                         try
                         {
-                            LdapDN dn = new LdapDN( dnBytes );
+                            LdapDN dn = new LdapDN( dnStr );
                             bindRequestMessage.setName( dn );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "Incorrect DN given : " + StringTools.utf8ToString(
dnBytes ) + " ("
+                            String msg = "Incorrect DN given : " + dnStr + " ("
                                 + StringTools.dumpBytes( dnBytes ) + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
 
@@ -1179,10 +1181,11 @@
                     else
                     {
                         byte[] dnBytes = tlv.getValue().getData();
+                        String dnStr = StringTools.utf8ToString( dnBytes );
 
                         try
                         {
-                            objectName = new LdapDN( dnBytes );
+                            objectName = new LdapDN( dnStr );
                         }
                         catch ( InvalidNameException ine )
                         {
@@ -1487,14 +1490,15 @@
                     else
                     {
                         byte[] dnBytes = tlv.getValue().getData();
+                        String dnStr = StringTools.utf8ToString( dnBytes );
 
                         try
                         {
-                            object = new LdapDN( dnBytes );
+                            object = new LdapDN( dnStr );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "Invalid DN given : " + StringTools.utf8ToString(
dnBytes ) + " ("
+                            String msg = "Invalid DN given : " + dnStr + " ("
                                 + StringTools.dumpBytes( dnBytes ) + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
 
@@ -1933,14 +1937,15 @@
                     {
                         LdapDN entryDn = null;
                         byte[] dnBytes = tlv.getValue().getData();
+                        String dnStr = StringTools.utf8ToString( dnBytes );
 
                         try
                         {
-                            entryDn = new LdapDN( dnBytes );
+                            entryDn = new LdapDN( dnStr );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "Invalid DN given : " + StringTools.utf8ToString(
dnBytes ) + " ("
+                            String msg = "Invalid DN given : " + dnStr + " ("
                                 + StringTools.dumpBytes( dnBytes ) + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
 
@@ -2251,14 +2256,15 @@
                     else
                     {
                         byte[] dnBytes = tlv.getValue().getData();
+                        String dnStr = StringTools.utf8ToString( dnBytes );
 
                         try
                         {
-                            entry = new LdapDN( dnBytes );
+                            entry = new LdapDN( dnStr );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "Invalid DN given : " + StringTools.utf8ToString(
dnBytes ) + " ("
+                            String msg = "Invalid DN given : " + dnStr + " ("
                                 + StringTools.dumpBytes( dnBytes ) + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
 
@@ -2321,15 +2327,16 @@
                     else
                     {
                         byte[] dnBytes = tlv.getValue().getData();
+                        String dnStr = StringTools.utf8ToString( dnBytes );
 
                         try
                         {
-                            LdapDN dn = new LdapDN( dnBytes );
+                            LdapDN dn = new LdapDN( dnStr );
                             newRdn = dn.getRdn( 0 );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "Invalid new RDN given : " + StringTools.utf8ToString(
dnBytes ) + " ("
+                            String msg = "Invalid new RDN given : " + dnStr + " ("
                                 + StringTools.dumpBytes( dnBytes ) + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
 
@@ -2457,14 +2464,15 @@
                     else
                     {
                         byte[] dnBytes = tlv.getValue().getData();
+                        String dnStr = StringTools.utf8ToString( dnBytes );
 
                         try
                         {
-                            newSuperior = new LdapDN( dnBytes );
+                            newSuperior = new LdapDN( dnStr );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "Invalid new superior DN given : " + StringTools.utf8ToString(
dnBytes )
+                            String msg = "Invalid new superior DN given : " + dnStr
                                 + " (" + StringTools.dumpBytes( dnBytes ) + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
 
@@ -2612,14 +2620,15 @@
                     else
                     {
                         byte[] dnBytes = tlv.getValue().getData();
+                        String dnStr = StringTools.utf8ToString( dnBytes );
 
                         try
                         {
-                            entry = new LdapDN( dnBytes );
+                            entry = new LdapDN( dnStr );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "Invalid DN given : " + StringTools.utf8ToString(
dnBytes ) + " ("
+                            String msg = "Invalid DN given : " + dnStr + " ("
                                 + StringTools.dumpBytes( dnBytes ) + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
 
@@ -3722,14 +3731,15 @@
                     if ( tlv.getLength() != 0 )
                     {
                         byte[] dnBytes = tlv.getValue().getData();
+                        String dnStr = StringTools.utf8ToString( dnBytes );
 
                         try
                         {
-                            baseObject = new LdapDN( dnBytes );
+                            baseObject = new LdapDN( dnStr );
                         }
                         catch ( InvalidNameException ine )
                         {
-                            String msg = "Invalid root DN given : " + StringTools.utf8ToString(
dnBytes ) + " ("
+                            String msg = "Invalid root DN given : " + dnStr + " ("
                                 + StringTools.dumpBytes( dnBytes ) + ") is invalid";
                             log.error( "{} : {}", msg, ine.getMessage() );
 

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java?rev=898353&r1=898352&r2=898353&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/actions/MatchedDNAction.java
Tue Jan 12 15:04:23 2010
@@ -33,7 +33,6 @@
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -90,15 +89,16 @@
                 case INVALID_DN_SYNTAX :
                 case ALIAS_DEREFERENCING_PROBLEM :
                     byte[] dnBytes = tlv.getValue().getData();
+                    String dnStr = StringTools.utf8ToString( dnBytes );
                     
                     try
                     {
-                        ldapResult.setMatchedDN( new LdapDN( dnBytes ) );
+                        ldapResult.setMatchedDN( new LdapDN( dnStr ) );
                     }
                     catch ( InvalidNameException ine )
                     {
                         // This is for the client side. We will never decode LdapResult on
the server
-                        String msg = "Incorrect DN given : " + StringTools.utf8ToString(
dnBytes ) + 
+                        String msg = "Incorrect DN given : " + dnStr + 
                             " (" + StringTools.dumpBytes( dnBytes )
                             + ") is invalid";
                         log.error( "{} : {}", msg, ine.getMessage() );

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=898353&r1=898352&r2=898353&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
Tue Jan 12 15:04:23 2010
@@ -27,7 +27,6 @@
 import java.io.ObjectOutput;
 import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
@@ -143,49 +142,6 @@
 
 
     /**
-     * Creates an ldap name using a list of NameComponents. Each NameComponent
-     * is a String
-     *
-     * @param list of String name components.
-     * @throws InvalidNameException If the nameComponent is incorrect
-     */
-    public LdapDN( List<String> list ) throws InvalidNameException
-    {
-        if ( ( list != null ) && ( list.size() != 0 ) )
-        {
-            for ( String nameComponent : list )
-            {
-                add( 0, nameComponent );
-            }
-        }
-
-        normalized = false;
-
-    }
-
-
-    /**
-     * Creates an ldap name using a list of name components.
-     *
-     * @param nameComponents List of String name components.
-     * @throws InvalidNameException If the nameComponent is incorrect
-     */
-    public LdapDN( Iterator<String> nameComponents ) throws InvalidNameException
-    {
-        if ( nameComponents != null )
-        {
-            while ( nameComponents.hasNext() )
-            {
-                String nameComponent = nameComponents.next();
-                add( 0, nameComponent );
-            }
-        }
-
-        normalized = false;
-    }
-
-
-    /**
      * Parse a String and checks that it is a valid DN <br>
      * <p>
      * &lt;distinguishedName&gt; ::= &lt;name&gt; | e <br>
@@ -233,13 +189,13 @@
      * @param upNames
      * @throws InvalidNameException
      */
-    public LdapDN( String... upNames ) throws InvalidNameException
+    public LdapDN( String... upRdns ) throws InvalidNameException
     {
         StringBuilder sb = new StringBuilder();
         boolean valueExpected = false;
         boolean isFirst = true;
         
-        for ( String upName : upNames )
+        for ( String upRdn : upRdns )
         {
             if ( isFirst )
             {
@@ -252,16 +208,16 @@
             
             if ( !valueExpected )
             {
-                sb.append( upName );
+                sb.append( upRdn );
                 
-                if ( upName.indexOf( '=' ) == -1 )
+                if ( upRdn.indexOf( '=' ) == -1 )
                 {
                     valueExpected = true;
                 }
             }
             else
             {
-                sb.append( "=" ).append( upName );
+                sb.append( "=" ).append( upRdn );
                 
                 valueExpected = false;
             }
@@ -343,27 +299,6 @@
 
 
     /**
-     * Parse a buffer and checks that it is a valid DN <br>
-     * <p>
-     * &lt;distinguishedName&gt; ::= &lt;name&gt; | e <br>
-     * &lt;name&gt; ::= &lt;name-component&gt; &lt;name-components&gt;
<br>
-     * &lt;name-components&gt; ::= &lt;spaces&gt; &lt;separator&gt;
-     * &lt;spaces&gt; &lt;name-component&gt; &lt;name-components&gt;
| e <br>
-     * </p>
-     *
-     * @param bytes The byte buffer that contains the DN.
-     * @throws InvalidNameException if the buffer does not contains a valid DN.
-     */
-    public LdapDN( byte[] bytes ) throws InvalidNameException
-    {
-        upName = StringTools.utf8ToString( bytes );
-        LdapDnParser.parseInternal( upName, rdns );
-        this.normName = toNormName();
-        normalized = false;
-    }
-
-
-    /**
      * Normalize the DN by triming useless spaces and lowercasing names.
      */
     void normalizeInternal()

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java?rev=898353&r1=898352&r2=898353&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/name/LdapDNTest.java
Tue Jan 12 15:04:23 2010
@@ -1630,36 +1630,6 @@
 
 
     /**
-     * Class to test for void LdapName(List)
-     */
-    @Test
-    public void testLdapNameList() throws InvalidNameException
-    {
-        List<String> list = new ArrayList<String>();
-        list.add( "ou=People" );
-        list.add( "dc=example" );
-        list.add( "dc=com" );
-        Name name = new LdapDN( list );
-        assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
-    }
-
-
-    /**
-     * Class to test for void LdapName(Iterator)
-     */
-    @Test
-    public void testLdapNameIterator() throws InvalidNameException
-    {
-        List<String> list = new ArrayList<String>();
-        list.add( "ou=People" );
-        list.add( "dc=example" );
-        list.add( "dc=com" );
-        Name name = new LdapDN( list.iterator() );
-        assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
-    }
-
-
-    /**
      * Class to test for Object clone()
      *
      * @throws Exception
@@ -2507,11 +2477,7 @@
     @Test
     public void testLdapNameToName() throws Exception
     {
-        List<String> list = new ArrayList<String>();
-        list.add( "ou= Some   People   " );
-        list.add( "dc = eXample" );
-        list.add( "dc= cOm" );
-        LdapDN name = new LdapDN( list.iterator() );
+        LdapDN name = new LdapDN( "ou= Some   People   ", "dc = eXample", "dc= cOm" );
 
         assertTrue( name.getName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" )
);
 
@@ -2524,11 +2490,7 @@
     @Test
     public void testRdnGetTypeUpName() throws Exception
     {
-        List<String> list = new ArrayList<String>();
-        list.add( "ou= Some   People   " );
-        list.add( "dc = eXample" );
-        list.add( "dc= cOm" );
-        LdapDN name = new LdapDN( list.iterator() );
+        LdapDN name = new LdapDN( "ou= Some   People   ", "dc = eXample", "dc= cOm" );
 
         assertTrue( name.getName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" )
);
 



Mime
View raw message