directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r106776 - /incubator/directory/eve/trunk/jndi-provider/src/java/org/apache/eve/db/LeafEvaluator.java /incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java
Date Sun, 28 Nov 2004 00:58:34 GMT
Author: akarasulu
Date: Sat Nov 27 16:58:33 2004
New Revision: 106776

URL: http://svn.apache.org/viewcvs?view=rev&rev=106776
Log:
Changes ...

 o implemented and tested modifyDn functionality with renames and moves under
   new superiors
 o fixed null pointer exception 


Modified:
   incubator/directory/eve/trunk/jndi-provider/src/java/org/apache/eve/db/LeafEvaluator.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java

Modified: incubator/directory/eve/trunk/jndi-provider/src/java/org/apache/eve/db/LeafEvaluator.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/jndi-provider/src/java/org/apache/eve/db/LeafEvaluator.java?view=diff&rev=106776&p1=incubator/directory/eve/trunk/jndi-provider/src/java/org/apache/eve/db/LeafEvaluator.java&r1=106775&p2=incubator/directory/eve/trunk/jndi-provider/src/java/org/apache/eve/db/LeafEvaluator.java&r2=106776
==============================================================================
--- incubator/directory/eve/trunk/jndi-provider/src/java/org/apache/eve/db/LeafEvaluator.java
(original)
+++ incubator/directory/eve/trunk/jndi-provider/src/java/org/apache/eve/db/LeafEvaluator.java
Sat Nov 27 16:58:33 2004
@@ -248,15 +248,21 @@
         
         // get the attribute associated with the node 
         Attributes attrs = rec.getAttributes();
+
+        if ( attrs == null )
+        {
+            return false;
+        }
+        
         return null != attrs.get( attrId );
     }
-    
+
 
     /**
      * Evaluates a simple equality attribute value assertion on a perspective
      * candidate.
-     * 
-     * @param node the equality node to evaluate 
+     *
+     * @param node the equality node to evaluate
      * @param rec the IndexRecord of the perspective candidate
      * @return the ava evaluation on the perspective candidate
      * @throws NamingException if there is a database access failure

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java?view=diff&rev=106776&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java&r1=106775&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java&r2=106776
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java
Sat Nov 27 16:58:33 2004
@@ -17,10 +17,16 @@
 package org.apache.eve.protocol;
 
 
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.protocol.AbstractSingleReplyHandler;
 
-import org.apache.ldap.common.NotImplementedException;
+import org.apache.ldap.common.name.LdapName;
+import org.apache.ldap.common.util.ExceptionUtils;
+import org.apache.ldap.common.message.*;
 
 
 /**
@@ -36,6 +42,58 @@
      */
     public Object handle( ClientKey key, Object request )
     {
-        throw new NotImplementedException( "handle in org.apache.eve.protocol.ModifyDnHandler
not implemented!" );
+        ModifyDnRequest req = ( ModifyDnRequest ) request;
+        ModifyDnResponse resp = new ModifyDnResponseImpl( req.getMessageId() );
+        resp.setLdapResult( new LdapResultImpl( resp ) );
+        InitialContext ictx = SessionRegistry.getSingleton( null ).get( key );
+
+        try
+        {
+            DirContext ctx = ( DirContext ) ictx.lookup( "" );
+            String deleteRDN = String.valueOf( req.getDeleteOldRdn() );
+            ctx.addToEnvironment( "java.naming.ldap.deleteRDN", deleteRDN );
+
+            if ( req.isMove() )
+            {
+                LdapName oldDn = new LdapName( req.getName() );
+                LdapName newDn = new LdapName( req.getNewSuperior() );
+
+                if ( req.getNewRdn() != null )
+                {
+                    newDn.add( req.getNewRdn() );
+                }
+                else
+                {
+                    newDn.add( oldDn.getRdn() );
+                }
+
+                ctx.rename( new LdapName( req.getName() ), newDn );
+            }
+            else
+            {
+                LdapName newDn = new LdapName( req.getName() );
+                newDn.remove( newDn.size() - 1 );
+                newDn.add( req.getNewRdn() );
+                ctx.rename( new LdapName( req.getName() ), newDn );
+            }
+        }
+        catch ( NamingException e )
+        {
+            String msg = "failed to add entry " + req.getName() + ":\n";
+            msg += ExceptionUtils.getStackTrace( e );
+            ResultCodeEnum code;
+            code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+            resp.getLdapResult().setResultCode( code );
+            resp.getLdapResult().setErrorMessage( msg );
+
+            if ( e.getResolvedName() != null )
+            {
+                resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
+            }
+        }
+
+        resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
+        resp.getLdapResult().setMatchedDn( req.getName() );
+        return resp;
     }
 }

Mime
View raw message