directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r208981 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedRequestGrammar.java
Date Sun, 03 Jul 2005 21:41:17 GMT
Author: elecharny
Date: Sun Jul  3 14:41:16 2005
New Revision: 208981

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

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

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedRequestGrammar.java?rev=208981&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedRequestGrammar.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ExtendedRequestGrammar.java
Sun Jul  3 14:41:16 2005
@@ -0,0 +1,193 @@
+/*
+ *   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.pojo.ExtendedRequest;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.primitives.OID;
+import org.apache.asn1.primitives.OctetString;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the ExtendedRequest 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 ExtendedRequestGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( ExtendedRequestGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. ExtendedRequest is a singleton */
+    private static IGrammar instance = new ExtendedRequestGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new ExtendedRequest object.
+     */
+    private ExtendedRequestGrammar()
+    {
+        name              = ExtendedRequestGrammar.class.getName();
+        statesEnum        = LdapStatesEnum.getInstance();
+
+        super.transitions = new GrammarTransition[LdapStatesEnum.LAST_EXTENDED_REQUEST_STATE][256];
+
+        //============================================================================================
+        // ExtendedRequest
+        //============================================================================================
+        // ExtendedRequest ::= [APPLICATION 23] SEQUENCE { (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.EXTENDED_REQUEST_TAG][0x77] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_REQUEST_TAG,
+                LdapStatesEnum.EXTENDED_REQUEST_VALUE, null );
+
+        // ExtendedRequest ::= [APPLICATION 23] SEQUENCE { (Value)
+        // Initialize the compare request pojo
+        super.transitions[LdapStatesEnum.EXTENDED_REQUEST_VALUE][0x77] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_REQUEST_VALUE, LdapStatesEnum.EXTENDED_REQUEST_NAME_TAG,
+                new GrammarAction( "Init Extended Request" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // We can allocate the ExtendedRequest Object
+                        ldapMessage.setProtocolOP( new ExtendedRequest() );
+                    }
+                } );
+
+        // ExtendedRequest ::= [APPLICATION 23] SEQUENCE { 
+        //     requestName      [0] LDAPOID, (Tag)
+        //     ...
+        // Nothing to do
+        super.transitions[LdapStatesEnum.EXTENDED_REQUEST_NAME_TAG][0x80] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_REQUEST_NAME_TAG,
+                LdapStatesEnum.EXTENDED_REQUEST_NAME_VALUE, null );
+
+        // ExtendedRequest ::= [APPLICATION 23] SEQUENCE { 
+        //     requestName      [0] LDAPOID, (Value)
+        //     ...
+        // Store the DN to be compared
+        super.transitions[LdapStatesEnum.EXTENDED_REQUEST_NAME_VALUE][0x80] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_REQUEST_NAME_VALUE, LdapStatesEnum.EXTENDED_REQUEST_VALUE_TAG,
+                new GrammarAction( "Store name" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // We can allocate the ExtendedRequest Object
+                        ExtendedRequest extendedRequest = ldapMessage.getExtendedRequest();
+
+                        // Get the Value and store it in the ExtendedRequest
+                        TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+                        // We have to handle the special case of a 0 length matched OID
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            throw new DecoderException( "The name must not be null" );
+                        }
+                        else
+                        {
+                            extendedRequest.setName( new OID( tlv.getValue().getData() )
);
+                        }
+                    }
+                } );
+
+        // ExtendedRequest ::= [APPLICATION 23] SEQUENCE { 
+        //     ...
+        //     requestValue     [1] OCTET STRING OPTIONAL } (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.EXTENDED_REQUEST_VALUE_TAG][0x81] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_REQUEST_VALUE_TAG,
+                LdapStatesEnum.EXTENDED_REQUEST_VALUE_VALUE, null );
+
+        // ExtendedRequest ::= [APPLICATION 23] SEQUENCE { 
+        //     ...
+        //     requestValue     [1] OCTET STRING OPTIONAL } (Value)
+        // Store the DN to be compared
+        super.transitions[LdapStatesEnum.EXTENDED_REQUEST_VALUE_VALUE][0x81] = new GrammarTransition(
+                LdapStatesEnum.EXTENDED_REQUEST_VALUE_VALUE, LdapStatesEnum.END_STATE,
+                new GrammarAction( "Store value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // We can allocate the ExtendedRequest Object
+                        ExtendedRequest extendedRequest = ldapMessage.getExtendedRequest();
+
+                        // Get the Value and store it in the ExtendedRequest
+                        TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+                        // We have to handle the special case of a 0 length matched OID
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            extendedRequest.setValue( OctetString.EMPTY_STRING );
+                        }
+                        else
+                        {
+                            extendedRequest.setValue( new OctetString( tlv.getValue().getData()
) );
+                        }
+                    }
+                } );
+
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * This class is a singleton.
+     *
+     * @return An instance on this grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}



Mime
View raw message