Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 75400 invoked from network); 3 Jul 2005 17:17:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Jul 2005 17:17:12 -0000 Received: (qmail 86407 invoked by uid 500); 3 Jul 2005 17:16:21 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 86201 invoked by uid 500); 3 Jul 2005 17:16:19 -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 86168 invoked by uid 99); 3 Jul 2005 17:16:19 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 Jul 2005 10:16:19 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME 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, 03 Jul 2005 10:16:20 -0700 Received: (qmail 71788 invoked by uid 65534); 3 Jul 2005 17:16:16 -0000 Message-ID: <20050703171616.71773.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r208956 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java Date: Sun, 03 Jul 2005 17:16:16 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.2 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Sun Jul 3 10:16:14 2005 New Revision: 208956 URL: http://svn.apache.org/viewcvs?rev=208956&view=rev Log: Added the CompareRequest grammar Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java?rev=208956&view=auto ============================================================================== --- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java (added) +++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java Sun Jul 3 10:16:14 2005 @@ -0,0 +1,254 @@ +/* + * 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.asn1.ldap.codec.grammars; + +import org.apache.asn1.DecoderException; +import org.apache.asn1.ber.containers.IAsn1Container; +import org.apache.asn1.ber.grammar.AbstractGrammar; +import org.apache.asn1.ber.grammar.GrammarAction; +import org.apache.asn1.ber.grammar.GrammarTransition; +import org.apache.asn1.ber.grammar.IGrammar; +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.CompareRequest; +import org.apache.asn1.ldap.pojo.LdapMessage; +import org.apache.asn1.primitives.OctetString; + +import org.apache.log4j.Logger; + + +/** + * This class implements the CompareRequest 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 CompareRequestGrammar extends AbstractGrammar implements IGrammar +{ + //~ Static fields/initializers ----------------------------------------------------------------- + + /** The logger */ + private static final Logger log = Logger.getLogger( CompareRequestGrammar.class ); + + /** Logging speed up */ + private static final boolean DEBUG = log.isDebugEnabled(); + + /** The instance of grammar. CompareRequest is a singleton */ + private static IGrammar instance = new CompareRequestGrammar(); + + //~ Constructors ------------------------------------------------------------------------------- + + /** + * Creates a new CompareRequest object. + */ + private CompareRequestGrammar() + { + name = CompareRequestGrammar.class.getName(); + statesEnum = LdapStatesEnum.getInstance(); + + super.transitions = new GrammarTransition[LdapStatesEnum.LAST_COMPARE_REQUEST_STATE][256]; + + //============================================================================================ + // CompareRequest + //============================================================================================ + // CompareRequest ::= [APPLICATION 14] SEQUENCE { (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.COMPARE_REQUEST_TAG][0x6E] = new GrammarTransition( + LdapStatesEnum.COMPARE_REQUEST_TAG, + LdapStatesEnum.COMPARE_REQUEST_VALUE, null ); + + // CompareRequest ::= [APPLICATION 14] SEQUENCE { (Value) + // Initialize the compare request pojo + super.transitions[LdapStatesEnum.COMPARE_REQUEST_VALUE][0x6E] = new GrammarTransition( + LdapStatesEnum.COMPARE_REQUEST_VALUE, LdapStatesEnum.COMPARE_REQUEST_ENTRY_TAG, + new GrammarAction( "Init Compare Request" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // We can allocate the CompareRequest Object + ldapMessage.setProtocolOP( new CompareRequest() ); + } + } ); + + // CompareRequest ::= [APPLICATION 14] SEQUENCE { + // entry LDAPDN, (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.COMPARE_REQUEST_ENTRY_TAG][0x04] = new GrammarTransition( + LdapStatesEnum.COMPARE_REQUEST_ENTRY_TAG, + LdapStatesEnum.COMPARE_REQUEST_ENTRY_VALUE, null ); + + // CompareRequest ::= [APPLICATION 14] SEQUENCE { + // entry LDAPDN, (Tag) + // ... + // Store the DN to be compared + super.transitions[LdapStatesEnum.COMPARE_REQUEST_ENTRY_VALUE][0x04] = new GrammarTransition( + LdapStatesEnum.COMPARE_REQUEST_ENTRY_VALUE, LdapStatesEnum.COMPARE_REQUEST_AVA_TAG, + new GrammarAction( "Store entry" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // We can allocate the CompareRequest Object + CompareRequest compareRequest = ldapMessage.getCompareRequest(); + + // Get the Value and store it in the CompareRequest + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // We have to handle the special case of a 0 length matched DN + if ( tlv.getLength().getLength() == 0 ) + { + throw new DecoderException( "The entry must not be null" ); + } + else + { + compareRequest.setEntry( new LdapDN( tlv.getValue().getData() ) ); + } + } + } ); + + // CompareRequest ::= [APPLICATION 14] SEQUENCE { + // ... + // ava AttributeValueAssertion } + // AttributeValueAssertion ::= SEQUENCE { (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.COMPARE_REQUEST_AVA_TAG][0x30] = new GrammarTransition( + LdapStatesEnum.COMPARE_REQUEST_AVA_TAG, + LdapStatesEnum.COMPARE_REQUEST_AVA_VALUE, null ); + + // CompareRequest ::= [APPLICATION 14] SEQUENCE { + // ... + // ava AttributeValueAssertion } + // AttributeValueAssertion ::= SEQUENCE { (Value) + // Nothing to do + super.transitions[LdapStatesEnum.COMPARE_REQUEST_AVA_VALUE][0x30] = new GrammarTransition( + LdapStatesEnum.COMPARE_REQUEST_AVA_VALUE, LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_TAG, null); + + // AttributeValueAssertion ::= SEQUENCE { + // attributeDesc AttributeDescription, (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_TAG][0x04] = new GrammarTransition( + LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_TAG, + LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_VALUE, null ); + + // AttributeValueAssertion ::= SEQUENCE { + // attributeDesc AttributeDescription, (Value) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_VALUE][0x04] = new GrammarTransition( + LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_VALUE, + LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_TAG, + new GrammarAction( "Store attribute desc" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // Get the CompareRequest Object + CompareRequest compareRequest = ldapMessage.getCompareRequest(); + + // Get the Value and store it in the CompareRequest + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // We have to handle the special case of a 0 length matched DN + if ( tlv.getLength().getLength() == 0 ) + { + throw new DecoderException( "The attribute description must not be null" ); + } + else + { + compareRequest.setAttributeDesc( new LdapString( tlv.getValue().getData() ) ); + } + } + } ); + + // AttributeValueAssertion ::= SEQUENCE { + // ... + // assertionValue AssertionValue } (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_TAG][0x04] = new GrammarTransition( + LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_TAG, + LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_VALUE, null ); + + // AttributeValueAssertion ::= SEQUENCE { + // ... + // assertionValue AssertionValue } (Value) + // Nothing to do + super.transitions[LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_VALUE][0x04] = new GrammarTransition( + LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_VALUE, + LdapStatesEnum.END_STATE, + new GrammarAction( "Store assertion value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + + // Get the CompareRequest Object + CompareRequest compareRequest = ldapMessage.getCompareRequest(); + + // Get the Value and store it in the CompareRequest + TLV tlv = ldapMessageContainer.getCurrentTLV(); + + // We have to handle the special case of a 0 length matched DN + if ( tlv.getLength().getLength() == 0 ) + { + compareRequest.setAssertionValue( OctetString.EMPTY_STRING ); + } + else + { + compareRequest.setAssertionValue( new OctetString( tlv.getValue().getData() ) ); + } + } + } ); + } + + //~ Methods ------------------------------------------------------------------------------------ + + /** + * This class is a singleton. + * + * @return An instance on this grammar + */ + public static IGrammar getInstance() + { + return instance; + } +}