directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r280496 - in /directory: apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/ apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/ apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/...
Date Tue, 13 Sep 2005 04:47:45 GMT
Author: akarasulu
Date: Mon Sep 12 21:47:33 2005
New Revision: 280496

URL: http://svn.apache.org/viewcvs?rev=280496&view=rev
Log:
changes ...

 o added objectIdentifierMatch Normalizer and Comparator to commons schema package
 o added setter for SimpleNode value to allow for filter normalization 
 o added new filter leaf value normalizing visitor to work with normalization
   service
 o altered normalization service to normalize filter leaf node values
 o modified bootstrap producers for system schema to return the correct normalizer
   and comparator for the objectIdentifierMatch matchingRule
 o now that we normalize the whole filter we need not normalize when comparing 
   within the LeafEvaluator

Note: 

  The majority of these changes improve filter normalization handling which was
in effect.  The main problem was the fact that the correct normalizer and 
comparator pair were not being used with the objectIdentifierMatch matchingRule.


Added:
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/ValueNormalizingVisitor.java
  (with props)
    directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierComparator.java
  (with props)
    directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierNormalizer.java
  (with props)
Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/NormalizationService.java
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/LeafEvaluator.java
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/SystemComparatorProducer.java
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/SystemNormalizerProducer.java
    directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/filter/SimpleNode.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/NormalizationService.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/NormalizationService.java?rev=280496&r1=280495&r2=280496&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/NormalizationService.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/NormalizationService.java
Mon Sep 12 21:47:33 2005
@@ -49,12 +49,15 @@
 public class NormalizationService extends BaseInterceptor
 {
     private DnParser parser;
+    private ValueNormalizingVisitor visitor;
 
 
     public void init( ContextFactoryConfiguration factoryCfg, InterceptorConfiguration cfg
) throws NamingException
     {
         AttributeTypeRegistry attributeRegistry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
-        parser = new DnParser( new PerComponentNormalizer( attributeRegistry ) );
+        NameComponentNormalizer ncn = new PerComponentNormalizer( attributeRegistry );
+        parser = new DnParser( ncn );
+        visitor = new ValueNormalizingVisitor( ncn );
     }
 
 
@@ -157,6 +160,7 @@
             base = parser.parse( base.toString() );
         }
 
+        filter.accept( visitor );
         return nextInterceptor.search( base, env, filter, searchCtls );
     }
 

Added: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/ValueNormalizingVisitor.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/ValueNormalizingVisitor.java?rev=280496&view=auto
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/ValueNormalizingVisitor.java
(added)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/ValueNormalizingVisitor.java
Mon Sep 12 21:47:33 2005
@@ -0,0 +1,103 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.server.normalization;
+
+
+import org.apache.ldap.common.filter.FilterVisitor;
+import org.apache.ldap.common.filter.ExprNode;
+import org.apache.ldap.common.filter.BranchNode;
+import org.apache.ldap.common.filter.SimpleNode;
+import org.apache.ldap.common.name.NameComponentNormalizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.NamingException;
+import java.util.ArrayList;
+
+
+/**
+ * A filter visitor which normalizes leaf node values as it visits them.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ValueNormalizingVisitor implements FilterVisitor
+{
+    private final static Logger log = LoggerFactory.getLogger( ValueNormalizingVisitor.class
);
+    private final NameComponentNormalizer ncn;
+
+
+    public ValueNormalizingVisitor( NameComponentNormalizer ncn )
+    {
+        this.ncn = ncn;
+    }
+
+
+    public void visit( ExprNode node )
+    {
+        if ( node instanceof SimpleNode )
+        {
+            SimpleNode snode = ( SimpleNode ) node;
+            String normalized = null;
+
+            try
+            {
+                if ( Character.isDigit( snode.getAttribute().charAt( 0 ) ) )
+                {
+                    normalized = ncn.normalizeByOid( snode.getAttribute(), snode.getValue()
);
+                }
+                else
+                {
+                    normalized = ncn.normalizeByName( snode.getAttribute(), snode.getValue()
);
+                }
+            }
+            catch ( NamingException e )
+            {
+                log.error( "Failed to normalize filter value: " + e.getMessage(), e );
+                throw new RuntimeException( e.getMessage() );
+            }
+
+            snode.setValue( normalized );
+            return;
+        }
+
+        BranchNode bnode = ( BranchNode ) node;
+        final int size = bnode.getChildren().size();
+        for ( int ii = 0; ii < size ; ii++ )
+        {
+            visit( ( ExprNode ) bnode.getChildren().get( ii ) );
+        }
+    }
+
+
+    public boolean canVisit( ExprNode node )
+    {
+        return node instanceof BranchNode || node instanceof SimpleNode;
+    }
+
+
+    public boolean isPrefix()
+    {
+        return false;
+    }
+
+
+    public ArrayList getOrder( BranchNode node, ArrayList children )
+    {
+        return children;
+    }
+}

Propchange: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/normalization/ValueNormalizingVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/LeafEvaluator.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/LeafEvaluator.java?rev=280496&r1=280495&r2=280496&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/LeafEvaluator.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/LeafEvaluator.java
Mon Sep 12 21:47:33 2005
@@ -182,7 +182,7 @@
          */
         Normalizer normalizer = getNormalizer( attrId );
         Comparator comparator = getComparator( attrId );
-        Object filterValue = normalizer.normalize( node.getValue() );
+        Object filterValue = node.getValue();
         NamingEnumeration list = attr.getAll();
         
         /*
@@ -308,7 +308,7 @@
         }
 
         // get the normalized AVA filter value
-        Object filterValue = normalizer.normalize( node.getValue() );
+        Object filterValue = node.getValue();
 
         // check if the normalized value is present
         if ( attr.contains( filterValue ) )

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/SystemComparatorProducer.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/SystemComparatorProducer.java?rev=280496&r1=280495&r2=280496&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/SystemComparatorProducer.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/SystemComparatorProducer.java
Mon Sep 12 21:47:33 2005
@@ -21,12 +21,7 @@
 
 import javax.naming.NamingException;
 
-import org.apache.ldap.common.schema.CachingNormalizer;
-import org.apache.ldap.common.schema.ComparableComparator;
-import org.apache.ldap.common.schema.DeepTrimNormalizer;
-import org.apache.ldap.common.schema.DeepTrimToLowerNormalizer;
-import org.apache.ldap.common.schema.DnComparator;
-import org.apache.ldap.common.schema.NormalizingComparator;
+import org.apache.ldap.common.schema.*;
 import org.apache.ldap.server.schema.ConcreteNameComponentNormalizer;
 
 
@@ -55,7 +50,7 @@
         ( 2.5.13.0 NAME 'objectIdentifierMatch'
           SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )
          */
-         comparator = new ComparableComparator();
+         comparator = new ObjectIdentifierComparator();
          cb.schemaObjectProduced( this, "2.5.13.0", comparator );
 
         /*

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/SystemNormalizerProducer.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/SystemNormalizerProducer.java?rev=280496&r1=280495&r2=280496&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/SystemNormalizerProducer.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/schema/bootstrap/SystemNormalizerProducer.java
Mon Sep 12 21:47:33 2005
@@ -19,12 +19,7 @@
 
 import javax.naming.NamingException;
 
-import org.apache.ldap.common.schema.CachingNormalizer;
-import org.apache.ldap.common.schema.DeepTrimNormalizer;
-import org.apache.ldap.common.schema.DeepTrimToLowerNormalizer;
-import org.apache.ldap.common.schema.DnNormalizer;
-import org.apache.ldap.common.schema.NoOpNormalizer;
-import org.apache.ldap.common.schema.Normalizer;
+import org.apache.ldap.common.schema.*;
 import org.apache.ldap.server.schema.ConcreteNameComponentNormalizer;
 
 
@@ -106,7 +101,7 @@
         ( 2.5.13.0 NAME 'objectIdentifierMatch'
           SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )
           */
-        normalizer = new NoOpNormalizer();
+        normalizer = new ObjectIdentifierNormalizer();
         cb.schemaObjectProduced( this, "2.5.13.0", normalizer );
 
         /*

Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/filter/SimpleNode.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/filter/SimpleNode.java?rev=280496&r1=280495&r2=280496&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/filter/SimpleNode.java
(original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/filter/SimpleNode.java
Mon Sep 12 21:47:33 2005
@@ -14,44 +14,34 @@
  *   limitations under the License.
  *
  */
-
-/*
- * $Id: SimpleNode.java,v 1.8 2003/10/14 04:59:23 akarasulu Exp $
- *
- * -- (c) LDAPd Group
- * -- Please refer to the LICENSE.txt file in the root directory of      --
- * -- any LDAPd project for copyright and distribution information.      --
- *
- */
 package org.apache.ldap.common.filter ;
 
 
 /**
  * A simple assertion value node.
  *
- * @author <a href="mailto:aok123@bellsouth.net">Alex Karasulu</a>
- * @author $author$
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Revision$
  */
 public class SimpleNode extends LeafNode
 {
     /** the value */
-    private final String m_value ;
+    private String value ;
 
 
     /**
      * Creates a new SimpleNode object.
      *
-     * @param a_attribute the attribute name
-     * @param a_value the value to test for 
-     * @param a_type the type of the assertion
+     * @param attribute the attribute name
+     * @param value the value to test for
+     * @param type the type of the assertion
      */
-    public SimpleNode( String a_attribute, String a_value, int a_type )
+    public SimpleNode( String attribute, String value, int type )
     {
-        super( a_attribute, a_type ) ;
-        m_value = a_value ;
+        super( attribute, type ) ;
+        this.value = value ;
 
-        switch ( a_type )
+        switch ( type )
         {
         case ( APPROXIMATE ):
             break ;
@@ -83,6 +73,7 @@
         }
     }
 
+
     /**
      * Gets the value.
      *
@@ -90,7 +81,18 @@
      */
     public final String getValue()
     {
-        return m_value ;
+        return value ;
+    }
+
+
+    /**
+     * Sets the value of this node.
+     *
+     * @param value the value for this node
+     */
+    public void setValue( String value )
+    {
+        this.value = value;
     }
 
 
@@ -98,53 +100,49 @@
      * @see org.apache.ldap.common.filter.ExprNode#printToBuffer(
      * java.lang.StringBuffer)
      */
-    public StringBuffer printToBuffer( StringBuffer a_buf )
+    public StringBuffer printToBuffer( StringBuffer buf )
     {
-        a_buf.append( '(' ).append( getAttribute() ) ;
+        buf.append( '(' ).append( getAttribute() ) ;
 
         switch ( getAssertionType() )
         {
         case ( APPROXIMATE ):
-            a_buf.append( "~=" ) ;
-
+            buf.append( "~=" ) ;
             break ;
 
         case ( EQUALITY ):
-            a_buf.append( "=" ) ;
-
+            buf.append( "=" ) ;
             break ;
 
         case ( GREATEREQ ):
-            a_buf.append( ">=" ) ;
-
+            buf.append( ">=" ) ;
             break ;
 
         case ( LESSEQ ):
-            a_buf.append( "<=" ) ;
-
+            buf.append( "<=" ) ;
             break ;
 
         default:
-            a_buf.append( "UNKNOWN" ) ;
+            buf.append( "UNKNOWN" ) ;
         }
 
 
-        a_buf.append( m_value ) ;
-        a_buf.append( ')' ) ;
+        buf.append( value ) ;
+        buf.append( ')' ) ;
 
         if ( ( null != getAnnotations() )
                 && getAnnotations().containsKey( "count" ) )
         {
-            a_buf.append( '[' ) ;
-            a_buf.append( getAnnotations().get( "count" ).toString() ) ;
-            a_buf.append( "] " ) ;
+            buf.append( '[' ) ;
+            buf.append( getAnnotations().get( "count" ).toString() ) ;
+            buf.append( "] " ) ;
         }
         else
         {
-            a_buf.append( ' ' ) ;
+            buf.append( ' ' ) ;
         }
         
-        return a_buf;
+        return buf;
     }
 
 
@@ -153,10 +151,9 @@
      */
     public String toString()
     {
-        StringBuffer l_buf = new StringBuffer() ;
-        printToBuffer( l_buf ) ;
-
-        return ( l_buf.toString() ) ;
+        StringBuffer buf = new StringBuffer() ;
+        printToBuffer( buf ) ;
+        return ( buf.toString() ) ;
     }
 
 
@@ -164,14 +161,15 @@
      * @see org.apache.ldap.common.filter.ExprNode#accept(
      * org.apache.ldap.common.filter.FilterVisitor)
      */
-    public void accept( FilterVisitor a_visitor )
+    public void accept( FilterVisitor visitor )
     {
-        if ( a_visitor.canVisit( this ) ) 
+        if ( visitor.canVisit( this ) )
         {
-            a_visitor.visit( this ) ;
+            visitor.visit( this ) ;
         }
     }
 
+
     /* (non-Javadoc)
      * @see java.lang.Object#equals(java.lang.Object)
      */
@@ -197,6 +195,6 @@
             return false;
         }
         
-        return m_value.equals( ( ( SimpleNode ) other ).getValue() );
+        return value.equals( ( ( SimpleNode ) other ).getValue() );
     }
 }

Added: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierComparator.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierComparator.java?rev=280496&view=auto
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierComparator.java
(added)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierComparator.java
Mon Sep 12 21:47:33 2005
@@ -0,0 +1,65 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.common.schema;
+
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+
+/**
+ * A comparator for the objectIdentifierMatch matchingRule.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ObjectIdentifierComparator implements Comparator, Serializable
+{
+    public int compare( Object o1, Object o2 )
+    {
+        if ( o1 == null && o2 == null )
+        {
+            return 0;
+        }
+        else if ( o1 != null && o2 == null )
+        {
+            return 1;
+        }
+        else if ( o1 == null && o2 != null )
+        {
+            return -1;
+        }
+
+        if ( o1.equals( o2 ) )
+        {
+            return 0;
+        }
+
+        if ( ! ( o1 instanceof String && o2 instanceof String ) )
+        {
+            if ( o1.equals( o2 ) )
+            {
+                return 0;
+            }
+
+            return -1;
+        }
+
+        String s1 = ( ( String ) o1 ).trim().toLowerCase(), s2 = ( ( String ) o2 ).trim().toLowerCase();
+        return s1.compareTo( s2 );
+    }
+}

Propchange: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierNormalizer.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierNormalizer.java?rev=280496&view=auto
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierNormalizer.java
(added)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierNormalizer.java
Mon Sep 12 21:47:33 2005
@@ -0,0 +1,57 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.common.schema;
+
+
+import javax.naming.NamingException;
+
+
+/**
+ * A normalizer for the objectIdentifierMatch matching rule.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ObjectIdentifierNormalizer implements Normalizer
+{
+    public Object normalize( Object value ) throws NamingException
+    {
+        if (! ( value instanceof String ) )
+        {
+            return value;
+        }
+
+        String str = ( ( String ) value ).trim();
+
+        if ( str == null )
+        {
+            return null;
+        }
+        else if ( str.trim().length() == 0 )
+        {
+            return "";
+        }
+        else if ( Character.isDigit( str.charAt( 0 ) ) )
+        {
+            return str;
+        }
+        else
+        {
+            return str.toLowerCase();
+        }
+    }
+}

Propchange: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ObjectIdentifierNormalizer.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message