directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r106734 - /incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java
Date Sat, 27 Nov 2004 17:11:43 GMT
Author: akarasulu
Date: Sat Nov 27 09:11:42 2004
New Revision: 106734

URL: http://svn.apache.org/viewcvs?view=rev&rev=106734
Log:
Completed the Modify handler.

Modified:
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java?view=diff&rev=106734&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java&r1=106733&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java&r2=106734
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java
Sat Nov 27 09:11:42 2004
@@ -17,10 +17,17 @@
 package org.apache.eve.protocol;
 
 
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.protocol.AbstractSingleReplyHandler;
 
 import org.apache.ldap.common.NotImplementedException;
+import org.apache.ldap.common.util.ExceptionUtils;
+import org.apache.ldap.common.message.*;
 
 
 /**
@@ -31,11 +38,40 @@
  */
 public class ModifyHandler extends AbstractSingleReplyHandler
 {
+    private static final ModificationItem[] EMPTY = new ModificationItem[0];
     /**
      * @see org.apache.seda.protocol.SingleReplyHandler#handle(ClientKey,Object)
      */
     public Object handle( ClientKey key, Object request )
     {
-        throw new NotImplementedException( "handle in org.apache.eve.protocol.ModifyHandler
not implemented!" );
+        ModifyRequest req = ( ModifyRequest ) request;
+        ModifyResponse resp = new ModifyResponseImpl( req.getMessageId() );
+        resp.setLdapResult( new LdapResultImpl( resp ) );
+        InitialContext ictx = SessionRegistry.getSingleton( null ).get( key );
+
+        try
+        {
+            DirContext ctx = ( DirContext ) ictx.lookup( "" );
+            Object[] mods = req.getModificationItems().toArray( EMPTY );
+            ctx.modifyAttributes( req.getName(), ( ModificationItem[] ) mods );
+        }
+        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