directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r412786 - in /directory/branches/shared/optimization/ldap/src: main/antlr/ main/java/org/apache/directory/shared/ldap/name/ main/java/org/apache/directory/shared/ldap/schema/ main/java/org/apache/directory/shared/ldap/subtree/ test/java/org...
Date Thu, 08 Jun 2006 16:08:49 GMT
Author: akarasulu
Date: Thu Jun  8 09:08:48 2006
New Revision: 412786

URL: http://svn.apache.org/viewvc?rev=412786&view=rev
Log:
made subtree specification normalized distinguished names - using new interfaces instead of
just a name component normalizer now

Added:
    directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NormalizerMappingResolver.java
Modified:
    directory/branches/shared/optimization/ldap/src/main/antlr/subtree-specification.g
    directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/NameComponentNormalizer.java
    directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/SimpleNameComponentNormalizer.java
    directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParser.java
    directory/branches/shared/optimization/ldap/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java

Modified: directory/branches/shared/optimization/ldap/src/main/antlr/subtree-specification.g
URL: http://svn.apache.org/viewvc/directory/branches/shared/optimization/ldap/src/main/antlr/subtree-specification.g?rev=412786&r1=412785&r2=412786&view=diff
==============================================================================
--- directory/branches/shared/optimization/ldap/src/main/antlr/subtree-specification.g (original)
+++ directory/branches/shared/optimization/ldap/src/main/antlr/subtree-specification.g Thu
Jun  8 09:08:48 2006
@@ -24,10 +24,7 @@
 import java.util.HashSet;
 import java.util.ArrayList;
 
-import javax.naming.NamingException;
-
 import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.name.NameComponentNormalizer;
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.LeafNode;
 import org.apache.directory.shared.ldap.filter.SimpleNode;
@@ -35,6 +32,7 @@
 import org.apache.directory.shared.ldap.filter.AbstractExprNode;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecificationModifier;
+import org.apache.directory.shared.ldap.schema.NormalizerMappingResolver;
 import org.apache.directory.shared.ldap.util.ComponentsMonitor;
 import org.apache.directory.shared.ldap.util.OptionalComponentsMonitor;
 
@@ -75,8 +73,7 @@
 {
     private static final Logger log = LoggerFactory.getLogger( AntlrSubtreeSpecificationParser.class
);
     
-    private boolean isNormalizing = false;
-    private NameComponentNormalizer normalizer;
+    private NormalizerMappingResolver resolver;
     
     private Set chopBeforeExclusions = new HashSet();
     private Set chopAfterExclusions = new HashSet();
@@ -86,25 +83,25 @@
     private ComponentsMonitor subtreeSpecificationComponentsMonitor = null;
 
     /**
-     * Creates a (normalizing) subordinate DnParser for parsing LocalNames.
-     * This method MUST be called for each instance while we cannot do
-     * constructor overloading for this class.
-     *
-     * @return the DnParser to be used for parsing LocalNames
+     * Does nothing.
      */
     public void init()
     {
     }
-
-    /**
-     * Sets the NameComponentNormalizer for this parser's dnParser.
-     */
-    public void setNormalizer(NameComponentNormalizer normalizer)
+    
+    
+    public void setNormalizerMappingResolver( NormalizerMappingResolver resolver )
     {
-        this.normalizer = normalizer;
-        this.isNormalizing = true;
+    	this.resolver = resolver;
     }
     
+    
+    public boolean isNormalizing()
+    {
+    	return this.resolver != null;
+    }
+    
+
     private int token2Integer( Token token ) throws RecognitionException
     {
         int i = 0;
@@ -293,6 +290,7 @@
     :
     ID_specificationFilter ( SP )+ theRefinement=refinement
     {
+    	// TODO need to normalize refinement filter
         ssModifier.setRefinement( theRefinement );
     }
     ;
@@ -306,6 +304,10 @@
     token:SAFEUTF8STRING
     {
         name = new LdapDN( token.getText() );
+        if ( isNormalizing() )
+        {
+        	name.normalize();
+        }
         log.debug( "recognized a DistinguishedName: " + token.getText() );
     }
     ;

Modified: directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/NameComponentNormalizer.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/NameComponentNormalizer.java?rev=412786&r1=412785&r2=412786&view=diff
==============================================================================
--- directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/NameComponentNormalizer.java
(original)
+++ directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/NameComponentNormalizer.java
Thu Jun  8 09:08:48 2006
@@ -48,6 +48,14 @@
      */
     boolean isDefined( String id );
 
+    /**
+     * Normalizes the attribute name/alias to use the OID for it instead.
+     * 
+     * @param attributeName the name or OID of the attributeType
+     * @return the OID of the attributeType if it is recognized
+     * @throws NamingException if the attributeName is not recognized as a valid alias
+     */
+    String normalizeName( String attributeName ) throws NamingException;
 
     /**
      * Normalizes an attribute's value given the name of the attribute - short

Modified: directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/SimpleNameComponentNormalizer.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/SimpleNameComponentNormalizer.java?rev=412786&r1=412785&r2=412786&view=diff
==============================================================================
--- directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/SimpleNameComponentNormalizer.java
(original)
+++ directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/name/SimpleNameComponentNormalizer.java
Thu Jun  8 09:08:48 2006
@@ -44,7 +44,7 @@
      * @param normalizer
      *            the Normalizer to use for all normalization requests
      */
-    public SimpleNameComponentNormalizer(Normalizer normalizer)
+    public SimpleNameComponentNormalizer( Normalizer normalizer )
     {
         this.normalizer = normalizer;
     }
@@ -77,5 +77,11 @@
     public boolean isDefined( String oid )
     {
         return true;
+    }
+
+
+    public String normalizeName( String attributeName ) throws NamingException
+    {
+        throw new UnsupportedOperationException( "This class is not aware of schema information
and cannot normalize" );
     }
 }

Added: directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NormalizerMappingResolver.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NormalizerMappingResolver.java?rev=412786&view=auto
==============================================================================
--- directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NormalizerMappingResolver.java
(added)
+++ directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/schema/NormalizerMappingResolver.java
Thu Jun  8 09:08:48 2006
@@ -0,0 +1,29 @@
+package org.apache.directory.shared.ldap.schema;
+
+import java.util.Map;
+
+import javax.naming.NamingException;
+
+
+/**
+ * A class is used to resolve the normalizer mapping hash used for normalization.
+ * This interface is implemented and passed into several kinds of parsers that
+ * need to handle the normalization of LDAP name strings.
+ * 
+ * Why you may ask are we doing this?  Why not just pass in the map of 
+ * normalizers to these parsers and let them use that?  First off this mapping
+ * will not be static when dynamic updates are enabled to schema.  So if
+ * we just passed in the map then there would be no way to set a new map or
+ * trigger the change of the map when schema changes.  Secondly we cannot just
+ * pass server side objects that return this mapping because these parsers may
+ * and will be used in client side applications.  They will not have access to
+ * these server side objects that generate these mappings.  Instead when a 
+ * resolver is used we can create mock or almost right implementations.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface NormalizerMappingResolver
+{
+    Map getNormalizerMapping() throws NamingException;
+}

Modified: directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParser.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParser.java?rev=412786&r1=412785&r2=412786&view=diff
==============================================================================
--- directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParser.java
(original)
+++ directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParser.java
Thu Jun  8 09:08:48 2006
@@ -21,7 +21,7 @@
 import java.io.StringReader;
 import java.text.ParseException;
 
-import org.apache.directory.shared.ldap.name.NameComponentNormalizer;
+import org.apache.directory.shared.ldap.schema.NormalizerMappingResolver;
 
 import antlr.RecognitionException;
 import antlr.TokenStreamException;
@@ -66,14 +66,13 @@
     /**
      * Creates a normalizing subtree specification parser.
      */
-    public SubtreeSpecificationParser(NameComponentNormalizer normalizer)
+    public SubtreeSpecificationParser( NormalizerMappingResolver resolver )
     {
         StringReader in = new StringReader( "" ); // place holder for the
                                                     // first input
         this.lexer = new ReusableAntlrSubtreeSpecificationLexer( in );
         this.parser = new ReusableAntlrSubtreeSpecificationParser( lexer );
-
-        this.parser.setNormalizer( normalizer );
+        this.parser.setNormalizerMappingResolver( resolver );
         this.parser.init(); // this method MUST be called while we cannot do
         // constructor overloading for antlr generated parser
         this.isNormalizing = true;

Modified: directory/branches/shared/optimization/ldap/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/optimization/ldap/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java?rev=412786&r1=412785&r2=412786&view=diff
==============================================================================
--- directory/branches/shared/optimization/ldap/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java
(original)
+++ directory/branches/shared/optimization/ldap/src/test/java/org/apache/directory/shared/ldap/subtree/SubtreeSpecificationParserTest.java
Thu Jun  8 09:08:48 2006
@@ -28,8 +28,6 @@
 import org.apache.directory.shared.ldap.filter.BranchNode;
 import org.apache.directory.shared.ldap.filter.SimpleNode;
 import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.name.SimpleNameComponentNormalizer;
-import org.apache.directory.shared.ldap.schema.DeepTrimNormalizer;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecificationParser;
 
@@ -88,10 +86,7 @@
 
     /** An invalid specification with completely unrelated content */
     private static final String INVALID_SILLY_THING = "How much wood would a wood chuck chuck
if a wood chuck would chuck wood?";
-
-    /** A valid specification only with base set and normalizing to be applied */
-    private static final String SPEC_WITH_BASE_NORMALIZING = "{ base \"ou=system   \" }";
-
+    
     /** the ss parser wrapper */
     SubtreeSpecificationParser parser;
 
@@ -336,23 +331,6 @@
         {
             assertNotNull( e );
         }
-    }
-
-
-    /**
-     * Tests the parser with a valid specification with base set and normalizing
-     * active.
-     */
-    public void testSpecWithBaseNormalizing() throws Exception
-    {
-        // create a new normalizing parser for this test case
-        SubtreeSpecificationParser parser = new SubtreeSpecificationParser( new SimpleNameComponentNormalizer(
-            new DeepTrimNormalizer() ) );
-        SubtreeSpecification ss = parser.parse( SPEC_WITH_BASE_NORMALIZING );
-        assertNotNull( ss );
-
-        // looking for "ou=system" and not "ou=system " due to normalizing
-        assertEquals( "ou=system", ss.getBase().toString() );
     }
 
 



Mime
View raw message