directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r106783 - /incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java
Date Sun, 28 Nov 2004 02:22:45 GMT
Author: akarasulu
Date: Sat Nov 27 18:22:44 2004
New Revision: 106783

URL: http://svn.apache.org/viewcvs?view=rev&rev=106783
Log:
completed and tested compare request
Modified:
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java?view=diff&rev=106783&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java&r1=106782&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java&r2=106783
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java
Sat Nov 27 18:22:44 2004
@@ -17,12 +17,16 @@
 package org.apache.eve.protocol;
 
 
-import org.apache.seda.protocol.HandlerTypeEnum;
-import org.apache.seda.protocol.SingleReplyHandler;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.Attribute;
+
 import org.apache.seda.protocol.AbstractSingleReplyHandler;
 import org.apache.seda.listener.ClientKey;
 
-import org.apache.ldap.common.NotImplementedException;
+import org.apache.ldap.common.util.ExceptionUtils;
+import org.apache.ldap.common.message.*;
 
 
 /**
@@ -38,6 +42,45 @@
      */
     public Object handle( ClientKey key, Object request )
     {
-        throw new NotImplementedException( "handle in org.apache.eve.protocol.CompareHandler
not implemented!" );
+        CompareRequest req = ( CompareRequest ) request;
+        CompareResponse resp = new CompareResponseImpl( req.getMessageId() );
+        resp.setLdapResult( new LdapResultImpl( resp ) );
+        InitialContext ictx = SessionRegistry.getSingleton( null ).get( key );
+
+        try
+        {
+            DirContext ctx = ( DirContext ) ictx.lookup( "" );
+            Attribute attr = ctx.getAttributes( req.getName() ).get( req.getAttributeId()
);
+
+            if ( attr == null )
+            {
+                resp.getLdapResult().setResultCode( ResultCodeEnum.COMPAREFALSE );
+            }
+            else if ( attr.contains( req.getAssertionValue() ) )
+            {
+                resp.getLdapResult().setResultCode( ResultCodeEnum.COMPARETRUE );
+            }
+            else
+            {
+                resp.getLdapResult().setResultCode( ResultCodeEnum.COMPAREFALSE );
+            }
+        }
+        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().setMatchedDn( req.getName() );
+        return resp;
     }
 }

Mime
View raw message