You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/06/13 01:05:43 UTC

svn commit: r190325 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/FilterGrammar.java

Author: elecharny
Date: Sun Jun 12 16:05:42 2005
New Revision: 190325

URL: http://svn.apache.org/viewcvs?rev=190325&view=rev
Log:
Added the transition for the Present Filter.
Factorized the actions of =, <=, >= and ~= filter transitions.
Added the >=, <= and ~= transitions.

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/FilterGrammar.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/FilterGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/FilterGrammar.java?rev=190325&r1=190324&r2=190325&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/FilterGrammar.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/FilterGrammar.java Sun Jun 12 16:05:42 2005
@@ -34,6 +34,7 @@
 import org.apache.asn1.ldap.pojo.filters.Filter;
 import org.apache.asn1.ldap.pojo.filters.NotFilter;
 import org.apache.asn1.ldap.pojo.filters.OrFilter;
+import org.apache.asn1.ldap.pojo.filters.PresentFilter;
 import org.apache.asn1.primitives.OctetString;
 import org.apache.asn1.util.MutableString;
 
@@ -279,6 +280,7 @@
                 LdapStatesEnum.FILTER_AND_VALUE, LdapStatesEnum.FILTER_TAG, null);
 
         // Filter ::= CHOICE {
+        //     ...
         //     or              [1] SET OF Filter, (Length)
         //     ...
         // We have to control the length to know if we have a completed level or not.
@@ -333,6 +335,7 @@
                 } );
 
         // Filter ::= CHOICE {
+        //     ...
         //     or              [1] SET OF Filter, (Value)
         //     ...
         // We just have to switch to the initial state of Filter, because this is what
@@ -341,6 +344,7 @@
                 LdapStatesEnum.FILTER_OR_VALUE, LdapStatesEnum.FILTER_TAG, null);
 
         // Filter ::= CHOICE {
+        //     ...
         //     not             [2] Filter, (Length)
         //     ...
         // We have to control the length to know if we have a completed level or not.
@@ -397,6 +401,7 @@
                 } );
 
         // Filter ::= CHOICE {
+        //     ...
         //     not             [2] Filter, (Value)
         //     ...
         // We just have to switch to the initial state of Filter, because this is what
@@ -405,6 +410,7 @@
                 LdapStatesEnum.FILTER_NOT_VALUE, LdapStatesEnum.FILTER_TAG, null);
 
         // Filter ::= CHOICE {
+        //     ...
         //     equalityMatch   [3] AttributeValueAssertion, (Length)
         //     ...
         // We have to control the length to know if we have a completed level or not.
@@ -414,53 +420,12 @@
                 {
                     public void action( IAsn1Container container ) throws DecoderException
                     {
-                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
-                            container;
-                        LdapMessage      ldapMessage          =
-                            ldapMessageContainer.getLdapMessage();
-                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
-
-                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
-
-                        // We can allocate the SearchRequest
-                        Filter equalityMatchFilter = new AttributeValueAssertionFilter();
-                        
-                        // Get the parent, if any
-                        Filter currentFilter = searchRequest.getCurrentFilter();
-                        
-                        if (currentFilter != null)
-                        {
-                            // Ok, we have a parent. The new Filter will be added to
-                            // this parent, then. We also have to check the length
-                            // against the parent.
-                            checkLength( currentFilter, tlv );
-                            currentFilter.addFilter(equalityMatchFilter);
-                            equalityMatchFilter.setParent( currentFilter );
-                        }
-                        else
-                        {
-                            // No parent. This Filter will become the root.
-                            // First, check the length to see if it does not exceed its parent
-                            // expected length. (If there is no parent, we have to check the
-                            // length against the SearchRequest )
-                            checkLength( searchRequest, tlv );
-
-                            searchRequest.setCurrentFilter(equalityMatchFilter);
-                            equalityMatchFilter.setParent( searchRequest );
-                            searchRequest.setFilter(equalityMatchFilter);
-                        }
-
-                        searchRequest.setCurrentFilter(equalityMatchFilter);
-
-                        // As this is a new Constructed object, we have to init its length
-                        int expectedLength = tlv.getLength().getLength();
-
-                        equalityMatchFilter.setExpectedLength( expectedLength );
-                        equalityMatchFilter.setCurrentLength( 0 );
+                        compareFilterAction(container);
                     }
                 } );
 
         // Filter ::= CHOICE {
+        //     ...
         //     equalityMatch   [3] AttributeValueAssertion, (Value)
         //     ...
         // We will create the filter container (as this is an equalityMatch filter,
@@ -468,6 +433,78 @@
         super.transitions[LdapStatesEnum.FILTER_EQUALITY_MATCH_VALUE][0xA3] = new GrammarTransition(
                 LdapStatesEnum.FILTER_EQUALITY_MATCH_VALUE, LdapStatesEnum.FILTER_ATTRIBUTE_DESC_TAG, null); 
                 
+        // Filter ::= CHOICE {
+        //     ...
+        //     greaterOrEqual  [5] AttributeValueAssertion, (Length)
+        //     ...
+        // We have to control the length to know if we have a completed level or not.
+        super.transitions[LdapStatesEnum.FILTER_GREATER_OR_EQUAL_LENGTH][0xA5] = new GrammarTransition(
+                LdapStatesEnum.FILTER_GREATER_OR_EQUAL_LENGTH, LdapStatesEnum.FILTER_GREATER_OR_EQUAL_VALUE,
+                new GrammarAction( "Init Greater Or Equal Filter" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        compareFilterAction(container);
+                    }
+                } );
+
+        // Filter ::= CHOICE {
+        //     ...
+        //     greaterOrEqual  [5] AttributeValueAssertion, (Value)
+        //     ...
+        // We will create the filter container (as this is an GreaterOrEqual filter,
+        // we will create an AttributeValueAssertionFilter).
+        super.transitions[LdapStatesEnum.FILTER_GREATER_OR_EQUAL_VALUE][0xA5] = new GrammarTransition(
+                LdapStatesEnum.FILTER_GREATER_OR_EQUAL_VALUE, LdapStatesEnum.FILTER_ATTRIBUTE_DESC_TAG, null); 
+                
+        // Filter ::= CHOICE {
+        //     ...
+        //     lessOrEqual    [6] AttributeValueAssertion, (Length)
+        //     ...
+        // We have to control the length to know if we have a completed level or not.
+        super.transitions[LdapStatesEnum.FILTER_LESS_OR_EQUAL_LENGTH][0xA6] = new GrammarTransition(
+                LdapStatesEnum.FILTER_LESS_OR_EQUAL_LENGTH, LdapStatesEnum.FILTER_LESS_OR_EQUAL_VALUE,
+                new GrammarAction( "Init Less Or Equal Filter" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        compareFilterAction(container);
+                    }
+                } );
+
+        // Filter ::= CHOICE {
+        //     ...
+        //     lessOrEqual    [6] AttributeValueAssertion, (Value)
+        //     ...
+        // We will create the filter container (as this is an lessOrEqual filter,
+        // we will create an AttributeValueAssertionFilter).
+        super.transitions[LdapStatesEnum.FILTER_LESS_OR_EQUAL_VALUE][0xA6] = new GrammarTransition(
+                LdapStatesEnum.FILTER_LESS_OR_EQUAL_VALUE, LdapStatesEnum.FILTER_ATTRIBUTE_DESC_TAG, null); 
+                
+        // Filter ::= CHOICE {
+        //     ...
+        //     approxMatch    [8] AttributeValueAssertion, (Length)
+        //     ...
+        // We have to control the length to know if we have a completed level or not.
+        super.transitions[LdapStatesEnum.FILTER_APPROX_MATCH_LENGTH][0xA8] = new GrammarTransition(
+                LdapStatesEnum.FILTER_APPROX_MATCH_LENGTH, LdapStatesEnum.FILTER_APPROX_MATCH_VALUE,
+                new GrammarAction( "Init ApproxMatch Filter" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        compareFilterAction(container);
+                    }
+                } );
+
+        // Filter ::= CHOICE {
+        //     ...
+        //     approxMatch    [8] AttributeValueAssertion, (Value)
+        //     ...
+        // We will create the filter container (as this is an approxMatch filter,
+        // we will create an AttributeValueAssertionFilter).
+        super.transitions[LdapStatesEnum.FILTER_APPROX_MATCH_VALUE][0xA8] = new GrammarTransition(
+                LdapStatesEnum.FILTER_APPROX_MATCH_VALUE, LdapStatesEnum.FILTER_ATTRIBUTE_DESC_TAG, null); 
+                
         // AttributeValueAssertion ::= SEQUENCE {
         //    attributeDesc   AttributeDescription, (TAG)
         //     ...
@@ -597,6 +634,151 @@
                     }
                 });
 
+        // AttributeValueAssertion ::= SEQUENCE {
+        //    attributeDesc   AttributeDescription, (LENGTH)
+        //     ...
+        // We have to check the length
+        super.transitions[LdapStatesEnum.FILTER_ATTRIBUTE_DESC_LENGTH][0x04] = new GrammarTransition(
+                LdapStatesEnum.FILTER_ATTRIBUTE_DESC_LENGTH, LdapStatesEnum.FILTER_ATTRIBUTE_DESC_VALUE, 
+                new GrammarAction( "Check AttributeDesc length" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        // We will check the length against the current filter
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+                        Filter     currentFilter =
+                            searchRequest.getCurrentFilter();
+                        
+                        TLV                  tlv = ldapMessageContainer.getCurrentTLV();
+
+                        checkLength( currentFilter, tlv );
+                        return;
+                    }
+                });
+
+        // AttributeValueAssertion ::= SEQUENCE {
+        //    attributeDesc   AttributeDescription, (VALUE)
+        //     ...
+        // We have to set the attribute description in the current filter.
+        // It could be an equalityMatch, greaterOrEqual, lessOrEqual or an
+        // approxMatch filter.
+        super.transitions[LdapStatesEnum.FILTER_ATTRIBUTE_DESC_VALUE][0x04] = new GrammarTransition(
+                LdapStatesEnum.FILTER_ATTRIBUTE_DESC_VALUE, LdapStatesEnum.FILTER_ASSERTION_VALUE_TAG, 
+                new GrammarAction( "Init attributeDesc Value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+                        MutableString attributeDesc = LdapString.parse(tlv.getValue().getData());
+                        
+                        AttributeValueAssertion assertion = new AttributeValueAssertion();
+                        assertion.setAttributeDesc(attributeDesc);
+                        
+                        AttributeValueAssertionFilter currentFilter = (AttributeValueAssertionFilter)searchRequest.getCurrentFilter();
+                        currentFilter.setAssertion(assertion);
+                    }
+                });
+
+        // AttributeValueAssertion ::= SEQUENCE {
+        //     ...
+        //    assertionValue  AssertionValue } (TAG)
+        // Nothing to do.
+        super.transitions[LdapStatesEnum.FILTER_ASSERTION_VALUE_TAG][0x04] = new GrammarTransition(
+                LdapStatesEnum.FILTER_ASSERTION_VALUE_TAG, LdapStatesEnum.FILTER_ASSERTION_VALUE_LENGTH, null);
+
+        // Filter ::= CHOICE {
+        //     ...
+        //     present    [7] AttributeDescription, (Length)
+        //     ...
+        // nothing to do.
+        super.transitions[LdapStatesEnum.FILTER_PRESENT_LENGTH][0x87] = new GrammarTransition(
+                LdapStatesEnum.FILTER_PRESENT_LENGTH, LdapStatesEnum.FILTER_PRESENT_VALUE, 
+                /*new GrammarAction( "Check present filter length" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        // We will check the length against the current filter
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+                        Filter     currentFilter =
+                            searchRequest.getCurrentFilter();
+                        
+                        TLV                  tlv = ldapMessageContainer.getCurrentTLV();
+
+                        checkLength( currentFilter, tlv );
+                        return;
+                    }
+                }*/ null);
+
+        // Filter ::= CHOICE {
+        //     ...
+        //     present    [7] AttributeDescription, (Value)
+        //     ...
+        super.transitions[LdapStatesEnum.FILTER_PRESENT_VALUE][0x87] = new GrammarTransition(
+                LdapStatesEnum.FILTER_PRESENT_VALUE, LdapStatesEnum.FILTER_TAG, 
+                new GrammarAction( "Init present filter Value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                        container;
+                        LdapMessage      ldapMessage          =
+                        ldapMessageContainer.getLdapMessage();
+                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+
+                        // We can allocate the Attribute Value Assertion
+                        PresentFilter presentFilter = new PresentFilter();
+                        
+                        // Get the parent, if any
+                        Filter currentFilter = searchRequest.getCurrentFilter();
+                        
+                        if (currentFilter != null)
+                        {
+                            // Ok, we have a parent. The new Filter will be added to
+                            // this parent, then. We also have to check the length
+                            // against the parent.
+                            checkLength( currentFilter, tlv );
+                            currentFilter.addFilter(presentFilter);
+                            presentFilter.setParent( currentFilter );
+                        }
+                        else
+                        {
+                            // No parent. This Filter will become the root.
+                            // First, check the length to see if it does not exceed its parent
+                            // expected length. (If there is no parent, we have to check the
+                            // length against the SearchRequest )
+                            checkLength( searchRequest, tlv );
+
+                            searchRequest.setCurrentFilter(presentFilter);
+                            presentFilter.setParent( searchRequest );
+                            searchRequest.setFilter(presentFilter);
+                        }
+
+                        // Store the value.
+                        presentFilter.setAttributeDescription(LdapString.parse(tlv.getValue().getData()));
+                        //searchRequest.setCurrentFilter(presentFilter);
+                        
+                        // We now have to get back to the nearest filter which is not terminal.
+                        unstackCurrent(searchRequest);
+                    }
+                });
     }
 
     //~ Methods ------------------------------------------------------------------------------------
@@ -661,5 +843,58 @@
         }
         
         return;
+    }
+
+    /**
+     * This method is used by each comparaison filters (=, <=, >= or ~=).
+     * 
+     * @param container The LdapContainer
+     * @throws DecoderException If any error occurs.
+     */
+    private void compareFilterAction( IAsn1Container container ) throws DecoderException
+    {
+        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+            container;
+        LdapMessage      ldapMessage          =
+            ldapMessageContainer.getLdapMessage();
+        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+
+        // We can allocate the Attribute Value Assertion
+        Filter filter = new AttributeValueAssertionFilter();
+        
+        // Get the parent, if any
+        Filter currentFilter = searchRequest.getCurrentFilter();
+        
+        if (currentFilter != null)
+        {
+            // Ok, we have a parent. The new Filter will be added to
+            // this parent, then. We also have to check the length
+            // against the parent.
+            checkLength( currentFilter, tlv );
+            currentFilter.addFilter(filter);
+            filter.setParent( currentFilter );
+        }
+        else
+        {
+            // No parent. This Filter will become the root.
+            // First, check the length to see if it does not exceed its parent
+            // expected length. (If there is no parent, we have to check the
+            // length against the SearchRequest )
+            checkLength( searchRequest, tlv );
+
+            searchRequest.setCurrentFilter(filter);
+            filter.setParent( searchRequest );
+            searchRequest.setFilter(filter);
+        }
+
+        searchRequest.setCurrentFilter(filter);
+
+        // As this is a new Constructed object, we have to init its length
+        int expectedLength = tlv.getLength().getLength();
+
+        filter.setExpectedLength( expectedLength );
+        filter.setCurrentLength( 0 );
     }
 }