directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1005753 - in /directory/shared/trunk: dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
Date Fri, 08 Oct 2010 09:56:42 GMT
Author: pamarcelot
Date: Fri Oct  8 09:56:42 2010
New Revision: 1005753

URL: http://svn.apache.org/viewvc?rev=1005753&view=rev
Log:
Added a DN.isNullOrEmpty(DN dn) method and using it the DSML Parser.

Modified:
    directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java

Modified: directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java?rev=1005753&r1=1005752&r2=1005753&view=diff
==============================================================================
--- directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java
(original)
+++ directory/shared/trunk/dsml-parser/src/main/java/org/apache/directory/shared/dsmlv2/reponse/LdapResultDsml.java
Fri Oct  8 09:56:42 2010
@@ -80,7 +80,7 @@ public class LdapResultDsml implements D
         // Matched DN
         DN matchedDN = result.getMatchedDn();
 
-        if ( ( matchedDN != null ) && ( !DN.EMPTY_DN.equals( matchedDN ) ) )
+        if ( !DN.isNullOrEmpty( matchedDN ) )
         {
             root.addAttribute( "matchedDN", matchedDN.getName() );
         }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java?rev=1005753&r1=1005752&r2=1005753&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/DN.java
Fri Oct  8 09:56:42 2010
@@ -120,11 +120,13 @@ public class DN implements Cloneable, Se
         // The current index
         int index;
 
+
         private RdnIterator()
         {
             index = rdns != null ? rdns.size() - 1 : -1;
         }
 
+
         /**
          * {@inheritDoc}
          */
@@ -133,6 +135,7 @@ public class DN implements Cloneable, Se
             return index >= 0;
         }
 
+
         /**
          * {@inheritDoc}
          */
@@ -141,6 +144,7 @@ public class DN implements Cloneable, Se
             return index >= 0 ? rdns.get( index-- ) : null;
         }
 
+
         /**
          * {@inheritDoc}
          */
@@ -150,6 +154,7 @@ public class DN implements Cloneable, Se
         }
     }
 
+
     // ~ Methods
     // ------------------------------------------------------------------------------------
 
@@ -179,7 +184,7 @@ public class DN implements Cloneable, Se
      */
     public DN( DN dn ) throws LdapInvalidDnException
     {
-       this( dn, null);
+        this( dn, null );
     }
 
 
@@ -206,7 +211,7 @@ public class DN implements Cloneable, Se
 
         normalized = new AtomicBoolean();
 
-        if( schemaManager != null )
+        if ( schemaManager != null )
         {
             normalize( schemaManager.getNormalizerMapping() );
         }
@@ -227,7 +232,6 @@ public class DN implements Cloneable, Se
     }
 
 
-
     /**
      * Parse a String and checks that it is a valid DN <br>
      * <p>
@@ -250,7 +254,7 @@ public class DN implements Cloneable, Se
 
         normalized = new AtomicBoolean();
 
-        if( schemaManager != null )
+        if ( schemaManager != null )
         {
             this.schemaManager = schemaManager;
             normalize( schemaManager.getNormalizerMapping() );
@@ -344,7 +348,7 @@ public class DN implements Cloneable, Se
         upName = sb.toString();
         DnParser.parseInternal( upName, rdns );
 
-        if( schemaManager != null )
+        if ( schemaManager != null )
         {
             this.schemaManager = schemaManager;
             normalize( schemaManager.getNormalizerMapping() );
@@ -429,7 +433,8 @@ public class DN implements Cloneable, Se
      * @throws LdapInvalidNameException If the DN is invalid.
      * @throws LdapInvalidDnException If something went wrong.
      */
-    /* No qualifier */ static DN normalize( String name, Map<String, OidNormalizer>
oidsMap ) throws LdapInvalidDnException
+    /* No qualifier */static DN normalize( String name, Map<String, OidNormalizer>
oidsMap )
+        throws LdapInvalidDnException
     {
         if ( ( name == null ) || ( name.length() == 0 ) || ( oidsMap == null ) || ( oidsMap.isEmpty()
) )
         {
@@ -762,7 +767,7 @@ public class DN implements Cloneable, Se
         {
             return isParentOf( new DN( dn ) );
         }
-        catch( LdapInvalidDnException lide )
+        catch ( LdapInvalidDnException lide )
         {
             return false;
         }
@@ -802,7 +807,7 @@ public class DN implements Cloneable, Se
         {
             return isChildOf( new DN( dn ) );
         }
-        catch( LdapInvalidDnException lide )
+        catch ( LdapInvalidDnException lide )
         {
             return false;
         }
@@ -1105,6 +1110,7 @@ public class DN implements Cloneable, Se
         return clonedDn;
     }
 
+
     /**
      * {@inheritDoc}
      */
@@ -1141,7 +1147,7 @@ public class DN implements Cloneable, Se
         }
         else
         {
-            if( schemaManager != null )
+            if ( schemaManager != null )
             {
                 clonedDn.normalize( schemaManager );
             }
@@ -1175,7 +1181,7 @@ public class DN implements Cloneable, Se
 
         clonedDn.rdns.add( 0, newRdn );
 
-        if( schemaManager != null )
+        if ( schemaManager != null )
         {
             clonedDn.normalize( schemaManager );
         }
@@ -1214,7 +1220,7 @@ public class DN implements Cloneable, Se
             }
             else
             {
-                if( schemaManager != null )
+                if ( schemaManager != null )
                 {
                     clonedDn.normalize( schemaManager );
                 }
@@ -1225,7 +1231,7 @@ public class DN implements Cloneable, Se
                 }
             }
         }
-        catch( LdapInvalidDnException e )
+        catch ( LdapInvalidDnException e )
         {
             LOG.error( e.getMessage(), e );
         }
@@ -1256,7 +1262,7 @@ public class DN implements Cloneable, Se
         int realPos = clonedDn.size() - posn;
         clonedDn.rdns.add( realPos, newRdn );
 
-        if( schemaManager != null )
+        if ( schemaManager != null )
         {
             clonedDn.normalize( schemaManager );
         }
@@ -1362,7 +1368,7 @@ public class DN implements Cloneable, Se
     {
         if ( obj instanceof String )
         {
-            return normName.equals( (String)obj );
+            return normName.equals( ( String ) obj );
         }
         else if ( obj instanceof DN )
         {
@@ -1478,7 +1484,8 @@ public class DN implements Cloneable, Se
      * @param oidsMap The map of all existing oids and normalizer.
      * @throws LdapInvalidDnException If the RDN is invalid.
      */
-    /** No qualifier */ static void rdnOidToName( RDN rdn, Map<String, OidNormalizer>
oidsMap ) throws LdapInvalidDnException
+    /** No qualifier */
+    static void rdnOidToName( RDN rdn, Map<String, OidNormalizer> oidsMap ) throws
LdapInvalidDnException
     {
         if ( rdn.getNbAtavs() > 1 )
         {
@@ -1487,7 +1494,7 @@ public class DN implements Cloneable, Se
             RDN rdnCopy = ( RDN ) rdn.clone();
             rdn.clear();
 
-            for ( AVA val:rdnCopy )
+            for ( AVA val : rdnCopy )
             {
                 AVA newAtav = atavOidToName( val, oidsMap );
                 rdn.addAVA( newAtav );
@@ -1567,7 +1574,7 @@ public class DN implements Cloneable, Se
 
         if ( normalized.get() )
         {
-           return this;
+            return this;
         }
 
         synchronized ( this )
@@ -1603,12 +1610,12 @@ public class DN implements Cloneable, Se
      */
     public DN normalize( SchemaManager schemaManager ) throws LdapInvalidDnException
     {
-        if( this.schemaManager == null )
+        if ( this.schemaManager == null )
         {
             this.schemaManager = schemaManager;
         }
 
-        if( this.schemaManager != null )
+        if ( this.schemaManager != null )
         {
             return normalize( schemaManager.getNormalizerMapping() );
         }
@@ -1650,4 +1657,22 @@ public class DN implements Cloneable, Se
     {
         return new RdnIterator();
     }
+
+
+    /**
+     * Check if a DistinguishedName is null or empty.
+     *
+     * @param dn The DN to validate
+     * @return <code>true></code> if the DN is null or empty, <code>false</code>
+     * otherwise
+     */
+    public static boolean isNullOrEmpty( DN dn )
+    {
+        if ( dn != null )
+        {
+            return dn.isEmpty();
+        }
+
+        return true;
+    }
 }



Mime
View raw message