directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
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 GMT
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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+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;
+    }
+}



Mime
View raw message