directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 22098 - in incubator/directory/eve/branches/start: . src/java/org/apache/eve/protocol src/java/org/apache/eve/schema
Date Fri, 25 Jun 2004 04:11:19 GMT
Author: akarasulu
Date: Thu Jun 24 21:11:17 2004
New Revision: 22098

Modified:
   incubator/directory/eve/branches/start/   (props changed)
   incubator/directory/eve/branches/start/src/java/org/apache/eve/protocol/CompareHandler.java
   incubator/directory/eve/branches/start/src/java/org/apache/eve/schema/   (props changed)
Log:
added compare functionality without JNDI

Modified: incubator/directory/eve/branches/start/src/java/org/apache/eve/protocol/CompareHandler.java
==============================================================================
--- incubator/directory/eve/branches/start/src/java/org/apache/eve/protocol/CompareHandler.java
(original)
+++ incubator/directory/eve/branches/start/src/java/org/apache/eve/protocol/CompareHandler.java
Thu Jun 24 21:11:17 2004
@@ -10,11 +10,20 @@
 package org.apache.eve.protocol ;
 
 
-import org.apache.ldap.common.message.ResultResponse ;
-import org.apache.ldap.common.message.CompareRequest ;
-import org.apache.ldap.common.message.MessageTypeEnum ;
 import org.apache.ldap.common.NotImplementedException ;
-import org.apache.ldap.common.message.SingleReplyRequest ;
+import org.apache.ldap.common.message.*;
+import org.apache.eve.backend.LdapEntry;
+import org.apache.eve.backend.Backend;
+import org.apache.eve.backend.BackendException;
+import org.apache.eve.schema.Schema;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.CascadingRuntimeException;
+
+import javax.naming.Name;
+import javax.naming.NamingException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
 
 
 /**
@@ -100,7 +109,112 @@
      */
     public ResultResponse handle( SingleReplyRequest a_request )
     {
-        CompareRequest l_request = ( CompareRequest ) a_request ;
-        throw new NotImplementedException() ;
+        Name dn = null;
+        Schema schema = null;
+        LdapEntry entry = null;
+        Backend be = null;
+        Logger log = m_module.getLogger();
+        CompareRequest req = ( CompareRequest ) a_request;
+        CompareResponseImpl resp;
+        resp = new CompareResponseImpl( req.getMessageId() );
+        LdapResultImpl result = new LdapResultImpl( resp );
+        resp.setLdapResult( result );
+        result.setResultCode( ResultCodeEnum.COMPAREFALSE );
+
+        try
+        {
+            dn = m_module.getNexus().getNormalizedName( req.getName() );
+        }
+        catch ( NamingException e )
+        {
+            String msg = "failed to parse dn " + req.getName();
+
+            if ( log.isErrorEnabled() )
+            {
+                log.error( msg, e );
+            }
+
+            throw new CascadingRuntimeException( msg, e );
+        }
+
+        try
+        {
+            schema = m_module.getNexus().getSchema( dn );
+        }
+        catch ( NamingException e )
+        {
+            String msg = "failed to lookup schema for dn " + req.getName();
+
+            if ( log.isErrorEnabled() )
+            {
+                log.error( msg, e );
+            }
+
+            throw new CascadingRuntimeException( msg, e );
+        }
+
+        try
+        {
+            be = m_module.getNexus().getBackend( dn ) ;
+        }
+        catch ( NamingException e )
+        {
+            String msg = "failed to resolve backend for " + req.getName();
+
+            if ( log.isErrorEnabled() )
+            {
+                log.error( msg, e );
+            }
+
+            throw new CascadingRuntimeException( msg, e );
+        }
+
+        try
+        {
+            entry = be.read( dn );
+        }
+        catch ( Exception e )
+        {
+            String msg = "failed to read entry for " + req.getName();
+
+            if ( log.isErrorEnabled() )
+            {
+                log.error( msg, e );
+            }
+
+            throw new CascadingRuntimeException( msg, e );
+        }
+
+        Iterator list;
+        list = entry.getMultiValue( req.getAttributeId() ).iterator();
+        String compareTo = req.getAssertionValue();
+
+        try
+        {
+            while( list.hasNext() )
+            {
+                String value = ( String ) list.next();
+                value = schema.normalize( req.getAttributeId(), value );
+                if ( value.equals( compareTo ) )
+                {
+                    result.setResultCode( ResultCodeEnum.COMPARETRUE );
+                    break;
+                }
+            }
+        }
+        catch( NamingException e )
+        {
+            String msg = "failed to normalize entry value for " + req.getName();
+
+            if ( log.isErrorEnabled() )
+            {
+                log.error( msg, e );
+            }
+
+            throw new CascadingRuntimeException( msg, e );
+        }
+
+        result.setMatchedDn( entry.getEntryDN() );
+        return resp ;
     }
 }

Mime
View raw message