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/24 23:48:49 UTC

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

Author: elecharny
Date: Fri Jun 24 14:48:47 2005
New Revision: 201682

URL: http://svn.apache.org/viewcvs?rev=201682&view=rev
Log:
Added the SearchResultEntry grammar's action

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

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultEntryGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultEntryGrammar.java?rev=201682&r1=201681&r2=201682&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultEntryGrammar.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultEntryGrammar.java Fri Jun 24 14:48:47 2005
@@ -25,8 +25,10 @@
 import org.apache.asn1.ber.tlv.TLV;
 import org.apache.asn1.ldap.codec.LdapMessageContainer;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
+import org.apache.asn1.ldap.codec.primitives.LdapString;
 import org.apache.asn1.ldap.pojo.LdapMessage;
 import org.apache.asn1.ldap.pojo.SearchResultEntry;
+import org.apache.asn1.primitives.OctetString;
 
 import org.apache.log4j.Logger;
 
@@ -65,7 +67,7 @@
      */
     private SearchResultEntryGrammar()
     {
-        name = SearchResultEntryGrammar.class.getName();
+        name       = SearchResultEntryGrammar.class.getName();
         statesEnum = LdapStatesEnum.getInstance();
 
         // Intitialisation
@@ -78,13 +80,15 @@
         // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { (Tag)
         // Nothing to do.
         super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TAG][0x64] = new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_TAG, LdapStatesEnum.SEARCH_RESULT_ENTRY_VALUE, null );
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_TAG, LdapStatesEnum.SEARCH_RESULT_ENTRY_VALUE,
+                null );
 
         // LdapMessage ::= ... SearchResultEntry ...
         // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { (Value)
         // Nothing to do.
         super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALUE][0x64] = new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_VALUE, LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG, 
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_VALUE,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG,
                 new GrammarAction( "Init SearchResultEntry" )
                 {
                     public void action( IAsn1Container container ) throws DecoderException
@@ -92,53 +96,239 @@
 
                         LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
                             container;
-                        LdapMessage      ldapMessage          =
+                        LdapMessage          ldapMessage          =
                             ldapMessageContainer.getLdapMessage();
+
                         // Now, we can allocate the SearchResultEntry Object
                         // And we associate it to the ldapMessage Object
                         ldapMessage.setProtocolOP( new SearchResultEntry() );
                     }
-                }  );
+                } );
 
         // LdapMessage ::= ... SearchResultEntry ...
-        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { 
+        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
         //    objectName      LDAPDN, (Tag)
         //    ...
         // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG][0x04] = new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG, LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE, null );
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE, null );
 
         // LdapMessage ::= ... SearchResultEntry ...
-        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { 
+        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
         //    objectName      LDAPDN, (Value)
         //    ...
         // Store the object name.
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE][0x04] = new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE, LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG, 
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG,
                 new GrammarAction( "Store search result entry object name Value" )
                 {
                     public void action( IAsn1Container container ) throws DecoderException
                     {
+
                         LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
-                        container;
-                        LdapMessage      ldapMessage          =
-                        ldapMessageContainer.getLdapMessage();
-                        SearchResultEntry searchResultEntry = ldapMessage.getSearchResultEntry();
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchResultEntry    searchResultEntry    =
+                            ldapMessage.getSearchResultEntry();
 
-                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+                        TLV                  tlv                  =
+                            ldapMessageContainer.getCurrentTLV();
 
                         // Store the value.
-                        searchResultEntry.setObjectName( new LdapDN( tlv.getValue().getData() ) );
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            searchResultEntry.setObjectName( LdapDN.EMPTY_STRING );
+                        }
+                        else
+                        {
+                            searchResultEntry.setObjectName( new LdapDN(
+                                    tlv.getValue().getData() ) );
+                        }
                     }
                 } );
 
-        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { 
+        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+        //    attributes      PartialAttributeList }
+        // PartialAttributeList ::= *SEQUENCE* OF SEQUENCE { (Tag)
+        //    ...
+        // Nothing to do
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG][0x30] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE, null );
+
+        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
         //    attributes      PartialAttributeList }
-        // PartialAttributeList ::= SEQUENCE OF SEQUENCE { (Tag)
+        // PartialAttributeList ::= *SEQUENCE* OF SEQUENCE { (Tag)
+        //    ...
+        // Loop.
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG][0x30] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE, null );
+
+        // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+        //    attributes      PartialAttributeList }
+        // PartialAttributeList ::= *SEQUENCE* OF SEQUENCE { (Tag)
         //    ...
         // We may have many attributes. Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG][0x30] = new GrammarTransition(
-                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG, LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE, null );
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE][0x30] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG, null );
+
+        // PartialAttributeList ::= SEQUENCE OF *SEQUENCE* { (Tag)
+        //    ...
+        // Nothing to do
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG][0x30] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE, null );
+
+        // PartialAttributeList ::= SEQUENCE OF *SEQUENCE* { (Value)
+        //    ...
+        // We may have many attributes. We also have to store a previously decoded AttributeValue
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE][0x30] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_TAG,
+                new GrammarAction( "Store attributeValue" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchResultEntry    searchResultEntry    =
+                            ldapMessage.getSearchResultEntry();
+
+                        searchResultEntry.addPartialAttributeList();
+                    }
+                } );
+
+        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+        //    type    AttributeDescription, (Tag)
+        //    ...
+        // Nothing to do.
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_TAG][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_TAG,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_VALUE, null );
+
+        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+        //    type    AttributeDescription, (Value)
+        //    ...
+        // Store the attribute's name.
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_VALUE][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_TYPE_VALUE,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_TAG,
+                new GrammarAction( "Store search result entry object name Value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchResultEntry    searchResultEntry    =
+                            ldapMessage.getSearchResultEntry();
+
+                        TLV                  tlv                  =
+                            ldapMessageContainer.getCurrentTLV();
+
+                        // Store the name
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            searchResultEntry.addAttributeValues( LdapString.EMPTY_STRING );
+                        }
+                        else
+                        {
+                            searchResultEntry.addAttributeValues( new LdapString(
+                                    tlv.getValue().getData() ) );
+                        }
+                    }
+                } );
+
+        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+        //    ...
+        //    vals    *SET OF* AttributeValue} (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_TAG][0x31] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_TAG,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_VALUE, null );
+
+        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+        //    ...
+        //    vals    *SET OF* AttributeValue} (Value)
+        // We may have many values. Nothing to do
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_VALUE][0x31] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_VALS_VALUE,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_TAG, null );
+
+        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+        //    ...
+        //    vals    SET OF *AttributeValue*} (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_TAG][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_TAG,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE, null );
+
+        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+        //    ...
+        //    vals    SET OF *AttributeValue*} (Tag)
+        // The loop.
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE, null );
+
+        // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+        //    ...
+        //    vals    SET OF *AttributeValue*} (Value)
+        // We may have many values. Store the current one in the current Attribute Value
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_VALUE,
+                LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG,
+                new GrammarAction( "Store Attribute Value value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer )
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+                        SearchResultEntry    searchResultEntry    =
+                            ldapMessage.getSearchResultEntry();
+
+                        TLV                  tlv                  =
+                            ldapMessageContainer.getCurrentTLV();
+
+                        // Store the name
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            searchResultEntry.addAttributeValue( OctetString.EMPTY_STRING );
+                        }
+                        else
+                        {
+                            searchResultEntry.addAttributeValue( new OctetString(
+                                    tlv.getValue().getData() ) );
+                        }
+                    }
+                } );
 
 
     }