directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r398377 - in /directory/trunks/shared/ldap/src: main/antlr/ main/java/org/apache/directory/shared/ldap/trigger/ test/java/org/apache/directory/shared/ldap/trigger/
Date Sun, 30 Apr 2006 16:54:57 GMT
Author: ersiner
Date: Sun Apr 30 09:54:56 2006
New Revision: 398377

URL: http://svn.apache.org/viewcvs?rev=398377&view=rev
Log:
Implemented my ConditionalParserFailureBasedOnCallerFeedback pattern for saving parsing time
by eliminating unnecassary parses.

Added:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/ConditionalParserFailureBasedOnCallerFeedback.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/GenericLdapOperationTokenListener.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperationTokenListener.java
Modified:
    directory/trunks/shared/ldap/src/main/antlr/TriggerSpecification.g
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperation.java
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParser.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParserTest.java

Modified: directory/trunks/shared/ldap/src/main/antlr/TriggerSpecification.g
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/main/antlr/TriggerSpecification.g?rev=398377&r1=398376&r2=398377&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/antlr/TriggerSpecification.g (original)
+++ directory/trunks/shared/ldap/src/main/antlr/TriggerSpecification.g Sun Apr 30 09:54:56
2006
@@ -72,6 +72,8 @@
     private boolean isNormalizing = false;
     private NameComponentNormalizer normalizer;
     
+    private LdapOperationTokenListener caller = null;
+    
     private ActionTime triggerActionTime;
     
     private LdapOperation triggerLdapOperation;
@@ -112,6 +114,11 @@
             throw new NullPointerException( "dnParser is null: " + msg );
         }
     }
+    
+	public void registerLdapOperationTokenListener( LdapOperationTokenListener listener )
+	{
+		this.caller = listener;
+	}
 
     /**
      * Sets the NameComponentNormalizer for this parser's dnParser.
@@ -191,7 +198,14 @@
     log.debug( "entered bindOperationAndStoredProcedureCall()" );
 }
     :
-    ID_bind theCompositeRuleForCallAndSPNameAndSPOptionList
+    ID_bind
+    {
+    	if ( caller.ldapOperationTokenRead( LdapOperation.BIND ) == false )
+    	{
+    		throw new ConditionalParserFailureBasedOnCallerFeedback( LdapOperation.BIND  );
+    	}
+    }
+    theCompositeRuleForCallAndSPNameAndSPOptionList
     OPEN_PARAN ( SP )*
         ( bindStoredProcedureParameterList )?
     CLOSE_PARAN
@@ -202,7 +216,14 @@
     log.debug( "entered unbindOperationAndStoredProcedureCall()" );
 }
     :
-    ID_unbind theCompositeRuleForCallAndSPNameAndSPOptionList
+    ID_unbind
+    {
+    	if ( caller.ldapOperationTokenRead( LdapOperation.UNBIND ) == false )
+    	{
+    		throw new ConditionalParserFailureBasedOnCallerFeedback( LdapOperation.UNBIND );
+    	}
+    }
+    theCompositeRuleForCallAndSPNameAndSPOptionList
     OPEN_PARAN ( SP )*
         ( unbindStoredProcedureParameterList )?
     CLOSE_PARAN
@@ -213,7 +234,14 @@
     log.debug( "entered searchOperationAndStoredProcedureCall()" );
 }
     :
-    ID_search theCompositeRuleForCallAndSPNameAndSPOptionList
+    ID_search
+    {
+    	if ( caller.ldapOperationTokenRead( LdapOperation.SEARCH ) == false )
+    	{
+    		throw new ConditionalParserFailureBasedOnCallerFeedback( LdapOperation.SEARCH );
+    	}
+    }
+    theCompositeRuleForCallAndSPNameAndSPOptionList
     OPEN_PARAN ( SP )*
         ( searchStoredProcedureParameterList )?
     CLOSE_PARAN
@@ -224,7 +252,14 @@
     log.debug( "entered modifyOperationAndStoredProcedureCall()" );
 }
     :
-    ID_modify theCompositeRuleForCallAndSPNameAndSPOptionList
+    ID_modify
+    {
+    	if ( caller.ldapOperationTokenRead( LdapOperation.MODIFY ) == false )
+    	{
+    		throw new ConditionalParserFailureBasedOnCallerFeedback( LdapOperation.MODIFY );
+    	}
+    }
+    theCompositeRuleForCallAndSPNameAndSPOptionList
     OPEN_PARAN ( SP )*
         ( modifyStoredProcedureParameterList )?
     CLOSE_PARAN
@@ -235,7 +270,14 @@
     log.debug( "entered addOperationAndStoredProcedureCall()" );
 }
     :
-    ID_add theCompositeRuleForCallAndSPNameAndSPOptionList
+    ID_add
+    {
+    	if ( caller.ldapOperationTokenRead( LdapOperation.ADD ) == false )
+    	{
+    		throw new ConditionalParserFailureBasedOnCallerFeedback( LdapOperation.ADD );
+    	}
+    }
+    theCompositeRuleForCallAndSPNameAndSPOptionList
     OPEN_PARAN ( SP )*
         ( addStoredProcedureParameterList )?
     CLOSE_PARAN
@@ -246,7 +288,14 @@
     log.debug( "entered delOperationAndStoredProcedureCall()" );
 }
     :
-    ( ID_del | ID_delete ) theCompositeRuleForCallAndSPNameAndSPOptionList
+    ( ID_del | ID_delete )
+    {
+    	if ( caller.ldapOperationTokenRead( LdapOperation.DEL ) == false )
+    	{
+    		throw new ConditionalParserFailureBasedOnCallerFeedback( LdapOperation.DEL );
+    	}
+    }
+    theCompositeRuleForCallAndSPNameAndSPOptionList
     OPEN_PARAN ( SP )*
         ( delStoredProcedureParameterList )?
     CLOSE_PARAN
@@ -257,7 +306,14 @@
     log.debug( "entered modDNOperationAndStoredProcedureCall()" );
 }
     :
-    ID_modDN theCompositeRuleForCallAndSPNameAndSPOptionList
+    ID_modDN
+    {
+    	if ( caller.ldapOperationTokenRead( LdapOperation.MODDN ) == false )
+    	{
+    		throw new ConditionalParserFailureBasedOnCallerFeedback( LdapOperation.MODDN );
+    	}
+    }
+    theCompositeRuleForCallAndSPNameAndSPOptionList
     OPEN_PARAN ( SP )*
         ( modDNStoredProcedureParameterList )?
     CLOSE_PARAN
@@ -268,7 +324,14 @@
     log.debug( "entered compareOperationAndStoredProcedureCall()" );
 }
     :
-    ID_compare theCompositeRuleForCallAndSPNameAndSPOptionList
+    ID_compare
+    {
+    	if ( caller.ldapOperationTokenRead( LdapOperation.COMPARE ) == false )
+    	{
+    		throw new ConditionalParserFailureBasedOnCallerFeedback( LdapOperation.COMPARE );
+    	}
+    }
+    theCompositeRuleForCallAndSPNameAndSPOptionList
     OPEN_PARAN ( SP )*
         ( compareStoredProcedureParameterList )?
     CLOSE_PARAN
@@ -279,7 +342,14 @@
     log.debug( "entered abandonOperationAndStoredProcedureCall()" );
 }
     :
-    ID_abandon theCompositeRuleForCallAndSPNameAndSPOptionList
+    ID_abandon
+    {
+    	if ( caller.ldapOperationTokenRead( LdapOperation.ABANDON ) == false )
+    	{
+    		throw new ConditionalParserFailureBasedOnCallerFeedback( LdapOperation.ABANDON );
+    	}
+    }
+    theCompositeRuleForCallAndSPNameAndSPOptionList
     OPEN_PARAN ( SP )*
         ( abandonStoredProcedureParameterList )?
     CLOSE_PARAN
@@ -290,7 +360,14 @@
     log.debug( "entered extendedOperationAndStoredProcedureCall()" );
 }
     :
-    ID_extended theCompositeRuleForCallAndSPNameAndSPOptionList
+    ID_extended
+    {
+    	if ( caller.ldapOperationTokenRead( LdapOperation.EXTENDED ) == false )
+    	{
+    		throw new ConditionalParserFailureBasedOnCallerFeedback( LdapOperation.EXTENDED );
+    	}
+    }
+    theCompositeRuleForCallAndSPNameAndSPOptionList
     OPEN_PARAN ( SP )*
         ( extendedStoredProcedureParameterList )?
     CLOSE_PARAN

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/ConditionalParserFailureBasedOnCallerFeedback.java
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/ConditionalParserFailureBasedOnCallerFeedback.java?rev=398377&view=auto
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/ConditionalParserFailureBasedOnCallerFeedback.java
(added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/ConditionalParserFailureBasedOnCallerFeedback.java
Sun Apr 30 09:54:56 2006
@@ -0,0 +1,43 @@
+/*
+ *   Copyright 2006 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.directory.shared.ldap.trigger;
+
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev:$, $Date:$
+ */
+public class ConditionalParserFailureBasedOnCallerFeedback extends RuntimeException
+{
+
+    private static final long serialVersionUID = 2524413387863284181L;
+
+    private Object readToken;    
+    
+    public ConditionalParserFailureBasedOnCallerFeedback( Object readToken )
+    {
+        this.readToken = readToken;
+    }
+    
+    public Object getReadToken()
+    {
+        return readToken;
+    }
+}

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/GenericLdapOperationTokenListener.java
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/GenericLdapOperationTokenListener.java?rev=398377&view=auto
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/GenericLdapOperationTokenListener.java
(added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/GenericLdapOperationTokenListener.java
Sun Apr 30 09:54:56 2006
@@ -0,0 +1,52 @@
+/*
+ *   Copyright 2006 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.directory.shared.ldap.trigger;
+
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev:$, $Date:$
+ */
+public class GenericLdapOperationTokenListener implements LdapOperationTokenListener
+{
+    public static final GenericLdapOperationTokenListener BindListener = new GenericLdapOperationTokenListener(
LdapOperation.BIND );
+    public static final GenericLdapOperationTokenListener UnbindListener = new GenericLdapOperationTokenListener(
LdapOperation.UNBIND );
+    public static final GenericLdapOperationTokenListener SearchListener = new GenericLdapOperationTokenListener(
LdapOperation.SEARCH );
+    public static final GenericLdapOperationTokenListener ModifyListener = new GenericLdapOperationTokenListener(
LdapOperation.MODIFY );
+    public static final GenericLdapOperationTokenListener AddListener = new GenericLdapOperationTokenListener(
LdapOperation.ADD );
+    public static final GenericLdapOperationTokenListener DelListener = new GenericLdapOperationTokenListener(
LdapOperation.DEL );
+    public static final GenericLdapOperationTokenListener ModDNListener = new GenericLdapOperationTokenListener(
LdapOperation.MODDN );
+    public static final GenericLdapOperationTokenListener CompareListener = new GenericLdapOperationTokenListener(
LdapOperation.COMPARE );
+    public static final GenericLdapOperationTokenListener AbandonListener = new GenericLdapOperationTokenListener(
LdapOperation.ABANDON );
+    public static final GenericLdapOperationTokenListener ExtendedListener = new GenericLdapOperationTokenListener(
LdapOperation.EXTENDED );
+    
+    private LdapOperation ldapOperation;
+    
+    private GenericLdapOperationTokenListener( LdapOperation ldapOperation )
+    {
+        this.ldapOperation = ldapOperation;
+    }
+
+    public boolean ldapOperationTokenRead( LdapOperation ldapOperation )
+    {
+        return this.ldapOperation.equals( ldapOperation ); 
+    }
+
+}

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperation.java
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperation.java?rev=398377&r1=398376&r2=398377&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperation.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperation.java
Sun Apr 30 09:54:56 2006
@@ -69,4 +69,23 @@
     {
         return name;
     }
+    
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        
+        if ( o instanceof LdapOperation )
+        {
+            LdapOperation operation = ( LdapOperation ) o;
+            return operation.getName().equals( getName() );
+            
+        }
+        else
+        {
+            return false;
+        }
+    }
 }

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperationTokenListener.java
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperationTokenListener.java?rev=398377&view=auto
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperationTokenListener.java
(added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/LdapOperationTokenListener.java
Sun Apr 30 09:54:56 2006
@@ -0,0 +1,29 @@
+/*
+ *   Copyright 2006 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.directory.shared.ldap.trigger;
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev:$, $Date:$
+ */
+public interface LdapOperationTokenListener
+{
+    public boolean ldapOperationTokenRead( LdapOperation ldapOperation );
+}

Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParser.java
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParser.java?rev=398377&r1=398376&r2=398377&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParser.java
(original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParser.java
Sun Apr 30 09:54:56 2006
@@ -99,7 +99,7 @@
      * @throws ParseException
      *          if there are any recognition errors (bad syntax)
      */
-    public synchronized TriggerSpecification parse( String spec ) throws ParseException
+    public synchronized TriggerSpecification parse( String spec ) throws ParseException,
ConditionalParserFailureBasedOnCallerFeedback
     {
         TriggerSpecification triggerSpecification = null;
 
@@ -129,6 +129,11 @@
         
         return triggerSpecification;
 
+    }
+    
+    public void registerLdapOperationTokenListener( LdapOperationTokenListener listener )
+    {
+        parser.registerLdapOperationTokenListener( listener );
     }
 
 

Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParserTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParserTest.java?rev=398377&r1=398376&r2=398377&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParserTest.java
(original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/trigger/TriggerSpecificationParserTest.java
Sun Apr 30 09:54:56 2006
@@ -18,10 +18,10 @@
 package org.apache.directory.shared.ldap.trigger;
 
 
-import org.apache.directory.shared.ldap.name.LdapName;
-
 import junit.framework.TestCase;
 
+import org.apache.directory.shared.ldap.name.LdapName;
+
 
 /**
  * Unit tests for {@link org.apache.directory.shared.ldap.trigger.TriggerSpecificationParser}.
@@ -57,6 +57,8 @@
 
     public void testWithOperationParameters() throws Exception
     {
+        parser.registerLdapOperationTokenListener( GenericLdapOperationTokenListener.DelListener
);
+        
         TriggerSpecification triggerSpecification = null;
         
         String spec = "BEFORE delete CALL \"BackupUtilities.backupDeletedEntry\" ($name,
$deletedEntry)";
@@ -77,6 +79,8 @@
     
     public void testWithGenericParameters() throws Exception
     {
+        parser.registerLdapOperationTokenListener( GenericLdapOperationTokenListener.AddListener
);
+        
         TriggerSpecification triggerSpecification = null;
         
         String spec = "AFTER add CALL \"Logger.logAddOperation\" ($entry, $attributes, $operationPrincipal)";
@@ -99,6 +103,8 @@
     
     public void testWithLanguageOptionAndComments() throws Exception
     {
+        parser.registerLdapOperationTokenListener( GenericLdapOperationTokenListener.SearchListener
);
+        
         TriggerSpecification triggerSpecification = null;
         
         String spec = "INSTEADOF search # do not do search \n" +
@@ -118,6 +124,8 @@
     
     public void testWithSearchContextOption() throws Exception
     {
+        parser.registerLdapOperationTokenListener( GenericLdapOperationTokenListener.BindListener
);
+        
         TriggerSpecification triggerSpecification = null;
         
         String spec = "BEFORE bind  # Action Time and Operation \n" +
@@ -138,6 +146,30 @@
         assertEquals( triggerSpecification.getStoredProcedureParameters().size(), 1 );
         assertTrue( triggerSpecification.getStoredProcedureParameters().contains(
             StoredProcedureParameter.BindStoredProcedureParameter.NAME ) );
+    }
+    
+    public void  testLdapOperationTokenListener() throws Exception
+    {
+        LdapOperationTokenListener expectedOperationToken = GenericLdapOperationTokenListener.CompareListener;
+        parser.registerLdapOperationTokenListener( expectedOperationToken );
+        
+        TriggerSpecification triggerSpecification = null;
+        
+        String longUnexpectedSpec = "INSTEADOF search \n" +
+            "CALL \"Search.customSearchSP\" \n" +
+                "{ searchContext { scope one } \"cn=Stored Procedures, ou=system\" } \n"
+
+                    "($baseObject, $scope, $derefAliases, $sizeLimit, $timeLimit, $timeLimit,
$filter, $attributes, $operationPrincipal)";
+
+        try
+        {
+            triggerSpecification = parser.parse( longUnexpectedSpec );
+            fail( "Unintended execution of this line." );
+        }
+        catch ( ConditionalParserFailureBasedOnCallerFeedback e )
+        {
+            assertEquals( e.getReadToken(), LdapOperation.SEARCH );
+            assertNull( triggerSpecification );
+        }
     }
     
 }



Mime
View raw message