directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r208936 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java
Date Sun, 03 Jul 2005 16:06:10 GMT
Author: elecharny
Date: Sun Jul  3 09:06:09 2005
New Revision: 208936

URL: http://svn.apache.org/viewcvs?rev=208936&view=rev
Log:
Added the DelRequest grammar

Added:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java?rev=208936&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/DelRequestGrammar.java
Sun Jul  3 09:06:09 2005
@@ -0,0 +1,125 @@
+/*
+ *   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.pojo.DelRequest;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the DelRequest 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 <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DelRequestGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( DelRequestGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. DelRequestGrammar is a singleton */
+    private static IGrammar instance = new DelRequestGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new DelRequestGrammar object.
+     */
+    private DelRequestGrammar()
+    {
+        name              = DelRequestGrammar.class.getName();
+        statesEnum        = LdapStatesEnum.getInstance();
+
+        super.transitions = new GrammarTransition[LdapStatesEnum.LAST_DEL_REQUEST_STATE][256];
+
+        //============================================================================================
+        // DelRequest
+        //============================================================================================
+        // DelRequestGrammar ::= [APPLICATION 10] LDAPDN { (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.DEL_REQUEST_TAG][0x4A] = new GrammarTransition(
+                LdapStatesEnum.DEL_REQUEST_TAG,
+                LdapStatesEnum.DEL_REQUEST_VALUE, null );
+
+        // DelRequestGrammar ::= [APPLICATION 10] LDAPDN { (Value)
+        // Initialise the del request pojo and store the DN to be deleted
+        super.transitions[LdapStatesEnum.DEL_REQUEST_VALUE][0x4A] = new GrammarTransition(
+                LdapStatesEnum.DEL_REQUEST_VALUE, LdapStatesEnum.END_STATE,
+                new GrammarAction( "Init del Request" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // We can allocate the ModifyDNRequest Object
+                        DelRequest delRequest = new DelRequest();
+
+                        // And store the DN into it
+                        // Get the Value and store it in the DelRequest
+                        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
+                        {
+                            delRequest.setEntry( new LdapDN( tlv.getValue().getData() ) );
+                        }
+
+                        // then we associate it to the ldapMessage Object
+                        ldapMessage.setProtocolOP( delRequest );
+                    }
+                } );
+
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * This class is a singleton.
+     *
+     * @return An instance on this grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}



Mime
View raw message