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/16 01:32:28 UTC

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

Author: elecharny
Date: Wed Jun 15 16:32:27 2005
New Revision: 190834

URL: http://svn.apache.org/viewcvs?rev=190834&view=rev
Log:
Added 90% of the Substring Filter grammar.

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=190834&r1=190833&r2=190834&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 Wed Jun 15 16:32:27 2005
@@ -29,6 +29,7 @@
 import org.apache.asn1.ldap.pojo.AttributeValueAssertion;
 import org.apache.asn1.ldap.pojo.LdapMessage;
 import org.apache.asn1.ldap.pojo.SearchRequest;
+import org.apache.asn1.ldap.pojo.SubstringFilter;
 import org.apache.asn1.ldap.pojo.filters.AndFilter;
 import org.apache.asn1.ldap.pojo.filters.AttributeValueAssertionFilter;
 import org.apache.asn1.ldap.pojo.filters.Filter;
@@ -778,7 +779,359 @@
                         // We now have to get back to the nearest filter which is not terminal.
                         unstackCurrent(searchRequest);
                     }
+                } );
+
+        // Here we are dealing with substrings. LDAP grammar is not very explicit about
+        // what is allowed (-- at least one must be present !!!), while RFC 2254 is
+        // really clear. So we will follow this RFC :
+        //
+        // substring ::= attr "=" [AttributeValue] any [AttributeValue]
+        // any       ::= "*" *(AttributeValue "*")
+        //
+        // Filter ::= CHOICE {
+        //     ...
+        //     substrings      [4] SubstringFilter, (Length)
+        //     ...
+        //
+        // Check the length
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_LENGTH][0xA4] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_LENGTH, LdapStatesEnum.FILTER_SUBSTRINGS_VALUE, 
+                new GrammarAction( "Init Substring Filter" )
+                {
+                    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 substringFilter = new SubstringFilter();
+                        
+                        // 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(substringFilter);
+                            substringFilter.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(substringFilter);
+                            searchRequest.setFilter(substringFilter);
+                            substringFilter.setParent( searchRequest );
+                        }
+
+                        // As this is a new Constructed object, we have to init its length
+                        int expectedLength = tlv.getLength().getLength();
+
+                        substringFilter.setExpectedLength( expectedLength );
+                        substringFilter.setCurrentLength( 0 );
+                    }
+                } );
+
+        // Filter ::= CHOICE {
+        //     ...
+        //     substrings      [4] SubstringFilter, (Value)
+        //     ...
+        // Nothing to do.
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_VALUE][0xA4] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_VALUE, LdapStatesEnum.FILTER_SUBSTRINGS_TYPE_TAG, null);
+        /* );
+               */
+
+        // SubstringFilter ::= SEQUENCE {
+        //     type            AttributeDescription, (Tag)
+        //     ...
+        // Nothing to do
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_TYPE_TAG][0x04] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_TYPE_TAG, LdapStatesEnum.FILTER_SUBSTRINGS_TYPE_LENGTH, null );
+
+        // SubstringFilter ::= SEQUENCE {
+        //     type            AttributeDescription, (Length)
+        //     ...
+        // 
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_TYPE_LENGTH][0x04] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_TYPE_LENGTH, LdapStatesEnum.FILTER_SUBSTRINGS_TYPE_VALUE, 
+                new GrammarAction( "Init Substring type Filter" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+
+                        // Get the filter
+                        Filter currentFilter = searchRequest.getCurrentFilter();
+                        
+                        // Check the length
+                        checkLength(currentFilter, tlv);
+
+                        // This is a constructed object, so we have to store its length
+                        int expectedLength = tlv.getLength().getLength();
+
+                        currentFilter.setExpectedLength( expectedLength );
+                        currentFilter.setCurrentLength( 0 );
+                        currentFilter.setParent( searchRequest );
+                    }
+                } );
+
+        // SubstringFilter ::= SEQUENCE {
+        //     type            AttributeDescription, (Value)
+        //     ...
+        // 
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_TYPE_VALUE][0x04] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_TYPE_VALUE, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_TAG, 
+                new GrammarAction( "Store substring 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();
+
+                        // Store the value.
+                        SubstringFilter substringFilter = (SubstringFilter)searchRequest.getCurrentFilter();
+                        substringFilter.setType(LdapString.parse(tlv.getValue().getData()));
+                    }
+                } );
+
+        // SubstringFilter ::= SEQUENCE {
+        //     ...
+        //     -- at least one must be present
+        //     substrings      SEQUENCE OF CHOICE { (Tag)
+        //          ...
+        // Nothing to do.
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_TAG][0x30] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_TAG, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_LENGTH, null );
+
+        // SubstringFilter ::= SEQUENCE {
+        //     ...
+        //     -- at least one must be present
+        //     substrings      SEQUENCE OF CHOICE { (Length)
+        //          ...
+        // Check the length.
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_LENGTH][0x30] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_LENGTH, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_VALUE, 
+                new GrammarAction( "Init Substring Substring Filter" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+
+                        Filter currentFilter = searchRequest.getCurrentFilter();
+                        
+                        // Check the length
+                        checkLength(currentFilter, tlv);
+                        
+                        // We have to store the length of the substring filter
+                        ((SubstringFilter)currentFilter).setSubstringsLength(tlv.getLength().getLength());
+                    }
+                } );
+
+        // SubstringFilter ::= SEQUENCE {
+        //     ...
+        //     -- at least one must be present
+        //     substrings      SEQUENCE OF CHOICE { (Value)
+        //          ...
+        // Nothing to do. Here, we may have two possibilities. We may have an "initial" value,
+        // or an "any" value
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_VALUE][0x30] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_VALUE, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_CHOICE_TAG, null );
+
+        // SubstringFilter ::= SEQUENCE {
+        //     ...
+        //     -- at least one must be present
+        //     substrings      SEQUENCE OF CHOICE {
+        //          initial [0] LDAPString, (Tag)
+        //          ...
+        // We have an "initial" value. Nothing to do.
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_CHOICE_TAG][0x80] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_CHOICE_TAG, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_INITIAL_LENGTH, null );
+
+        // SubstringFilter ::= SEQUENCE {
+        //     ...
+        //     -- at least one must be present
+        //     substrings      SEQUENCE OF CHOICE {
+        //          initial [0] LDAPString, (Length)
+        //          ...
+        // We have an "initial" value. Check the length.
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_INITIAL_LENGTH][0x80] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_INITIAL_LENGTH, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_INITIAL_VALUE, 
+                new GrammarAction( "Init Substring Substring Initial Filter" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+
+                        SubstringFilter currentFilter = (SubstringFilter)searchRequest.getCurrentFilter();
+                        
+                        // Check the length
+                        int newLength = currentFilter.getSubstringsLength() - tlv.getLength().getLength() - tlv.getLength().getSize() -1; 
+                        
+                        if (newLength < 0) 
+                        {
+                            throw new DecoderException("The substring filter length is exceeded by the 'initial' length");
+                        }
+                        else
+                        {
+                            currentFilter.setSubstringsLength(newLength);
+                        }
+                        
+                    }
+                });
+
+        // SubstringFilter ::= SEQUENCE {
+        //     ...
+        //     -- at least one must be present
+        //     substrings      SEQUENCE OF CHOICE {
+        //          initial [0] LDAPString, (Value)
+        //          ...
+        // Store the initial value.
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_INITIAL_VALUE][0x80] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_INITIAL_VALUE, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_TAG, 
+                new GrammarAction( "Store substring filter initial Value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                        container;
+                        LdapMessage      ldapMessage          =
+                        ldapMessageContainer.getLdapMessage();
+                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+
+                        // Store the value.
+                        SubstringFilter substringFilter = (SubstringFilter)searchRequest.getCurrentFilter();
+                        substringFilter.setInitialSubstrings(LdapString.parse(tlv.getValue().getData()));
+                    }
                 });
+                
+        // SubstringFilter ::= SEQUENCE {
+        //     ...
+        //     -- at least one must be present
+        //     substrings      SEQUENCE OF CHOICE { 
+        //          ...
+        //          any     [1] LDAPString, (Tag)
+        //          ...
+        // We have an 'any' value without an 'initial' value. Nothing to do.
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_CHOICE_TAG][0x81] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_CHOICE_TAG, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_LENGTH, null);
+
+        // SubstringFilter ::= SEQUENCE {
+        //     ...
+        //     -- at least one must be present
+        //     substrings      SEQUENCE OF CHOICE { 
+        //          initial [0] LDAPString,
+        //          any     [1] LDAPString, (Tag)
+        //          ...
+        // We had an 'initial' substring, and now we have an 'any' substring. Nothing to do.
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_TAG][0x81] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_TAG, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_LENGTH, null );
+
+
+        // SubstringFilter ::= SEQUENCE {
+        //     ...
+        //     -- at least one must be present
+        //     substrings      SEQUENCE OF CHOICE { 
+        //          ...
+        //          any     [1] LDAPString, (Length)
+        //          ...
+        // We had an 'initial' substring, and now we have an 'any' substring. Nothing to do.
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_LENGTH][0x81] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_LENGTH, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_VALUE, 
+                new GrammarAction( "Init Substring Substring any Filter" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+
+                        SubstringFilter currentFilter = (SubstringFilter)searchRequest.getCurrentFilter();
+                        
+                        // Check the length
+                        int newLength = currentFilter.getSubstringsLength() - tlv.getLength().getLength() - tlv.getLength().getSize() -1; 
+                        
+                        if (newLength < 0) 
+                        {
+                            throw new DecoderException("The substring filter length is exceeded by the 'any' length");
+                        }
+                        else
+                        {
+                            currentFilter.setSubstringsLength(newLength);
+                        }
+                        
+                    }
+                });
+
+        // SubstringFilter ::= SEQUENCE {
+        //     ...
+        //     -- at least one must be present
+        //     substrings      SEQUENCE OF CHOICE { 
+        //          ...
+        //          any     [1] LDAPString, (Value)
+        //          ...
+        // Store the 'any' value. 
+        super.transitions[LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_VALUE][0x81] = new GrammarTransition(
+                LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_VALUE, LdapStatesEnum.FILTER_SUBSTRINGS_SUBSTRINGS_ANY_VALUE_LOOP, 
+                new GrammarAction( "Store substring filter any Value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                        container;
+                        LdapMessage      ldapMessage          =
+                        ldapMessageContainer.getLdapMessage();
+                        SearchRequest searchRequest = ldapMessage.getSearchRequest();
+
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+
+                        // Store the value.
+                        SubstringFilter substringFilter = (SubstringFilter)searchRequest.getCurrentFilter();
+                        substringFilter.addAnySubstrings(LdapString.parse(tlv.getValue().getData()));
+                    }
+                });
+                
     }
 
     //~ Methods ------------------------------------------------------------------------------------