Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 91019 invoked from network); 21 Aug 2005 16:54:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Aug 2005 16:54:28 -0000 Received: (qmail 95814 invoked by uid 500); 21 Aug 2005 16:54:26 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 95669 invoked by uid 500); 21 Aug 2005 16:54:23 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 95599 invoked by uid 99); 21 Aug 2005 16:54:23 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Aug 2005 09:54:23 -0700 X-ASF-Spam-Status: No, hits=-9.6 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME,UPPERCASE_25_50 X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 21 Aug 2005 09:54:35 -0700 Received: (qmail 90416 invoked by uid 65534); 21 Aug 2005 16:54:15 -0000 Message-ID: <20050821165415.90415.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r234264 [6/11] - in /directory/shared/ldap/branches/new-codec-integration/apache2-provider/src: ./ java/ java/main/ java/main/org/ java/main/org/apache/ java/main/org/apache/asn1new/ java/main/org/apache/asn1new/ldap/ java/main/org/apache/a... Date: Sun, 21 Aug 2005 16:54:00 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyDNResponseGrammar.java URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyDNResponseGrammar.java?rev=234264&view=auto ============================================================================== --- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyDNResponseGrammar.java (added) +++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyDNResponseGrammar.java Sun Aug 21 09:53:27 2005 @@ -0,0 +1,114 @@ +/* + * Copyright 2005 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.asn1new.ldap.codec.grammar; + +import org.apache.asn1new.DecoderException; +import org.apache.asn1new.ber.containers.IAsn1Container; +import org.apache.asn1new.ber.grammar.AbstractGrammar; +import org.apache.asn1new.ber.grammar.GrammarAction; +import org.apache.asn1new.ber.grammar.GrammarTransition; +import org.apache.asn1new.ber.grammar.IGrammar; +import org.apache.asn1new.ber.tlv.UniversalTag; +import org.apache.asn1new.ldap.codec.LdapConstants; +import org.apache.asn1new.ldap.codec.LdapMessageContainer; +import org.apache.asn1new.ldap.pojo.LdapMessage; +import org.apache.asn1new.ldap.pojo.ModifyDNResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This class implements the ModifyDNResponse LDAP message. All the actions are declared in this + * class. As it is a singleton, these declaration are only done once. + * + * @author Apache Directory Project + */ +public class ModifyDNResponseGrammar extends AbstractGrammar implements IGrammar +{ + //~ Static fields/initializers ----------------------------------------------------------------- + + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( ModifyDNResponseGrammar.class ); + + /** Logging speed up */ + private static final boolean DEBUG = log.isDebugEnabled(); + + /** The instance of grammar. ModifyDNResponseGrammar is a singleton */ + private static IGrammar instance = new ModifyDNResponseGrammar(); + + //~ Constructors ------------------------------------------------------------------------------- + + /** + * Creates a new ModifyDNResponseGrammar object. + */ + private ModifyDNResponseGrammar() + { + name = ModifyDNResponseGrammar.class.getName(); + statesEnum = LdapStatesEnum.getInstance(); + + // Intitialisation + super.transitions = new GrammarTransition[LdapStatesEnum.LAST_MODIFY_DN_RESPONSE_STATE][256]; + + //============================================================================================ + // ModifyDNResponse Message + //============================================================================================ + // LdapMessage ::= ... ModifyDNResponse ... + // ModifyDNResponse ::= [APPLICATION 13] LDAPResult (Tag) + // Nothing to do. + super.transitions[LdapStatesEnum.MODIFY_RESPONSE_TAG][LdapConstants.MODIFY_DN_RESPONSE_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_RESPONSE_TAG, LdapStatesEnum.MODIFY_DN_RESPONSE_VALUE, null ); + + // LdapMessage ::= ... ModifyDNResponse ... + // ModifyDNResponse ::= [APPLICATION 13] LDAPResult (Value) + // The next Tag will be the LDAPResult Tag (0x0A). + // We will switch the grammar then. + super.transitions[LdapStatesEnum.MODIFY_DN_RESPONSE_VALUE][LdapConstants.MODIFY_DN_RESPONSE_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_DN_RESPONSE_VALUE, LdapStatesEnum.MODIFY_DN_RESPONSE_LDAP_RESULT, + new GrammarAction( "Init ModifyDNResponse" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // And we associate it to the ldapMessage Object + ldapMessage.setProtocolOP( new ModifyDNResponse() ); + } + } ); + + // LdapMessage ::= ... ModifyDNResponse ... + // ModifyDNResponse ::= [APPLICATION 13] LDAPResult (Value) + // Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar. + super.transitions[LdapStatesEnum.MODIFY_DN_RESPONSE_LDAP_RESULT][UniversalTag.ENUMERATED_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_DN_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, null ); + } + + //~ Methods ------------------------------------------------------------------------------------ + + /** + * Get the instance of this grammar + * + * @return An instance on the LdapMessage Grammar + */ + public static IGrammar getInstance() + { + return instance; + } +} Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyRequestGrammar.java URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyRequestGrammar.java?rev=234264&view=auto ============================================================================== --- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyRequestGrammar.java (added) +++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyRequestGrammar.java Sun Aug 21 09:53:27 2005 @@ -0,0 +1,406 @@ +/* + * Copyright 2005 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.asn1new.ldap.codec.grammar; + +import org.apache.asn1new.DecoderException; +import org.apache.asn1new.ber.containers.IAsn1Container; +import org.apache.asn1new.ber.grammar.AbstractGrammar; +import org.apache.asn1new.ber.grammar.GrammarAction; +import org.apache.asn1new.ber.grammar.GrammarTransition; +import org.apache.asn1new.ber.grammar.IGrammar; +import org.apache.asn1new.ber.tlv.TLV; +import org.apache.asn1new.ber.tlv.UniversalTag; +import org.apache.asn1new.util.IntegerDecoder; +import org.apache.asn1new.primitives.OctetString; +import org.apache.asn1new.ldap.codec.LdapConstants; +import org.apache.asn1new.ldap.codec.LdapMessageContainer; +import org.apache.asn1new.ldap.codec.primitives.LdapDN; +import org.apache.asn1new.ldap.codec.primitives.LdapString; +import org.apache.asn1new.ldap.pojo.LdapMessage; +import org.apache.asn1new.ldap.pojo.ModifyRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This class implements the ModifyRequest LDAP message. All the actions are declared in this + * class. As it is a singleton, these declaration are only done once. + * + * @author Apache Directory Project + */ +public class ModifyRequestGrammar extends AbstractGrammar implements IGrammar +{ + //~ Static fields/initializers ----------------------------------------------------------------- + + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( ModifyRequestGrammar.class ); + + /** Logging speed up */ + private static final boolean DEBUG = log.isDebugEnabled(); + + /** The instance of grammar. ModifyRequestGrammar is a singleton */ + private static IGrammar instance = new ModifyRequestGrammar(); + + //~ Constructors ------------------------------------------------------------------------------- + + /** + * Creates a new ModifyRequestGrammar object. + */ + private ModifyRequestGrammar() + { + name = ModifyRequestGrammar.class.getName(); + statesEnum = LdapStatesEnum.getInstance(); + + // Intitialisation + super.transitions = new GrammarTransition[LdapStatesEnum.LAST_MODIFY_REQUEST_STATE][256]; + + //============================================================================================ + // ModifyRequest Message + //============================================================================================ + // LdapMessage ::= ... ModifyRequest ... + // ModifyRequest ::= [APPLICATION 6] SEQUENCE { (Tag) + // Nothing to do. + super.transitions[LdapStatesEnum.MODIFY_REQUEST_TAG][LdapConstants.MODIFY_REQUEST_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_TAG, LdapStatesEnum.MODIFY_REQUEST_VALUE, null ); + + // LdapMessage ::= ... ModifyRequest ... + // ModifyRequest ::= [APPLICATION 6] SEQUENCE { (Value) + // Create the structure + super.transitions[LdapStatesEnum.MODIFY_REQUEST_VALUE][LdapConstants.MODIFY_REQUEST_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_VALUE, LdapStatesEnum.MODIFY_REQUEST_OBJECT_TAG, + new GrammarAction( "Init ModifyRequest" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // Now, we can allocate the ModifyRequest Object + // And we associate it to the ldapMessage Object + ldapMessage.setProtocolOP( new ModifyRequest() ); + } + } ); + + // LdapMessage ::= ... ModifyRequest ... + // ModifyRequest ::= [APPLICATION 6] SEQUENCE { + // object LDAPDN, (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_OBJECT_TAG][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_OBJECT_TAG, + LdapStatesEnum.MODIFY_REQUEST_OBJECT_VALUE, null ); + + // LdapMessage ::= ... ModifyRequest ... + // ModifyRequest ::= [APPLICATION 6] SEQUENCE { + // object LDAPDN, (Value) + // ... + // Store the object name. + super.transitions[LdapStatesEnum.MODIFY_REQUEST_OBJECT_VALUE][UniversalTag.OCTET_STRING_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_OBJECT_VALUE, + LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_TAG, + new GrammarAction( "Store Modify request object Value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + ModifyRequest modifyRequest = ldapMessage.getModifyRequest(); + + TLV tlv = + ldapMessageContainer.getCurrentTLV(); + + // Store the value. + if ( tlv.getLength().getLength() == 0 ) + { + modifyRequest.setObject( LdapDN.EMPTY_STRING ); + } + else + { + modifyRequest.setObject( new LdapDN( + tlv.getValue().getData() ) ); + } + } + } ); + + // LdapMessage ::= ... ModifyRequest ... + // ModifyRequest ::= [APPLICATION 6] SEQUENCE { + // ... + // modification *SEQUENCE* OF SEQUENCE { (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_TAG][UniversalTag.SEQUENCE_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_TAG, + LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_VALUE, null ); + + // LdapMessage ::= ... ModifyRequest ... + // ModifyRequest ::= [APPLICATION 6] SEQUENCE { + // ... + // modification *SEQUENCE* OF SEQUENCE { (Value) + // Allocates the array list + super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_VALUE][UniversalTag.SEQUENCE_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_MODIFICATIONS_VALUE, + LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_TAG, + new GrammarAction( "Init modifications array list" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + ModifyRequest modifyRequest = ldapMessage.getModifyRequest(); + + modifyRequest.initModifications(); + } + } ); + + // LdapMessage ::= ... ModifyRequest ... + // ModifyRequest ::= [APPLICATION 6] SEQUENCE { + // ... + // modification SEQUENCE OF *SEQUENCE* { (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_TAG][UniversalTag.SEQUENCE_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_TAG, + LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_VALUE, null ); + + // LdapMessage ::= ... ModifyRequest ... + // ModifyRequest ::= [APPLICATION 6] SEQUENCE { + // ... + // modification SEQUENCE OF *SEQUENCE* { (Tag) + // Nothing to do + // This is a loop, when dealing with more than one modification + super.transitions[LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_OR_MODIFICATION_TAG][UniversalTag.SEQUENCE_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_OR_MODIFICATION_TAG, + LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_VALUE, null ); + + // LdapMessage ::= ... ModifyRequest ... + // ModifyRequest ::= [APPLICATION 6] SEQUENCE { + // ... + // modification SEQUENCE OF *SEQUENCE* { (Value) + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_VALUE][UniversalTag.SEQUENCE_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_SEQUENCE_VALUE, + LdapStatesEnum.MODIFY_REQUEST_OPERATION_TAG, null ); + + // ... + // modification SEQUENCE OF SEQUENCE { + // operation ENUMERATED { (Tag) + // add (0), + // delete (1), + // replace (2) }, + // ... + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_OPERATION_TAG][UniversalTag.ENUMERATED_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_OPERATION_TAG, + LdapStatesEnum.MODIFY_REQUEST_OPERATION_VALUE, null ); + + // ... + // modification SEQUENCE OF SEQUENCE { + // operation ENUMERATED { (Value) + // add (0), + // delete (1), + // replace (2) }, + // ... + // Store the operation type. We put it in a temporary storage, + // because we can't allocate a ModificationItem before knowing + // the attributes'name. + super.transitions[LdapStatesEnum.MODIFY_REQUEST_OPERATION_VALUE][UniversalTag.ENUMERATED_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_OPERATION_VALUE, + LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_TAG, + new GrammarAction( "Store operation type" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + ModifyRequest modifyRequest = ldapMessage.getModifyRequest(); + + TLV tlv = + ldapMessageContainer.getCurrentTLV(); + + // Decode the operation type + int operation = IntegerDecoder.parse( tlv.getValue(), 0, 2 ); + + // Store the current operation. + modifyRequest.setCurrentOperation( operation ); + } + } ); + + // ... + // modification SEQUENCE OF SEQUENCE { + // modification AttributeTypeAndValues } } + // AttributeTypeAndValues ::= SEQUENCE { (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_TAG][UniversalTag.SEQUENCE_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_TAG, + LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_VALUE, null ); + + // ... + // modification SEQUENCE OF SEQUENCE { + // modification AttributeTypeAndValues } } + // AttributeTypeAndValues ::= SEQUENCE { (Value) + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_VALUE][UniversalTag.SEQUENCE_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_MODIFICATION_VALUE, + LdapStatesEnum.MODIFY_REQUEST_TYPE_TAG, null ); + + // AttributeTypeAndValues ::= SEQUENCE { + // type AttributeDescription, (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_TYPE_TAG][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_TYPE_TAG, LdapStatesEnum.MODIFY_REQUEST_TYPE_VALUE, + null ); + + // AttributeTypeAndValues ::= SEQUENCE { + // type AttributeDescription, (Value) + // ... + // Store a new attribute type and values. + super.transitions[LdapStatesEnum.MODIFY_REQUEST_TYPE_VALUE][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_TYPE_VALUE, LdapStatesEnum.MODIFY_REQUEST_VALS_TAG, + new GrammarAction( "Store type" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + ModifyRequest modifyRequest = ldapMessage.getModifyRequest(); + + TLV tlv = + ldapMessageContainer.getCurrentTLV(); + + // Store the value. It can't be null + if ( tlv.getLength().getLength() == 0 ) + { + throw new DecoderException( "The type can't be null" ); + } + else + { + modifyRequest.addAttributeTypeAndValues( new LdapString( + tlv.getValue().getData() ) ); + } + } + } ); + + // AttributeTypeAndValues ::= SEQUENCE { + // ... + // vals SET OF AttributeValue } (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_VALS_TAG][UniversalTag.SET_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_VALS_TAG, LdapStatesEnum.MODIFY_REQUEST_VALS_VALUE, + null ); + + // AttributeTypeAndValues ::= SEQUENCE { + // ... + // vals SET OF AttributeValue } (Value) + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_VALS_VALUE][UniversalTag.SET_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_VALS_VALUE, + LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_TAG, null ); + + // AttributeTypeAndValues ::= SEQUENCE { + // ... + // vals SET OF AttributeValue } + // AttributeValue ::= OCTET STRING (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_TAG][UniversalTag.OCTET_STRING_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_TAG, + LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_VALUE, null ); + + // AttributeTypeAndValues ::= SEQUENCE { + // ... + // vals SET OF AttributeValue } + // AttributeValue ::= OCTET STRING (Tag) + // This is a loop, when dealing with multi-valued attributes + super.transitions[LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_OR_MODIFICATION_TAG][UniversalTag.OCTET_STRING_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_OR_MODIFICATION_TAG, + LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_VALUE, null ); + + // AttributeTypeAndValues ::= SEQUENCE { + // ... + // vals SET OF AttributeValue } + // AttributeValue ::= OCTET STRING (Value) + // Store a new attribute value. + super.transitions[LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_VALUE][UniversalTag.OCTET_STRING_TAG] = + new GrammarTransition( + LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_VALUE, + LdapStatesEnum.MODIFY_REQUEST_ATTRIBUTE_VALUE_OR_MODIFICATION_TAG, + new GrammarAction( "Store value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + ModifyRequest modifyRequest = ldapMessage.getModifyRequest(); + + TLV tlv = + ldapMessageContainer.getCurrentTLV(); + + // Store the value. It can't be null + if ( tlv.getLength().getLength() == 0 ) + { + modifyRequest.addAttributeValue( OctetString.EMPTY_STRING ); + } + else + { + modifyRequest.addAttributeValue( new OctetString( + tlv.getValue().getData() ) ); + } + } + } ); + + } + + //~ Methods ------------------------------------------------------------------------------------ + + /** + * Get the instance of this grammar + * + * @return An instance on the ModifyRequest Grammar + */ + public static IGrammar getInstance() + { + return instance; + } +} Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyResponseGrammar.java URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyResponseGrammar.java?rev=234264&view=auto ============================================================================== --- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyResponseGrammar.java (added) +++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/ModifyResponseGrammar.java Sun Aug 21 09:53:27 2005 @@ -0,0 +1,114 @@ +/* + * Copyright 2005 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.asn1new.ldap.codec.grammar; + +import org.apache.asn1new.DecoderException; +import org.apache.asn1new.ber.containers.IAsn1Container; +import org.apache.asn1new.ber.grammar.AbstractGrammar; +import org.apache.asn1new.ber.grammar.GrammarAction; +import org.apache.asn1new.ber.grammar.GrammarTransition; +import org.apache.asn1new.ber.grammar.IGrammar; +import org.apache.asn1new.ber.tlv.UniversalTag; +import org.apache.asn1new.ldap.codec.LdapConstants; +import org.apache.asn1new.ldap.codec.LdapMessageContainer; +import org.apache.asn1new.ldap.pojo.LdapMessage; +import org.apache.asn1new.ldap.pojo.ModifyResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This class implements the ModifyResponse LDAP message. All the actions are declared in this + * class. As it is a singleton, these declaration are only done once. + * + * @author Apache Directory Project + */ +public class ModifyResponseGrammar extends AbstractGrammar implements IGrammar +{ + //~ Static fields/initializers ----------------------------------------------------------------- + + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( ModifyResponseGrammar.class ); + + /** Logging speed up */ + private static final boolean DEBUG = log.isDebugEnabled(); + + /** The instance of grammar. ModifyResponseGrammar is a singleton */ + private static IGrammar instance = new ModifyResponseGrammar(); + + //~ Constructors ------------------------------------------------------------------------------- + + /** + * Creates a new ModifyResponseGrammar object. + */ + private ModifyResponseGrammar() + { + name = ModifyResponseGrammar.class.getName(); + statesEnum = LdapStatesEnum.getInstance(); + + // Intitialisation + super.transitions = new GrammarTransition[LdapStatesEnum.LAST_MODIFY_RESPONSE_STATE][256]; + + //============================================================================================ + // ModifyResponse Message + //============================================================================================ + // LdapMessage ::= ... ModifyResponse ... + // ModifyResponse ::= [APPLICATION 7] LDAPResult (Tag) + // Nothing to do. + super.transitions[LdapStatesEnum.MODIFY_RESPONSE_TAG][LdapConstants.MODIFY_RESPONSE_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_RESPONSE_TAG, LdapStatesEnum.MODIFY_RESPONSE_VALUE, null ); + + // LdapMessage ::= ... ModifyResponse ... + // ModifyResponse ::= [APPLICATION 7] LDAPResult (Value) + // The next Tag will be the LDAPResult Tag (0x0A). + // We will switch the grammar then. + super.transitions[LdapStatesEnum.MODIFY_RESPONSE_VALUE][LdapConstants.MODIFY_RESPONSE_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_RESPONSE_VALUE, LdapStatesEnum.MODIFY_RESPONSE_LDAP_RESULT, + new GrammarAction( "Init ModifyResponse" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // We associate it to the ldapMessage Object + ldapMessage.setProtocolOP( new ModifyResponse() ); + } + } ); + + // LdapMessage ::= ... ModifyResponse ... + // ModifyResponse ::= [APPLICATION 7] LDAPResult (Value) + // Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar. + super.transitions[LdapStatesEnum.MODIFY_RESPONSE_LDAP_RESULT][UniversalTag.ENUMERATED_TAG] = new GrammarTransition( + LdapStatesEnum.MODIFY_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, null ); + } + + //~ Methods ------------------------------------------------------------------------------------ + + /** + * Get the instance of this grammar + * + * @return An instance on the LdapMessage Grammar + */ + public static IGrammar getInstance() + { + return instance; + } +} Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchRequestGrammar.java URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchRequestGrammar.java?rev=234264&view=auto ============================================================================== --- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchRequestGrammar.java (added) +++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchRequestGrammar.java Sun Aug 21 09:53:27 2005 @@ -0,0 +1,607 @@ +/* + * Copyright 2005 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.asn1new.ldap.codec.grammar; + +import org.apache.asn1new.DecoderException; +import org.apache.asn1new.ber.containers.IAsn1Container; +import org.apache.asn1new.ber.grammar.AbstractGrammar; +import org.apache.asn1new.ber.grammar.GrammarAction; +import org.apache.asn1new.ber.grammar.GrammarTransition; +import org.apache.asn1new.ber.grammar.IGrammar; +import org.apache.asn1new.ber.tlv.TLV; +import org.apache.asn1new.ber.tlv.UniversalTag; +import org.apache.asn1new.ber.tlv.Value; +import org.apache.asn1new.util.IntegerDecoder; +import org.apache.asn1new.ldap.codec.LdapConstants; +import org.apache.asn1new.ldap.codec.LdapMessageContainer; +import org.apache.asn1new.ldap.codec.primitives.LdapDN; +import org.apache.asn1new.ldap.codec.primitives.LdapString; +import org.apache.asn1new.ldap.pojo.LdapMessage; +import org.apache.asn1new.ldap.pojo.SearchRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This class implements the SearchRequest LDAP message. All the actions are declared in this + * class. As it is a singleton, these declaration are only done once. + * + * If an action is to be added or modified, this is where the work is to be done ! + * + * @author Apache Directory Project + */ +public class SearchRequestGrammar extends AbstractGrammar implements IGrammar +{ + //~ Static fields/initializers ----------------------------------------------------------------- + + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( SearchRequestGrammar.class ); + + /** Logging speed up */ + private static final boolean DEBUG = log.isDebugEnabled(); + + /** The instance of grammar. SearchRequestGrammar is a singleton */ + private static IGrammar instance = new SearchRequestGrammar(); + + //~ Constructors ------------------------------------------------------------------------------- + + /** + * Creates a new SearchRequestGrammar object. + */ + private SearchRequestGrammar() + { + name = SearchRequestGrammar.class.getName(); + statesEnum = LdapStatesEnum.getInstance(); + + // Initialisation of the transitions table + super.transitions = new GrammarTransition[LdapStatesEnum.LAST_SEARCH_REQUEST_STATE][256]; + + //============================================================================================ + // SearchRequest Message + //============================================================================================ + // LdapMessage ::= ... SearchRequest ... + // SearchRequest ::= [APPLICATION 3] SEQUENCE { (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TAG][LdapConstants.SEARCH_REQUEST_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_TAG, LdapStatesEnum.SEARCH_REQUEST_VALUE, null ); + + // LdapMessage ::= ... SearchRequest ... + // SearchRequest ::= [APPLICATION 3] SEQUENCE { ... (Value) + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_VALUE][LdapConstants.SEARCH_REQUEST_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_VALUE, LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_TAG, + new GrammarAction( "Init SearchRequest" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // Now, we can allocate the SearchRequest + // And we associate it to the ldapMessage Object + ldapMessage.setProtocolOP( new SearchRequest() ); + } + }); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // baseObject LDAPDN, (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_TAG][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_TAG, LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_VALUE, + null); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // baseObject LDAPDN, (Value) + // ... + // We have a value for the base object, we will store it in the message + super.transitions[LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_VALUE][UniversalTag.OCTET_STRING_TAG] = + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_BASE_OBJECT_VALUE, + LdapStatesEnum.SEARCH_REQUEST_SCOPE_TAG, + new GrammarAction( "store base object value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + + SearchRequest searchRequest = + ldapMessageContainer.getLdapMessage().getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // We have to check that this is a correct DN + LdapDN baseObject = null; + + // We have to handle the special case of a 0 length base object, + // which is not permitted + if ( tlv.getLength().getLength() == 0 ) + { + throw new DecoderException("The base object must not be null"); + } + + try + { + baseObject = new LdapDN(tlv.getValue().getData()); + } + catch (DecoderException de) + { + log.error("The DN " + baseObject.toString() + " is invalid"); + throw de; + } + + searchRequest.setBaseObject(baseObject); + + return; + } + } ); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // ... + // scope ENUMERATED { + // baseObject (0), + // singleLevel (1), + // wholeSubtree (2) }, (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_SCOPE_TAG][UniversalTag.ENUMERATED_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_SCOPE_TAG, LdapStatesEnum.SEARCH_REQUEST_SCOPE_VALUE, + null); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // ... + // scope ENUMERATED { + // baseObject (0), + // singleLevel (1), + // wholeSubtree (2) }, (Value) + // ... + // We have a value for the scope, we will store it in the message + super.transitions[LdapStatesEnum.SEARCH_REQUEST_SCOPE_VALUE][UniversalTag.ENUMERATED_TAG] = + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_SCOPE_VALUE, + LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_TAG, + new GrammarAction( "store scope value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + + SearchRequest searchRequest = + ldapMessageContainer.getLdapMessage().getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // We have to check that this is a correct scope + Value value = tlv.getValue(); + + int scope = IntegerDecoder.parse( value, LdapConstants.SCOPE_BASE_OBJECT, LdapConstants.SCOPE_WHOLE_SUBTREE ); + + searchRequest.setScope(scope); + + return; + } + } ); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // ... + // derefAliases ENUMERATED { + // neverDerefAliases (0), + // derefInSearching (1), + // derefFindingBaseObj (2), + // derefAlways (3) }, (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_TAG][UniversalTag.ENUMERATED_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_TAG, LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_VALUE, + null); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // ... + // derefAliases ENUMERATED { + // neverDerefAliases (0), + // derefInSearching (1), + // derefFindingBaseObj (2), + // derefAlways (3) }, (Value) + // ... + // We have a value for the derefAliases, we will store it in the message + super.transitions[LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_VALUE][UniversalTag.ENUMERATED_TAG] = + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_DEREF_ALIASES_VALUE, + LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_TAG, + new GrammarAction( "store derefAliases value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + + SearchRequest searchRequest = + ldapMessageContainer.getLdapMessage().getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // We have to check that this is a correct derefAliases + Value value = tlv.getValue(); + + int derefAliases = IntegerDecoder.parse( value, LdapConstants.NEVER_DEREF_ALIASES, LdapConstants.DEREF_ALWAYS ); + + searchRequest.setDerefAliases( derefAliases ); + + return; + } + } ); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // ... + // sizeLimit INTEGER (0 .. maxInt), (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_TAG][UniversalTag.INTEGER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_TAG, LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_VALUE, + null); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // ... + // sizeLimit INTEGER (0 .. maxInt), (Value) + // ... + // We have a value for the sizeLimit, we will store it in the message + super.transitions[LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_VALUE][UniversalTag.INTEGER_TAG] = + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_SIZE_LIMIT_VALUE, + LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_TAG, + new GrammarAction( "store sizeLimit value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + + SearchRequest searchRequest = + ldapMessageContainer.getLdapMessage().getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // The current TLV should be a integer + // We get it and store it in sizeLimit + Value value = tlv.getValue(); + + int sizeLimit = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE ); + + searchRequest.setSizeLimit( sizeLimit ); + + return; + } + } ); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // ... + // timeLimit INTEGER (0 .. maxInt), (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_TAG][UniversalTag.INTEGER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_TAG, LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_VALUE, + null); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // ... + // timeLimit INTEGER (0 .. maxInt), (Value) + // ... + // We have a value for the timeLimit, we will store it in the message + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_VALUE][UniversalTag.INTEGER_TAG] = + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_TIME_LIMIT_VALUE, + LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_TAG, + new GrammarAction( "store timeLimit value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + + SearchRequest searchRequest = + ldapMessageContainer.getLdapMessage().getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // The current TLV should be a integer + // We get it and store it in timeLimit + Value value = tlv.getValue(); + + int timeLimit = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE ); + + searchRequest.setTimeLimit( timeLimit ); + + return; + } + } ); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // ... + // typesOnly BOOLEAN, (Tag) + // ... + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_TAG][UniversalTag.BOOLEAN_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_TAG, LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_VALUE, + null); + + // SearchRequest ::= [APPLICATION 3] SEQUENCE { + // ... + // typesOnly BOOLEAN, (Value) + // ... + // We have a value for the typesOnly, we will store it in the message. + // The next transition will deal with the Filter. As a filter could contains + // sub-filter, we will initialize the filter Object right here. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_VALUE][UniversalTag.BOOLEAN_TAG] = + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_TYPES_ONLY_VALUE, + LdapStatesEnum.SEARCH_REQUEST_FILTER, + new GrammarAction( "store typesOnly value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + + SearchRequest searchRequest = + ldapMessageContainer.getLdapMessage().getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // We get the value. If it's a 0, it's a FALSE. If it's + // a FF, it's a TRUE. Any other value should be an error, + // but we could relax this constraint. So if we have something + // which is not 0, it will be interpreted as TRUE, but we + // will generate a warning. + Value value = tlv.getValue(); + + int typesOnly = IntegerDecoder.parse( value, 0, 255 ); + + searchRequest.setTypesOnly( typesOnly != 0 ); + + if ( ( typesOnly != 0 ) && (typesOnly != 255 ) ) + { + log.warn("A boolean must be encoded with a 0x00 or a 0xFF value"); + } + + return; + } + } ); + + //******************************************************************************************** + // Here we are dealing with the Search Request filter. + // If the Tag is 0xA0, then it's an and Filter + // If the Tag is 0xA1, then it's an or Filter + // If the Tag is 0xA2, then it's a not Filter + // If the Tag is 0xA3, then it's an equalityMatch Filter + // If the Tag is 0xA4, then it's a substrings Filter + // If the Tag is 0xA5, then it's a greaterOrEqual Filter + // If the Tag is 0xA6, then it's a lessOrEqual Filter + // If the Tag is 0x87, then it's a present Filter + // If the Tag is 0xA8, then it's an approxMatch Filter + // If the Tag is 0xA9, then it's an extensibleMatch Filter + //******************************************************************************************** + + //-------------------------------------------------------------------------------------------- + // And Filter Message. + //-------------------------------------------------------------------------------------------- + // Filter ::= CHOICE { + // and [0] SET OF Filter, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][LdapConstants.AND_FILTER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTER_GRAMMAR_SWITCH, + null ); + + //-------------------------------------------------------------------------------------------- + // Or Filter Message. + //-------------------------------------------------------------------------------------------- + // Filter ::= CHOICE { + // ... + // or [0] SET OF Filter, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][LdapConstants.OR_FILTER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTER_GRAMMAR_SWITCH, + null ); + + //-------------------------------------------------------------------------------------------- + // Not Filter Message. + //-------------------------------------------------------------------------------------------- + // Filter ::= CHOICE { + // ... + // not [2] Filter, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][LdapConstants.NOT_FILTER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTER_GRAMMAR_SWITCH, + null ); + + //-------------------------------------------------------------------------------------------- + // EqualityMatch Filter Message. + //-------------------------------------------------------------------------------------------- + // Filter ::= CHOICE { + // ... + // equalityMatch [3] AttributeValueAssertion, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][LdapConstants.EQUALITY_MATCH_FILTER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTER_GRAMMAR_SWITCH, + null ); + + //-------------------------------------------------------------------------------------------- + // Substrings Filter Message. + //-------------------------------------------------------------------------------------------- + // Filter ::= CHOICE { + // ... + // substrings [4] SubstringFilter, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][LdapConstants.SUBSTRINGS_FILTER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTER_GRAMMAR_SWITCH, + null ); + + //-------------------------------------------------------------------------------------------- + // GreaterOrEqual Filter Message. + //-------------------------------------------------------------------------------------------- + // Filter ::= CHOICE { + // ... + // greaterOrEqual [5] AttributeValueAssertion, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][LdapConstants.GREATER_OR_EQUAL_FILTER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTER_GRAMMAR_SWITCH, + null ); + + //-------------------------------------------------------------------------------------------- + // LessOrEqual Filter Message. + //-------------------------------------------------------------------------------------------- + // Filter ::= CHOICE { + // ... + // lessOrEqual [6] AttributeValueAssertion, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][LdapConstants.LESS_OR_EQUAL_FILTER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTER_GRAMMAR_SWITCH, + null ); + + //-------------------------------------------------------------------------------------------- + // Present Filter Message. + //-------------------------------------------------------------------------------------------- + // Filter ::= CHOICE { + // ... + // present [7] AttributeDescription, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][LdapConstants.PRESENT_FILTER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTER_GRAMMAR_SWITCH, + null ); + + //-------------------------------------------------------------------------------------------- + // ApproxMatch Filter Message. + //-------------------------------------------------------------------------------------------- + // Filter ::= CHOICE { + // ... + // approxMatch [8] AttributeValueAssertion, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][LdapConstants.APPROX_MATCH_FILTER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTER_GRAMMAR_SWITCH, + null ); + + //-------------------------------------------------------------------------------------------- + // ExtensibleMatch Filter Message. + //-------------------------------------------------------------------------------------------- + // Filter ::= CHOICE { + // ... + // extensibleMatch [9] MatchingRuleAssertion, + // ... + // We have to switch to the Filter grammar + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][LdapConstants.EXTENSIBLE_MATCH_FILTER_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.FILTER_GRAMMAR_SWITCH, + null ); + + + // ... + // attributes AttributeDescriptionList } + // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription (Tag) + // ... + // We have to check that the filter has been created. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_FILTER][UniversalTag.SEQUENCE_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_FILTER, LdapStatesEnum.SEARCH_REQUEST_ATTRIBUTE_DESCRIPTION_LIST_VALUE, + null); + + // ... + // attributes AttributeDescriptionList } + // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription (Length) + // ... + // We have to create an array of elements to store the list of attributes + // to retrieve. We don't know yet how many attributes we will read so we + // will allocate an ArrayList. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_ATTRIBUTE_DESCRIPTION_LIST_VALUE][UniversalTag.SEQUENCE_TAG] = + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_ATTRIBUTE_DESCRIPTION_LIST_VALUE, + LdapStatesEnum.SEARCH_REQUEST_ATTRIBUTE_DESCRIPTION_TAG, + new GrammarAction( "store Attribute Description List value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + + SearchRequest searchRequest = + ldapMessageContainer.getLdapMessage().getSearchRequest(); + + searchRequest.initAttributes(); + + return; + } + } ); + + // AttributeDescription ::= LDAPString + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_ATTRIBUTE_DESCRIPTION_TAG][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_REQUEST_ATTRIBUTE_DESCRIPTION_TAG, LdapStatesEnum.SEARCH_REQUEST_ATTRIBUTE_DESCRIPTION_VALUE, + null); + + // ... + // attributes AttributeDescriptionList } + // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription (Length) + // ... + // We have to create an array of elements to store the list of attributes + // to retrieve. We don't know yet how many attributes we will read. + super.transitions[LdapStatesEnum.SEARCH_REQUEST_ATTRIBUTE_DESCRIPTION_VALUE][UniversalTag.OCTET_STRING_TAG] = + new GrammarTransition( LdapStatesEnum.SEARCH_REQUEST_ATTRIBUTE_DESCRIPTION_VALUE, + LdapStatesEnum.SEARCH_REQUEST_ATTRIBUTE_DESCRIPTION_TAG, + new GrammarAction( "store Attribute Description value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + + SearchRequest searchRequest = + ldapMessageContainer.getLdapMessage().getSearchRequest(); + + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + searchRequest.addAttribute( new LdapString(tlv.getValue().getData())); + + return; + } + } ); + + } + + //~ Methods ------------------------------------------------------------------------------------ + + /** + * Get the instance of this grammar + * + * @return An instance on the LdapMessage Grammar + */ + public static IGrammar getInstance() + { + return instance; + } +} Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchResultDoneGrammar.java URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchResultDoneGrammar.java?rev=234264&view=auto ============================================================================== --- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchResultDoneGrammar.java (added) +++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchResultDoneGrammar.java Sun Aug 21 09:53:27 2005 @@ -0,0 +1,114 @@ +/* + * Copyright 2005 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.asn1new.ldap.codec.grammar; + +import org.apache.asn1new.DecoderException; +import org.apache.asn1new.ber.containers.IAsn1Container; +import org.apache.asn1new.ber.grammar.AbstractGrammar; +import org.apache.asn1new.ber.grammar.GrammarAction; +import org.apache.asn1new.ber.grammar.GrammarTransition; +import org.apache.asn1new.ber.grammar.IGrammar; +import org.apache.asn1new.ber.tlv.UniversalTag; +import org.apache.asn1new.ldap.codec.LdapConstants; +import org.apache.asn1new.ldap.codec.LdapMessageContainer; +import org.apache.asn1new.ldap.pojo.LdapMessage; +import org.apache.asn1new.ldap.pojo.SearchResultDone; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This class implements the SearchResultDone LDAP message. All the actions are declared in this + * class. As it is a singleton, these declaration are only done once. + * + * @author Apache Directory Project + */ +public class SearchResultDoneGrammar extends AbstractGrammar implements IGrammar +{ + //~ Static fields/initializers ----------------------------------------------------------------- + + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( SearchResultDoneGrammar.class ); + + /** Logging speed up */ + private static final boolean DEBUG = log.isDebugEnabled(); + + /** The instance of grammar. SearchResultDoneGrammar is a singleton */ + private static IGrammar instance = new SearchResultDoneGrammar(); + + //~ Constructors ------------------------------------------------------------------------------- + + /** + * Creates a new SearchResultDoneGrammar object. + */ + private SearchResultDoneGrammar() + { + name = SearchResultDoneGrammar.class.getName(); + statesEnum = LdapStatesEnum.getInstance(); + + // Intitialisation + super.transitions = new GrammarTransition[LdapStatesEnum.LAST_SEARCH_RESULT_DONE_STATE][256]; + + //============================================================================================ + // DelResponse Message + //============================================================================================ + // LdapMessage ::= ... SearchResultDone ... + // SearchResultDone ::= [APPLICATION 5] LDAPResult (Tag) + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_RESULT_DONE_TAG][LdapConstants.SEARCH_RESULT_DONE_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_RESULT_DONE_TAG, LdapStatesEnum.SEARCH_RESULT_DONE_VALUE, null ); + + // LdapMessage ::= ... SearchResultDone ... + // SearchResultDone ::= [APPLICATION 5] LDAPResult (Value) + // The next Tag will be the LDAPResult Tag (0x0A). + // We will switch the grammar then. + super.transitions[LdapStatesEnum.SEARCH_RESULT_DONE_VALUE][LdapConstants.SEARCH_RESULT_DONE_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_RESULT_DONE_VALUE, LdapStatesEnum.SEARCH_RESULT_DONE_LDAP_RESULT, + new GrammarAction( "Init search Result Done" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // Now, we can allocate the SearchResultDone Object + ldapMessage.setProtocolOP( new SearchResultDone() ); + } + } ); + + // LdapMessage ::= ... SearchResultDone ... + // SearchResultDone ::= [APPLICATION 5] LDAPResult (Value) + // Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar. + super.transitions[LdapStatesEnum.SEARCH_RESULT_DONE_LDAP_RESULT][UniversalTag.ENUMERATED_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_RESULT_DONE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH, null ); + } + + //~ Methods ------------------------------------------------------------------------------------ + + /** + * Get the instance of this grammar + * + * @return An instance on the LdapMessage Grammar + */ + public static IGrammar getInstance() + { + return instance; + } +} Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchResultEntryGrammar.java URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchResultEntryGrammar.java?rev=234264&view=auto ============================================================================== --- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchResultEntryGrammar.java (added) +++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/grammar/SearchResultEntryGrammar.java Sun Aug 21 09:53:27 2005 @@ -0,0 +1,349 @@ +/* + * Copyright 2005 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.asn1new.ldap.codec.grammar; + +import org.apache.asn1new.DecoderException; +import org.apache.asn1new.ber.containers.IAsn1Container; +import org.apache.asn1new.ber.grammar.AbstractGrammar; +import org.apache.asn1new.ber.grammar.GrammarAction; +import org.apache.asn1new.ber.grammar.GrammarTransition; +import org.apache.asn1new.ber.grammar.IGrammar; +import org.apache.asn1new.ber.tlv.TLV; +import org.apache.asn1new.ber.tlv.UniversalTag; +import org.apache.asn1new.primitives.OctetString; +import org.apache.asn1new.ldap.codec.LdapConstants; +import org.apache.asn1new.ldap.codec.LdapMessageContainer; +import org.apache.asn1new.ldap.codec.primitives.LdapDN; +import org.apache.asn1new.ldap.codec.primitives.LdapString; +import org.apache.asn1new.ldap.pojo.LdapMessage; +import org.apache.asn1new.ldap.pojo.SearchResultEntry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * This class implements the SearchResultEntry LDAP message. All the actions are declared in this + * class. As it is a singleton, these declaration are only done once. + * + * We have to deal with empty elements, as stated by rfc 2251 : + * + * -- implementors should note that the PartialAttributeList may + * -- have zero elements (if none of the attributes of that entry + * -- were requested, or could be returned), and that the vals set + * -- may also have zero elements (if types only was requested, or + * -- all values were excluded from the result.) + * + * @author Apache Directory Project + */ +public class SearchResultEntryGrammar extends AbstractGrammar implements IGrammar +{ + //~ Static fields/initializers ----------------------------------------------------------------- + + /** The logger */ + private static final Logger log = LoggerFactory.getLogger( SearchResultEntryGrammar.class ); + + /** Logging speed up */ + private static final boolean DEBUG = log.isDebugEnabled(); + + /** The instance of grammar. SearchResultEntryGrammar is a singleton */ + private static IGrammar instance = new SearchResultEntryGrammar(); + + //~ Constructors ------------------------------------------------------------------------------- + + /** + * Creates a new SearchResultEntryGrammar object. + */ + private SearchResultEntryGrammar() + { + name = SearchResultEntryGrammar.class.getName(); + statesEnum = LdapStatesEnum.getInstance(); + + // Intitialisation + super.transitions = new GrammarTransition[LdapStatesEnum.LAST_SEARCH_RESULT_ENTRY_STATE][256]; + + //============================================================================================ + // SearchResultEntry Message + //============================================================================================ + // LdapMessage ::= ... SearchResultEntry ... + // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { (Tag) + // Nothing to do. + super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_TAG][LdapConstants.SEARCH_RESULT_ENTRY_TAG] = new GrammarTransition( + 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][LdapConstants.SEARCH_RESULT_ENTRY_TAG] = new GrammarTransition( + LdapStatesEnum.SEARCH_RESULT_ENTRY_VALUE, + LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG, + new GrammarAction( "Init SearchResultEntry" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + 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 { + // objectName LDAPDN, (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG][UniversalTag.OCTET_STRING_TAG] = + new GrammarTransition( + LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_TAG, + LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE, null ); + + // LdapMessage ::= ... SearchResultEntry ... + // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { + // objectName LDAPDN, (Value) + // ... + // Store the object name. + super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_OBJECT_NAME_VALUE][UniversalTag.OCTET_STRING_TAG] = + 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(); + + TLV tlv = + ldapMessageContainer.getCurrentTLV(); + + // Store the value. + if ( tlv.getLength().getLength() == 0 ) + { + searchResultEntry.setObjectName( LdapDN.EMPTY_STRING ); + } + else + { + searchResultEntry.setObjectName( new LdapDN( + tlv.getValue().getData() ) ); + } + } + } ); + + // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { + // attributes PartialAttributeList } + // PartialAttributeList ::= *SEQUENCE* OF SEQUENCE { (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_TAG][UniversalTag.SEQUENCE_TAG] = + 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) + // ... + // We may have many attributes. Nothing to do + super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTES_VALUE][UniversalTag.SEQUENCE_TAG] = + 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][UniversalTag.SEQUENCE_TAG] = + new GrammarTransition( + LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_TAG, + LdapStatesEnum.SEARCH_RESULT_ENTRY_PARTIAL_ATTRIBUTE_LIST_VALUE, null ); + + // SearchResultEntry ::= [APPLICATION 4] SEQUENCE { + // attributes PartialAttributeList } + // PartialAttributeList ::= SEQUENCE OF *SEQUENCE* { (Tag) + // ... + // Loop. + super.transitions[LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_LIST_TAG][UniversalTag.SEQUENCE_TAG] = + new GrammarTransition( + LdapStatesEnum.SEARCH_RESULT_ENTRY_ATTRIBUTE_VALUE_OR_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][UniversalTag.SEQUENCE_TAG] = + 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][UniversalTag.OCTET_STRING_TAG] = + 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][UniversalTag.OCTET_STRING_TAG] = + 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][UniversalTag.SET_TAG] = + 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][UniversalTag.SET_TAG] = + 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][UniversalTag.OCTET_STRING_TAG] = + 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][UniversalTag.OCTET_STRING_TAG] = + 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][UniversalTag.OCTET_STRING_TAG] = + 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() ) ); + } + } + } ); + + + } + + //~ Methods ------------------------------------------------------------------------------------ + + /** + * Get the instance of this grammar + * + * @return An instance on the SearchResultEntry Grammar + */ + public static IGrammar getInstance() + { + return instance; + } +}