directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r421724 - /directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/FilterGrammar.java
Date Thu, 13 Jul 2006 22:58:10 GMT
Author: elecharny
Date: Thu Jul 13 15:58:09 2006
New Revision: 421724

URL: http://svn.apache.org/viewvc?rev=421724&view=rev
Log:
- reformated comments 
- moved addCurrentFilter into SearchRequest class
- renamed compareFilterAction to terminalFilterAction
- moved unstackFilters method to SearchRequest class
- added a setTerminalFilter() to the SearchRequest class
- the terminalFilterAction method has been simplified

Modified:
    directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/FilterGrammar.java

Modified: directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/FilterGrammar.java
URL: http://svn.apache.org/viewvc/directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/FilterGrammar.java?rev=421724&r1=421723&r2=421724&view=diff
==============================================================================
--- directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/FilterGrammar.java
(original)
+++ directory/branches/shared/optimization/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/FilterGrammar.java
Thu Jul 13 15:58:09 2006
@@ -70,109 +70,106 @@
         // Create the transitions table
         super.transitions = new GrammarTransition[LdapStatesEnum.LAST_FILTER_STATE][256];
 
-        // ============================================================================================
+        //============================================================================================
         // Search Request And Filter
         // This is quite complicated, because we have a tree structure to build,
-        // and we may have many elements on each node. For instance, considering
-        // the
+        // and we may have many elements on each node. For instance, considering the 
         // search filter :
         // (& (| (a = b) (c = d)) (! (e = f)) (attr =* h))
         // We will have to create an And filter with three children :
-        // - an Or child,
-        // - a Not child
-        // - and a Present child.
+        //  - an Or child,
+        //  - a Not child
+        //  - and a Present child.
         // The Or child will also have two children.
         //
-        // We know when we have a children while decoding the PDU, because the
-        // length
+        // We know when we have a children while decoding the PDU, because the length
         // of its parent has not yet reached its expected length.
         //
         // This search filter :
         // (&(|(objectclass=top)(ou=contacts))(!(objectclass=ttt))(objectclass=*top))
         // is encoded like this :
-        // +----------------+---------------+
-        // | ExpectedLength | CurrentLength |
-        // +-----------------------------+----------------+---------------+
-        // |A0 52 | 82 | 0 | new level 1
-        // | A1 24 | 82 36 | 0 0 | new level 2
-        // | A3 12 | 82 36 18 | 0 0 0 | new level 3
-        // | 04 0B 'objectclass' | 82 36 18 | 0 0 13 |
-        // | 04 03 'top' | 82 36 18 | 0 20 18 |
-        // | | ^ ^ |
-        // | | | | |
-        // | | +---------------+ |
-        // +-----------------------------* end level 3 -------------------*
-        // | A3 0E | 82 36 14 | 0 0 0 | new level 3
-        // | 04 02 'ou' | 82 36 14 | 0 0 4 |
-        // | 04 08 'contacts' | 82 36 14 | 38 36 14 |
-        // | | ^ ^ ^ ^ |
-        // | | | | | | |
-        // | | | +-------------|--+ |
-        // | | +----------------+ |
-        // +-----------------------------* end level 3, end level 2 ------*
-        // | A2 14 | 82 20 | 38 0 | new level 2
-        // | A3 12 | 82 20 18 | 38 0 0 | new level 3
-        // | 04 0B 'objectclass' | 82 20 18 | 38 0 13 |
-        // | 04 03 'ttt' | 82 20 18 | 60 20 18 |
-        // | | ^ ^ ^ ^ |
-        // | | | | | | |
-        // | | | +-------------|--+ |
-        // | | +----------------+ |
-        // +-----------------------------* end level 3, end level 2 ------*
-        // | A4 14 | 82 20 | 60 0 | new level 2
-        // | 04 0B 'objectclass' | 82 20 | 60 13 |
-        // | 30 05 | 82 20 | 60 13 |
-        // | 82 03 'top' | 82 20 | 82 20 |
-        // | | ^ ^ ^ ^ |
-        // | | | | | | |
-        // | | | +-------------|--+ |
-        // | | +----------------+ |
-        // +-----------------------------* end level 2, end level 1 ------*
-        // +-----------------------------+----------------+---------------+
+        //                              +----------------+---------------+
+        //                              | ExpectedLength | CurrentLength |
+        //+-----------------------------+----------------+---------------+
+        //|A0 52                        | 82             | 0             | new level 1
+        //|   A1 24                     | 82 36          | 0 0           | new level 2
+        //|      A3 12                  | 82 36 18       | 0 0 0         | new level 3
+        //|         04 0B 'objectclass' | 82 36 18       | 0 0 13        |
+        //|         04 03 'top'         | 82 36 18       | 0 20 18       | 
+        //|                             |       ^               ^        |
+        //|                             |       |               |        |
+        //|                             |       +---------------+        |
+        //+-----------------------------* end level 3 -------------------*
+        //|      A3 0E                  | 82 36 14       | 0 0 0         | new level 3
+        //|         04 02 'ou'          | 82 36 14       | 0 0 4         |
+        //|         04 08 'contacts'    | 82 36 14       | 38 36 14      | 
+        //|                             |    ^  ^             ^  ^       |
+        //|                             |    |  |             |  |       |
+        //|                             |    |  +-------------|--+       |
+        //|                             |    +----------------+          |
+        //+-----------------------------* end level 3, end level 2 ------*
+        //|   A2 14                     | 82 20          | 38 0          | new level 2
+        //|      A3 12                  | 82 20 18       | 38 0 0        | new level 3
+        //|         04 0B 'objectclass' | 82 20 18       | 38 0 13       | 
+        //|         04 03 'ttt'         | 82 20 18       | 60 20 18      |
+        //|                             |    ^  ^             ^  ^       |
+        //|                             |    |  |             |  |       |
+        //|                             |    |  +-------------|--+       |
+        //|                             |    +----------------+          |
+        //+-----------------------------* end level 3, end level 2 ------*
+        //|   A4 14                     | 82 20          | 60 0          | new level 2
+        //|      04 0B 'objectclass'    | 82 20          | 60 13         |
+        //|      30 05                  | 82 20          | 60 13         |
+        //|         82 03 'top'         | 82 20          | 82 20         | 
+        //|                             | ^  ^             ^  ^          |
+        //|                             | |  |             |  |          |
+        //|                             | |  +-------------|--+          |
+        //|                             | +----------------+             |
+        //+-----------------------------* end level 2, end level 1 ------*
+        //+-----------------------------+----------------+---------------+
         //
         // When the current length equals the expected length of the parent PDU,
-        // then we are able to 'close' the parent : it has all its children.
-        // This
+        // then we are able to 'close' the parent : it has all its children. This
         // is propagated through all the tree, until either there are no more
         // parents, or the expected length of the parent is different from the
         // current length.
         //                              
-        // ============================================================================================
+        //============================================================================================
         // Filter ::= CHOICE {
-        // and [0] SET OF Filter, (Tag)
-        // ...
+        //     and             [0] SET OF Filter, (Tag)
+        //     ...
         // Nothing to do
         super.transitions[LdapStatesEnum.FILTER_TAG][LdapConstants.AND_FILTER_TAG] = new
GrammarTransition(
             LdapStatesEnum.FILTER_TAG, LdapStatesEnum.FILTER_AND_VALUE, null );
 
         // Filter ::= CHOICE {
-        // ...
-        // or [1] SET OF Filter, (Tag)
-        // ...
+        //     ...
+        //     or              [1] SET OF Filter, (Tag)
+        //     ...
         // Nothing to do
         super.transitions[LdapStatesEnum.FILTER_TAG][LdapConstants.OR_FILTER_TAG] = new GrammarTransition(
             LdapStatesEnum.FILTER_TAG, LdapStatesEnum.FILTER_OR_VALUE, null );
 
         // Filter ::= CHOICE {
-        // ...
-        // not [2] Filter, (Tag)
-        // ...
+        //     ...
+        //     not             [2] Filter, (Tag)
+        //     ...
         // Nothing to do
         super.transitions[LdapStatesEnum.FILTER_TAG][LdapConstants.NOT_FILTER_TAG] = new
GrammarTransition(
             LdapStatesEnum.FILTER_TAG, LdapStatesEnum.FILTER_NOT_VALUE, null );
 
         // Filter ::= CHOICE {
-        // ...
-        // equalityMatch [3] AttributeValueAssertion, (Tag)
-        // ...
+        //     ...
+        //     equalityMatch   [3] AttributeValueAssertion, (Tag)
+        //     ...
         // Nothing to do
         super.transitions[LdapStatesEnum.FILTER_TAG][LdapConstants.EQUALITY_MATCH_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_TAG, LdapStatesEnum.FILTER_EQUALITY_MATCH_VALUE, null );
 
         // Filter ::= CHOICE {
-        // ...
-        // substrings [4] SubstringFilter, (Tag)
-        // ...
+        //     ...
+        //     substrings      [4] SubstringFilter, (Tag)
+        //     ...
         // Nothing to do
         super.transitions[LdapStatesEnum.FILTER_TAG][LdapConstants.SUBSTRINGS_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_TAG, LdapStatesEnum.SUBSTRING_FILTER_GRAMMAR_SWITCH, new
GrammarAction( "Allow pop" )
@@ -184,40 +181,40 @@
             } );
 
         // Filter ::= CHOICE {
-        // ...
-        // greaterOrEqual [5] AttributeValueAssertion, (Tag)
-        // ...
+        //     ...
+        //     greaterOrEqual  [5] AttributeValueAssertion, (Tag)
+        //     ...
         // Nothing to do
         super.transitions[LdapStatesEnum.FILTER_TAG][LdapConstants.GREATER_OR_EQUAL_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_TAG, LdapStatesEnum.FILTER_GREATER_OR_EQUAL_VALUE, null
);
 
         // Filter ::= CHOICE {
-        // ...
-        // lessOrEqual [6] AttributeValueAssertion, (Tag)
-        // ...
+        //     ...
+        //     lessOrEqual     [6] AttributeValueAssertion, (Tag)
+        //     ...
         // Nothing to do
         super.transitions[LdapStatesEnum.FILTER_TAG][LdapConstants.LESS_OR_EQUAL_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_TAG, LdapStatesEnum.FILTER_LESS_OR_EQUAL_VALUE, null );
 
         // Filter ::= CHOICE {
-        // ...
-        // present [7] AttributeDescription, (Tag)
-        // ...
+        //     ...
+        //     present         [7] AttributeDescription, (Tag)
+        //     ...
         // Nothing to do
         super.transitions[LdapStatesEnum.FILTER_TAG][LdapConstants.PRESENT_FILTER_TAG] =
new GrammarTransition(
             LdapStatesEnum.FILTER_TAG, LdapStatesEnum.FILTER_PRESENT_VALUE, null );
 
         // Filter ::= CHOICE {
-        // ...
-        // approxMatch [8] AttributeValueAssertion, (Tag)
-        // ...
+        //     ...
+        //     approxMatch     [8] AttributeValueAssertion, (Tag)
+        //     ...
         // Nothing to do
         super.transitions[LdapStatesEnum.FILTER_TAG][LdapConstants.APPROX_MATCH_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_TAG, LdapStatesEnum.FILTER_APPROX_MATCH_VALUE, null );
 
         // Filter ::= CHOICE {
-        // ...
-        // extensibleMatch [9] ExtensibleMatchFilter } (Tag)
+        //     ...
+        //     extensibleMatch [9] ExtensibleMatchFilter } (Tag)
         // Nothing to do
         super.transitions[LdapStatesEnum.FILTER_TAG][LdapConstants.EXTENSIBLE_MATCH_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_TAG, LdapStatesEnum.MATCHING_RULE_ASSERTION_GRAMMAR_SWITCH,
new GrammarAction(
@@ -230,10 +227,9 @@
             } );
 
         // Filter ::= CHOICE {
-        // and [0] SET OF Filter, (Value)
-        // ...
-        // We just have to switch to the initial state of Filter, because this
-        // is what
+        //     and             [0] SET OF Filter, (Value)
+        //     ...
+        // We just have to switch to the initial state of Filter, because this is what
         // we will get !
         super.transitions[LdapStatesEnum.FILTER_AND_VALUE][LdapConstants.AND_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_AND_VALUE, LdapStatesEnum.FILTER_TAG, new GrammarAction(
"Init And Filter" )
@@ -256,33 +252,16 @@
                     // We can allocate the SearchRequest
                     Filter andFilter = new AndFilter();
 
-                    // 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.
-                        ( ( ConnectorFilter ) currentFilter ).addFilter( andFilter );
-                        andFilter.setParent( currentFilter );
-                    }
-                    else
-                    {
-                        // No parent. This Filter will become the root.
-                        searchRequest.setFilter( andFilter );
-                        andFilter.setParent( searchRequest );
-                    }
-
-                    searchRequest.setCurrentFilter( andFilter );
+                    // Set the filter
+                    searchRequest.addCurrentFilter( andFilter );
                 }
             } );
 
         // Filter ::= CHOICE {
-        // ...
-        // or [1] SET OF Filter, (Value)
-        // ...
-        // We just have to switch to the initial state of Filter, because this
-        // is what
+        //     ...
+        //     or              [1] SET OF Filter, (Value)
+        //     ...
+        // We just have to switch to the initial state of Filter, because this is what
         // we will get !
         super.transitions[LdapStatesEnum.FILTER_OR_VALUE][LdapConstants.OR_FILTER_TAG] =
new GrammarTransition(
             LdapStatesEnum.FILTER_OR_VALUE, LdapStatesEnum.FILTER_TAG, new GrammarAction(
"Init Or Filter" )
@@ -305,33 +284,16 @@
                     // We can allocate the SearchRequest
                     Filter orFilter = new OrFilter();
 
-                    // 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.
-                        ( ( ConnectorFilter ) currentFilter ).addFilter( orFilter );
-                        orFilter.setParent( currentFilter );
-                    }
-                    else
-                    {
-                        // No parent. This Filter will become the root.
-                        searchRequest.setFilter( orFilter );
-                        orFilter.setParent( searchRequest );
-                    }
-
-                    searchRequest.setCurrentFilter( orFilter );
+                    // Set the filter
+                    searchRequest.addCurrentFilter( orFilter );
                 }
             } );
 
         // Filter ::= CHOICE {
-        // ...
-        // not [2] Filter, (Value)
-        // ...
-        // We just have to switch to the initial state of Filter, because this
-        // is what
+        //     ...
+        //     not             [2] Filter, (Value)
+        //     ...
+        // We just have to switch to the initial state of Filter, because this is what
         // we will get !
         super.transitions[LdapStatesEnum.FILTER_NOT_VALUE][LdapConstants.NOT_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_NOT_VALUE, LdapStatesEnum.FILTER_TAG, new GrammarAction(
"Init Not Filter" )
@@ -354,33 +316,16 @@
                     // We can allocate the SearchRequest
                     Filter notFilter = new NotFilter();
 
-                    // 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.
-                        ( ( ConnectorFilter ) currentFilter ).addFilter( notFilter );
-                        notFilter.setParent( currentFilter );
-                    }
-                    else
-                    {
-                        // No parent. This Filter will become the root.
-                        searchRequest.setFilter( notFilter );
-                        notFilter.setParent( searchRequest );
-                    }
-
-                    searchRequest.setCurrentFilter( notFilter );
+                    // Set the filter
+                    searchRequest.addCurrentFilter( notFilter );
                 }
             } );
 
         // Filter ::= CHOICE {
-        // ...
-        // equalityMatch [3] AttributeValueAssertion, (Value)
-        // ...
-        // We will create the filter container (as this is an equalityMatch
-        // filter,
+        //     ...
+        //     equalityMatch   [3] AttributeValueAssertion, (Value)
+        //     ...
+        // We will create the filter container (as this is an equalityMatch filter,
         // we will create an AttributeValueAssertionFilter).
         super.transitions[LdapStatesEnum.FILTER_EQUALITY_MATCH_VALUE][LdapConstants.EQUALITY_MATCH_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_EQUALITY_MATCH_VALUE, LdapStatesEnum.FILTER_ATTRIBUTE_DESC_TAG,
new GrammarAction(
@@ -388,16 +333,15 @@
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {
-                    compareFilterAction( container, LdapConstants.EQUALITY_MATCH_FILTER );
+                    terminalFilterAction( container, LdapConstants.EQUALITY_MATCH_FILTER
);
                 }
             } );
 
         // Filter ::= CHOICE {
-        // ...
-        // greaterOrEqual [5] AttributeValueAssertion, (Value)
-        // ...
-        // We will create the filter container (as this is an GreaterOrEqual
-        // filter,
+        //     ...
+        //     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][LdapConstants.GREATER_OR_EQUAL_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_GREATER_OR_EQUAL_VALUE, LdapStatesEnum.FILTER_ATTRIBUTE_DESC_TAG,
new GrammarAction(
@@ -405,16 +349,15 @@
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {
-                    compareFilterAction( container, LdapConstants.GREATER_OR_EQUAL_FILTER
);
+                    terminalFilterAction( container, LdapConstants.GREATER_OR_EQUAL_FILTER
);
                 }
             } );
 
         // Filter ::= CHOICE {
-        // ...
-        // lessOrEqual [6] AttributeValueAssertion, (Value)
-        // ...
-        // We will create the filter container (as this is an lessOrEqual
-        // filter,
+        //     ...
+        //     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][LdapConstants.LESS_OR_EQUAL_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_LESS_OR_EQUAL_VALUE, LdapStatesEnum.FILTER_ATTRIBUTE_DESC_TAG,
new GrammarAction(
@@ -422,16 +365,15 @@
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {
-                    compareFilterAction( container, LdapConstants.LESS_OR_EQUAL_FILTER );
+                    terminalFilterAction( container, LdapConstants.LESS_OR_EQUAL_FILTER );
                 }
             } );
 
         // Filter ::= CHOICE {
-        // ...
-        // approxMatch [8] AttributeValueAssertion, (Value)
-        // ...
-        // We will create the filter container (as this is an approxMatch
-        // filter,
+        //     ...
+        //     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][LdapConstants.APPROX_MATCH_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_APPROX_MATCH_VALUE, LdapStatesEnum.FILTER_ATTRIBUTE_DESC_TAG,
new GrammarAction(
@@ -439,20 +381,20 @@
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {
-                    compareFilterAction( container, LdapConstants.APPROX_MATCH_FILTER );
+                    terminalFilterAction( container, LdapConstants.APPROX_MATCH_FILTER );
                 }
             } );
 
         // AttributeValueAssertion ::= SEQUENCE {
-        // attributeDesc AttributeDescription, (TAG)
-        // ...
+        //    attributeDesc   AttributeDescription, (TAG)
+        //     ...
         // Nothing to do.
         super.transitions[LdapStatesEnum.FILTER_ATTRIBUTE_DESC_TAG][UniversalTag.OCTET_STRING_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_ATTRIBUTE_DESC_TAG, LdapStatesEnum.FILTER_ATTRIBUTE_DESC_VALUE,
null );
 
         // AttributeValueAssertion ::= SEQUENCE {
-        // attributeDesc AttributeDescription, (VALUE)
-        // ...
+        //    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.
@@ -482,22 +424,22 @@
                         throw new DecoderException( "Invalid assertion description " + msg
+ ", : " + lsee.getMessage() );
                     }
 
-                    AttributeValueAssertionFilter currentFilter = ( AttributeValueAssertionFilter
) searchRequest
-                        .getCurrentFilter();
-                    currentFilter.setAssertion( assertion );
+                    AttributeValueAssertionFilter comparisonFilter = ( AttributeValueAssertionFilter
) searchRequest
+                        .getTerminalFilter();
+                    comparisonFilter.setAssertion( assertion );
                 }
             } );
 
         // AttributeValueAssertion ::= SEQUENCE {
-        // ...
-        // assertionValue AssertionValue } (TAG)
+        //     ...
+        //    assertionValue  AssertionValue } (TAG)
         // Nothing to do.
         super.transitions[LdapStatesEnum.FILTER_ASSERTION_VALUE_TAG][UniversalTag.OCTET_STRING_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_ASSERTION_VALUE_TAG, LdapStatesEnum.FILTER_ASSERTION_VALUE_VALUE,
null );
 
         // AttributeValueAssertion ::= SEQUENCE {
-        // ...
-        // assertionValue AssertionValue } (VALUE)
+        //     ...
+        //    assertionValue  AssertionValue } (VALUE)
         // We have to set the attribute description in the current filter.
         // It could be an equalityMatch, greaterOrEqual, lessOrEqual or an
         // approxMatch filter.
@@ -522,9 +464,9 @@
                         assertionValue = tlv.getValue().getData();
                     }
 
-                    AttributeValueAssertionFilter currentFilter = ( AttributeValueAssertionFilter
) searchRequest
-                        .getCurrentFilter();
-                    AttributeValueAssertion assertion = currentFilter.getAssertion();
+                    AttributeValueAssertionFilter terminalFilter = ( AttributeValueAssertionFilter
) searchRequest
+                        .getTerminalFilter();
+                    AttributeValueAssertion assertion = terminalFilter.getAssertion();
 
                     if ( ldapMessageContainer.isBinary( assertion.getAttributeDesc() ) )
                     {
@@ -537,14 +479,15 @@
 
                     // We now have to get back to the nearest filter which is
                     // not terminal.
-                    unstackFilters( container );
+                    searchRequest.unstackFilters( container );
+
                     container.grammarPopAllowed( true );
                 }
             } );
 
         // AttributeValueAssertion ::= SEQUENCE {
-        // attributeDesc AttributeDescription, (VALUE)
-        // ...
+        //    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.
@@ -581,24 +524,24 @@
                             throw new DecoderException( "Invalid assertion value " + msg
+ ", : " + lsee.getMessage() );
                         }
 
-                        AttributeValueAssertionFilter currentFilter = ( AttributeValueAssertionFilter
) searchRequest
-                            .getCurrentFilter();
-                        currentFilter.setAssertion( assertion );
+                        AttributeValueAssertionFilter terminalFilter = ( AttributeValueAssertionFilter
) searchRequest
+                            .getTerminalFilter();
+                        terminalFilter.setAssertion( assertion );
                     }
                 }
             } );
 
         // AttributeValueAssertion ::= SEQUENCE {
-        // ...
-        // assertionValue AssertionValue } (TAG)
+        //     ...
+        //    assertionValue  AssertionValue } (TAG)
         // Nothing to do.
         super.transitions[LdapStatesEnum.FILTER_ASSERTION_VALUE_TAG][UniversalTag.OCTET_STRING_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_ASSERTION_VALUE_TAG, LdapStatesEnum.FILTER_ASSERTION_VALUE_VALUE,
null );
 
         // Filter ::= CHOICE {
-        // ...
-        // present [7] AttributeDescription, (Value)
-        // ...
+        //     ...
+        //     present    [7] AttributeDescription, (Value)
+        //     ...
         super.transitions[LdapStatesEnum.FILTER_PRESENT_VALUE][LdapConstants.PRESENT_FILTER_TAG]
= new GrammarTransition(
             LdapStatesEnum.FILTER_PRESENT_VALUE, LdapStatesEnum.FILTER_TAG, new GrammarAction(
                 "Init present filter Value" )
@@ -614,23 +557,9 @@
                     // 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.
-                        ( ( ConnectorFilter ) currentFilter ).addFilter( presentFilter );
-                        presentFilter.setParent( currentFilter );
-                    }
-                    else
-                    {
-                        // No parent. This Filter will become the root.
-                        // searchRequest.setCurrentFilter(presentFilter);
-                        presentFilter.setParent( searchRequest );
-                        searchRequest.setFilter( presentFilter );
-                    }
+                    // add the filter to the request filter
+                    searchRequest.addCurrentFilter( presentFilter );
+                    searchRequest.setTerminalFilter( presentFilter );
 
                     String value = StringTools.utf8ToString( tlv.getValue().getData() );
 
@@ -657,7 +586,8 @@
 
                     // We now have to get back to the nearest filter which is
                     // not terminal.
-                    unstackFilters( container );
+                    searchRequest.unstackFilters( container );
+                    
                     container.grammarPopAllowed( true );
                 }
             } );
@@ -680,60 +610,22 @@
 
 
     /**
-     * This method is used to clear the filter's stack for terminated elements.
-     * An element is considered as terminated either if : - it's a final element
-     * (ie an element which cannot contains a Filter) - its current length
-     * equals its expected length.
-     * 
-     * @param container
-     *            The container being decoded
-     */
-    private void unstackFilters( IAsn1Container container )
-    {
-        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
-        LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage();
-        SearchRequest searchRequest = ldapMessage.getSearchRequest();
-
-        TLV tlv = ldapMessageContainer.getCurrentTLV();
-
-        // Get the parent, if any
-        Filter currentFilter = searchRequest.getCurrentFilter();
-
-        // We now have to check if the parent has been completed
-        if ( tlv.getParent().getExpectedLength() == 0 )
-        {
-            TLV parent = tlv.getParent();
-
-            // The parent has been completed, we have to switch it
-            while ( ( parent != null ) && ( parent.getExpectedLength() == 0 ) )
-            {
-                parent = parent.getParent();
-
-                if ( ( currentFilter != null ) && ( currentFilter.getParent() instanceof
Filter ) )
-                {
-                    currentFilter = ( Filter ) currentFilter.getParent();
-                }
-                else
-                {
-                    currentFilter = null;
-                    break;
-                }
-            }
-
-            searchRequest.setCurrentFilter( currentFilter );
-        }
-    }
-
-
-    /**
      * This method is used by each comparaison filters (=, <=, >= or ~=).
      * 
+     * We have two cases :
+     * 1) there is no previous current filter : this filter is the top level
+     * filter
+     * 2) there is a previous currentFilter : its necesseraly a connector,
+     * and the filter is added to its set of filters. We also update the 
+     * currentTerminalFilter, to be able to store the terminal filter value
+     * in it.
+     * 
      * @param container
      *            The LdapContainer
      * @throws DecoderException
      *             If any error occurs.
      */
-    private void compareFilterAction( IAsn1Container container, int filterType ) throws DecoderException
+    private void terminalFilterAction( IAsn1Container container, int filterType ) throws
DecoderException
     {
         LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) container;
         LdapMessage ldapMessage = ldapMessageContainer.getLdapMessage();
@@ -742,23 +634,10 @@
         // We can allocate the Attribute Value Assertion
         Filter filter = new AttributeValueAssertionFilter( filterType );
 
-        // 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.
-            ( ( ConnectorFilter ) currentFilter ).addFilter( filter );
-            filter.setParent( currentFilter );
-        }
-        else
-        {
-            // No parent. This Filter will become the root.
-            filter.setParent( searchRequest );
-            searchRequest.setFilter( filter );
-        }
-
-        searchRequest.setCurrentFilter( filter );
+        searchRequest.addCurrentFilter( filter );
+        
+        // Store the filter structure that still has to be
+        // fullfiled
+        searchRequest.setTerminalFilter( filter );
     }
 }



Mime
View raw message