Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 93195 invoked from network); 3 Jul 2005 12:31:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Jul 2005 12:31:27 -0000 Received: (qmail 64221 invoked by uid 500); 3 Jul 2005 12:31:26 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 64188 invoked by uid 500); 3 Jul 2005 12:31:25 -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 64175 invoked by uid 99); 3 Jul 2005 12:31:25 -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 05:31:25 -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, 03 Jul 2005 05:31:26 -0700 Received: (qmail 93159 invoked by uid 65534); 3 Jul 2005 12:31:22 -0000 Message-ID: <20050703123122.93158.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r208909 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AddRequestGrammar.java Date: Sun, 03 Jul 2005 12:31:22 -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 05:31:21 2005 New Revision: 208909 URL: http://svn.apache.org/viewcvs?rev=208909&view=rev Log: Added the AddRequest grammar Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AddRequestGrammar.java Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AddRequestGrammar.java URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AddRequestGrammar.java?rev=208909&view=auto ============================================================================== --- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AddRequestGrammar.java (added) +++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/AddRequestGrammar.java Sun Jul 3 05:31:21 2005 @@ -0,0 +1,325 @@ +/* + * 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.AddRequest; +import org.apache.asn1.ldap.pojo.LdapMessage; +import org.apache.asn1.primitives.OctetString; + +import org.apache.log4j.Logger; + + +/** + * This class implements the AddRequest 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 AddRequestGrammar extends AbstractGrammar implements IGrammar +{ + //~ Static fields/initializers ----------------------------------------------------------------- + + /** The logger */ + private static final Logger log = Logger.getLogger( AddRequestGrammar.class ); + + /** Logging speed up */ + private static final boolean DEBUG = log.isDebugEnabled(); + + /** The instance of grammar. AddRequestGrammar is a singleton */ + private static IGrammar instance = new AddRequestGrammar(); + + //~ Constructors ------------------------------------------------------------------------------- + + /** + * Creates a new AddRequestGrammar object. + */ + private AddRequestGrammar() + { + name = AddRequestGrammar.class.getName(); + statesEnum = LdapStatesEnum.getInstance(); + + // Intitialisation + super.transitions = new GrammarTransition[LdapStatesEnum.LAST_ADD_REQUEST_STATE][256]; + + //============================================================================================ + // AddRequest Message + //============================================================================================ + // LdapMessage ::= ... AddRequest ... + // AddRequest ::= [APPLICATION 8] SEQUENCE { (Tag) + // Nothing to do. + super.transitions[LdapStatesEnum.ADD_REQUEST_TAG][0x68] = new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_TAG, LdapStatesEnum.ADD_REQUEST_VALUE, null ); + + // LdapMessage ::= ... AddRequest ... + // AddRequest ::= [APPLICATION 8] SEQUENCE { (Value) + // Create the structure + super.transitions[LdapStatesEnum.ADD_REQUEST_VALUE][0x68] = new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_VALUE, LdapStatesEnum.ADD_REQUEST_ENTRY_TAG, + new GrammarAction( "Init addRequest" ) + { + 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 AddRequest() ); + } + } ); + + // AddRequest ::= [APPLICATION 8] SEQUENCE { + // entry LDAPDN, (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.ADD_REQUEST_ENTRY_TAG][0x04] = new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ENTRY_TAG, LdapStatesEnum.ADD_REQUEST_ENTRY_VALUE, + null ); + + // AddRequest ::= [APPLICATION 8] SEQUENCE { + // entry LDAPDN, (Value) + // ... + // Store the object name. + super.transitions[LdapStatesEnum.ADD_REQUEST_ENTRY_VALUE][0x04] = new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ENTRY_VALUE, LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TAG, + new GrammarAction( "Store add request object Value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + AddRequest addRequest = ldapMessage.getAddRequest(); + + TLV tlv = + ldapMessageContainer.getCurrentTLV(); + + // Store the entry. It can't be null + if ( tlv.getLength().getLength() == 0 ) + { + throw new DecoderException( "The DN can't be null" ); + } + else + { + addRequest.setEntry( new LdapDN( + tlv.getValue().getData() ) ); + } + } + } ); + + // AddRequest ::= [APPLICATION 8] SEQUENCE { + // ... + // attributes AttributeList } + // AttributeList ::= *SEQUENCE* OF SEQUENCE { (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TAG][0x30] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TAG, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALUE, null ); + + // AddRequest ::= [APPLICATION 8] SEQUENCE { + // ... + // attributes AttributeList } + // AttributeList ::= *SEQUENCE* OF SEQUENCE { (Value) + // Allocate the attributes ArrayList + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALUE][0x30] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALUE, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_TAG, + new GrammarAction( "Init attributes array list" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + AddRequest addRequest = ldapMessage.getAddRequest(); + + addRequest.initAttributes(); + } + } ); + + // AttributeList ::= SEQUENCE OF *SEQUENCE* { (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_TAG][0x30] = new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_TAG, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_VALUE, null ); + + // AttributeList ::= SEQUENCE OF *SEQUENCE* { (Tag) + // ... + // Nothing to do + // This is a loop, when dealing with more than one attribute + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_OR_ATTRIBUTE_OR_END][0x30] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_OR_ATTRIBUTE_OR_END, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_VALUE, null ); + + // AttributeList ::= SEQUENCE OF *SEQUENCE* { (Value) + // Nothing to do + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_VALUE][0x30] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTE_VALUE, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_TAG, null ); + + // AttributeList ::= SEQUENCE OF *SEQUENCE* { + // type AttributeDescription, (Tag) + // ... + // Nothing to do + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_TAG][0x04] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_TAG, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_VALUE, null ); + + // AttributeList ::= SEQUENCE OF *SEQUENCE* { + // type AttributeDescription, (Value) + // ... + // Store the attribute type. + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_VALUE][0x04] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_TYPE_VALUE, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_TAG, + new GrammarAction( "Store attribute type" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + TLV tlv = + ldapMessageContainer.getCurrentTLV(); + + AddRequest addRequest = ldapMessage.getAddRequest(); + + // Store the type. It can't be null. + if ( tlv.getLength().getLength() == 0 ) + { + throw new DecoderException( "The type can't be null" ); + } + else + { + addRequest.addAttributeType( new LdapString( + tlv.getValue().getData() ) ); + } + } + } ); + + // AttributeTypeAndValues ::= SEQUENCE { + // ... + // vals *SET OF* AttributeValue } (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_TAG][0x31] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_TAG, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_VALUE, null ); + + // AttributeTypeAndValues ::= SEQUENCE { + // ... + // vals *SET OF* AttributeValue } (Value) + // Nothing to do + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_VALUE][0x31] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VALS_VALUE, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_TAG, null ); + + // AttributeTypeAndValues ::= SEQUENCE { + // ... + // vals SET OF *AttributeValue* } (Tag) + // Nothing to do + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_TAG][0x04] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_TAG, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_VALUE, null ); + + // AttributeTypeAndValues ::= SEQUENCE { + // ... + // vals SET OF *AttributeValue* } (Loop) + // This is a loop, when dealing with multi-valued attributes + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_OR_ATTRIBUTE_OR_END][0x04] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_OR_ATTRIBUTE_OR_END, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_VALUE, null ); + + // AttributeTypeAndValues ::= SEQUENCE { + // ... + // vals SET OF AttributeValue } + // AttributeValue ::= OCTET STRING (Value) + // Store a new attribute value. + super.transitions[LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_VALUE][0x04] = + new GrammarTransition( + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_VALUE, + LdapStatesEnum.ADD_REQUEST_ATTRIBUTES_VAL_OR_ATTRIBUTE_OR_END, + new GrammarAction( "Store attribute value" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + + LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer ) + container; + LdapMessage ldapMessage = + ldapMessageContainer.getLdapMessage(); + AddRequest addRequest = ldapMessage.getAddRequest(); + + TLV tlv = + ldapMessageContainer.getCurrentTLV(); + + // Store the value. It can't be null + if ( tlv.getLength().getLength() == 0 ) + { + addRequest.addAttributeValue( OctetString.EMPTY_STRING ); + } + else + { + addRequest.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; + } +}