directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r208924 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyDNRequestGrammar.java
Date Sun, 03 Jul 2005 14:59:38 GMT
Author: elecharny
Date: Sun Jul  3 07:59:38 2005
New Revision: 208924

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

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

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyDNRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyDNRequestGrammar.java?rev=208924&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyDNRequestGrammar.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyDNRequestGrammar.java
Sun Jul  3 07:59:38 2005
@@ -0,0 +1,319 @@
+/*
+ *   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.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.LdapMessageContainer;
+import org.apache.asn1.ldap.codec.primitives.LdapDN;
+import org.apache.asn1.ldap.codec.primitives.RelativeLdapDN;
+import org.apache.asn1.ldap.codec.utils.IntegerDecoder;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.ldap.pojo.ModifyDNRequest;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the ModifyDNRequest 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 ModifyDNRequestGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( ModifyDNRequestGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. ModifyDNRequestGrammar is a singleton */
+    private static IGrammar instance = new ModifyDNRequestGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new ModifyDNRequestGrammar object.
+     */
+    private ModifyDNRequestGrammar()
+    {
+        name              = ModifyDNRequestGrammar.class.getName();
+        statesEnum        = LdapStatesEnum.getInstance();
+
+        super.transitions = new GrammarTransition[LdapStatesEnum.LAST_MODIFY_DN_REQUEST_STATE][256];
+
+        //============================================================================================
+        // ModifyDNRequest
+        //============================================================================================
+        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE { (Tag)
+        // Nothing to do
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_TAG][0x6c] = new GrammarTransition(
+                LdapStatesEnum.MODIFY_DN_REQUEST_TAG, LdapStatesEnum.MODIFY_DN_REQUEST_VALUE,
+                null );
+
+        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE { (Value)
+        // Initialise the modify DN request pojo
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_VALUE][0x6c] = new GrammarTransition(
+                LdapStatesEnum.MODIFY_DN_REQUEST_VALUE, LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_TAG,
+                new GrammarAction( "Init Modify DN Request" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        // Now, we can allocate the ModifyDNRequest Object
+                        // And we associate it to the ldapMessage Object
+                        ldapMessage.setProtocolOP( new ModifyDNRequest() );
+
+                    }
+                } );
+
+        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+        //    entry           LDAPDN, (Tag)
+        //    ...
+        // The tag is 0x04. Nothing to do
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_TAG][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_TAG,
+                LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_VALUE, null );
+
+        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+        //    entry           LDAPDN, (Value)
+        //    ...
+        // We store the entry. It must not be null.
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_VALUE][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_VALUE,
+                LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_TAG,
+                new GrammarAction( "Store entry" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        ModifyDNRequest      modifyDNRequest = ldapMessage.getModifyDNRequest();
+
+                        // Get the Value and store it in the modifyDNRequest
+                        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 nut be null" );
+                        }
+                        else
+                        {
+                            modifyDNRequest.setEntry( new LdapDN( tlv.getValue().getData()
) );
+                        }
+
+                        return;
+                    }
+                } );
+
+        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+        //    ...
+        //    newrdn          RelativeLDAPDN, (Tag)
+        //    ...
+        // The tag is 0x04. A RelativeLDAPDN is a component of a
+        // LDAPDN. Nothing to do
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_TAG][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_TAG,
+                LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_VALUE, null );
+
+        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+        //    ...
+        //    newrdn          RelativeLDAPDN, (Value)
+        //    ...
+        // A RelativeLDAPDN is a component of a LDAPDN. We have to check that it is
+        // valid.
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_VALUE][0x04] =
+            new GrammarTransition( LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_VALUE,
+                LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_TAG,
+                new GrammarAction( "Store new RDN" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        ModifyDNRequest      modifyDNRequest = ldapMessage.getModifyDNRequest();
+
+                        // Get the Value and store it in the modifyDNRequest
+                        TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+                        // We have to handle the special case of a 0 length matched newDN
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                            throw new DecoderException( "The newrdn must nut be null" );
+                        }
+                        else
+                        {
+                            modifyDNRequest.setNewRDN( new RelativeLdapDN(
+                                    tlv.getValue().getData() ) );
+                        }
+                    }
+                } );
+
+        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+        //    ...
+        //    deleteoldrdn    BOOLEAN, (Tag)
+        //    ...
+        // Nothing to do.
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_TAG][0x01] =
+            new GrammarTransition( LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_TAG,
+                LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_VALUE, null );
+
+        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+        //    ...
+        //    deleteoldrdn    BOOLEAN, (Value)
+        //    ...
+        // Store the flag
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_VALUE][0x01] =
+            new GrammarTransition( LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_VALUE,
+                LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG,
+                new GrammarAction( "Store matching dnAttributes Value" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        TLV                  tlv = ldapMessageContainer.getCurrentTLV();
+
+                        // Store the value.
+                        ModifyDNRequest modifyDNRequest = ldapMessage.getModifyDNRequest();
+
+                        // We get the value. If it's a 0, it's a FALSE. If it's
+                        // a FF, it's a TRUE. Any other value should be an error,
+                        // but we could relax this constraint. So if we have something
+                        // which is not 0, it will be interpreted as TRUE, but we
+                        // will generate a warning.
+                        Value value        = tlv.getValue();
+
+                        int   deleteOldRDN = IntegerDecoder.parse( value, 0, 255 );
+
+                        modifyDNRequest.setDeleteOldRDN( deleteOldRDN != 0 );
+
+                        if ( ( deleteOldRDN != 0 ) && ( deleteOldRDN != 255 ) )
+                        {
+                            log.warn( "A boolean must be encoded with a 0x00 or a 0xFF value"
);
+                        }
+
+                    }
+                } );
+
+        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+        //    ...
+        //    newSuperior     [0] LDAPDN OPTIONAL } (Tag)
+        // This is an optionnal element. Nothing to do
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG,
+                LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_VALUE, null );
+
+        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+        //    ...
+        //    newSuperior     [0] LDAPDN OPTIONAL } (Tag)
+        // We store the new superior. It may be null, but in this case,
+        // we will consider that it's just a change of the entry, except
+        // if the deleteOldRDN flag is set to true, in which case this is
+        // an error.
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_VALUE][0x04] =
+            new GrammarTransition(
+                LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_VALUE, LdapStatesEnum.GRAMMAR_END,
+                new GrammarAction( "Store new superior" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessage          ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        ModifyDNRequest      modifyDNRequest = ldapMessage.getModifyDNRequest();
+
+                        // Get the Value and store it in the modifyDNRequest
+                        TLV tlv = ldapMessageContainer.getCurrentTLV();
+
+                        // We have to handle the special case of a 0 length matched DN
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+
+                            if ( modifyDNRequest.isDeleteOldRDN() )
+                            {
+                                throw new DecoderException(
+                                    "The new superior must nut be null if the flag 'delete
old DN' is set to true" );
+                            }
+                            else
+                            {
+                                log.warn(
+                                    "The new superior is null, so we will change the entry"
);
+                            }
+
+                            modifyDNRequest.setNewSuperior( LdapDN.EMPTY_STRING );
+                        }
+                        else
+                        {
+                            modifyDNRequest.setNewSuperior( new LdapDN(
+                                    tlv.getValue().getData() ) );
+                        }
+
+                        return;
+                    }
+                } );
+
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * This class is a singleton.
+     *
+     * @return An instance on this grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}



Mime
View raw message