Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 19845 invoked from network); 26 Jun 2005 20:13:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 26 Jun 2005 20:13:15 -0000 Received: (qmail 90764 invoked by uid 500); 26 Jun 2005 20:13:14 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 90740 invoked by uid 500); 26 Jun 2005 20:13:14 -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 90725 invoked by uid 99); 26 Jun 2005 20:13:14 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Jun 2005 13:13:14 -0700 X-ASF-Spam-Status: No, hits=0.4 required=10.0 tests=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, 26 Jun 2005 13:13:13 -0700 Received: (qmail 19804 invoked by uid 65534); 26 Jun 2005 20:13:11 -0000 Message-ID: <20050626201311.19803.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r201899 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java Date: Sun, 26 Jun 2005 20:13:10 -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 Jun 26 13:13:10 2005 New Revision: 201899 URL: http://svn.apache.org/viewcvs?rev=201899&view=rev Log: Created the ModifyRequest grammar Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java?rev=201899&view=auto ============================================================================== --- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java (added) +++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyRequestGrammar.java Sun Jun 26 13:13:10 2005 @@ -0,0 +1,404 @@ +/* + * 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.codec.utils.IntegerDecoder; +import org.apache.asn1.ldap.pojo.LdapMessage; +import org.apache.asn1.ldap.pojo.ModifyRequest; +import org.apache.asn1.primitives.OctetString; + +import org.apache.log4j.Logger; + +import javax.naming.directory.DirContext; + + +/** + * 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 = Logger.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][0x66] = 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][0x66] = 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][0x04] = 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][0x04] = + 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][0x30] = + 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][0x30] = + 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][0x30] = + 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][0x30] = + 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][0x30] = + 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][0x0A] = + 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][0x0A] = + 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(), + DirContext.ADD_ATTRIBUTE, DirContext.REPLACE_ATTRIBUTE ); + + // 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][0x30] = + 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][0x30] = + 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][0x04] = 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][0x04] = 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][0x31] = 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][0x31] = 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][0x04] = + 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][0x04] = + 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][0x04] = + 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 SearchResultEntry Grammar + */ + public static IGrammar getInstance() + { + return instance; + } +}