directory-commits mailing list archives

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

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

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

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java?rev=208956&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareRequestGrammar.java
Sun Jul  3 10:16:14 2005
@@ -0,0 +1,254 @@
+/*
+ *   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.CompareRequest;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.primitives.OctetString;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the CompareRequest 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 CompareRequestGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( CompareRequestGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. CompareRequest is a singleton */
+    private static IGrammar instance = new CompareRequestGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new CompareRequest object.
+     */
+    private CompareRequestGrammar()
+    {
+        name              = CompareRequestGrammar.class.getName();
+        statesEnum        = LdapStatesEnum.getInstance();
+
+        super.transitions = new GrammarTransition[LdapStatesEnum.LAST_COMPARE_REQUEST_STATE][256];
+
+        //============================================================================================
+        // CompareRequest
+        //============================================================================================
+        // CompareRequest ::= [APPLICATION 14] SEQUENCE { (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_TAG][0x6E] = new GrammarTransition(
+                LdapStatesEnum.COMPARE_REQUEST_TAG,
+                LdapStatesEnum.COMPARE_REQUEST_VALUE, null );
+
+        // CompareRequest ::= [APPLICATION 14] SEQUENCE { (Value)
+        // Initialize the compare request pojo
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_VALUE][0x6E] = new GrammarTransition(
+                LdapStatesEnum.COMPARE_REQUEST_VALUE, LdapStatesEnum.COMPARE_REQUEST_ENTRY_TAG,
+                new GrammarAction( "Init Compare Request" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // We can allocate the CompareRequest Object
+                        ldapMessage.setProtocolOP( new CompareRequest() );
+                    }
+                } );
+
+        // CompareRequest ::= [APPLICATION 14] SEQUENCE { 
+        //     entry           LDAPDN, (Tag)
+        //     ...
+        // Nothing to do
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ENTRY_TAG][0x04] = new GrammarTransition(
+                LdapStatesEnum.COMPARE_REQUEST_ENTRY_TAG,
+                LdapStatesEnum.COMPARE_REQUEST_ENTRY_VALUE, null );
+
+        // CompareRequest ::= [APPLICATION 14] SEQUENCE { 
+        //     entry           LDAPDN, (Tag)
+        //     ...
+        // Store the DN to be compared
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ENTRY_VALUE][0x04] = new GrammarTransition(
+                LdapStatesEnum.COMPARE_REQUEST_ENTRY_VALUE, LdapStatesEnum.COMPARE_REQUEST_AVA_TAG,
+                new GrammarAction( "Store entry" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // We can allocate the CompareRequest Object
+                        CompareRequest compareRequest = ldapMessage.getCompareRequest();
+
+                        // Get the Value and store it in the CompareRequest
+                        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
+                        {
+                            compareRequest.setEntry( new LdapDN( tlv.getValue().getData()
) );
+                        }
+                    }
+                } );
+
+        // CompareRequest ::= [APPLICATION 14] SEQUENCE { 
+        //     ...
+        //     ava             AttributeValueAssertion }
+        // AttributeValueAssertion ::= SEQUENCE { (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_AVA_TAG][0x30] = new GrammarTransition(
+                LdapStatesEnum.COMPARE_REQUEST_AVA_TAG,
+                LdapStatesEnum.COMPARE_REQUEST_AVA_VALUE, null );
+
+        // CompareRequest ::= [APPLICATION 14] SEQUENCE { 
+        //     ...
+        //     ava             AttributeValueAssertion }
+        // AttributeValueAssertion ::= SEQUENCE { (Value)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_AVA_VALUE][0x30] = new GrammarTransition(
+                LdapStatesEnum.COMPARE_REQUEST_AVA_VALUE, LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_TAG,
null);
+
+        // AttributeValueAssertion ::= SEQUENCE {
+        //     attributeDesc   AttributeDescription, (Tag)
+        //     ...
+        // Nothing to do
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_TAG][0x04] = new
GrammarTransition(
+                LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_TAG,
+                LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_VALUE, null );
+
+        // AttributeValueAssertion ::= SEQUENCE {
+        //     attributeDesc   AttributeDescription, (Value)
+        //     ...
+        // Nothing to do
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_VALUE][0x04] = new
GrammarTransition(
+                LdapStatesEnum.COMPARE_REQUEST_ATTRIBUTE_DESC_VALUE,
+                LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_TAG, 
+                new GrammarAction( "Store attribute desc" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // Get the CompareRequest Object
+                        CompareRequest compareRequest = ldapMessage.getCompareRequest();
+
+                        // Get the Value and store it in the CompareRequest
+                        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 attribute description must not
be null" );
+                        }
+                        else
+                        {
+                            compareRequest.setAttributeDesc( new LdapString( tlv.getValue().getData()
) );
+                        }
+                    }
+                } );
+
+        // AttributeValueAssertion ::= SEQUENCE {
+        //     ...
+        //     assertionValue  AssertionValue } (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_TAG][0x04] = new
GrammarTransition(
+                LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_TAG,
+                LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_VALUE, null );
+
+        // AttributeValueAssertion ::= SEQUENCE {
+        //     ...
+        //     assertionValue  AssertionValue } (Value)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_VALUE][0x04] = new
GrammarTransition(
+                LdapStatesEnum.COMPARE_REQUEST_ASSERTION_VALUE_VALUE,
+                LdapStatesEnum.END_STATE, 
+                new GrammarAction( "Store assertion value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // Get the CompareRequest Object
+                        CompareRequest compareRequest = ldapMessage.getCompareRequest();
+
+                        // Get the Value and store it in the CompareRequest
+                        TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+                        // We have to handle the special case of a 0 length matched DN
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            compareRequest.setAssertionValue( OctetString.EMPTY_STRING );
+                        }
+                        else
+                        {
+                            compareRequest.setAssertionValue( 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