Author: kayyagari
Date: Mon May 3 16:28:47 2010
New Revision: 940504
URL: http://svn.apache.org/viewvc?rev=940504&view=rev
Log:
an extended control which is planned to be used in syncrepl implementation
(NOTE: syncrepl spec RFC4533 doesn't support this)
Added:
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControl.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlContainer.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlDecoder.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlGrammar.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlStatesEnum.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlTags.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncModifyDnType.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncModifyDnControlTest.java
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControl.java?rev=940504&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControl.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControl.java
Mon May 3 16:28:47 2010
@@ -0,0 +1,324 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.controls.replication.syncmodifydn;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.codec.controls.AbstractControl;
+import org.apache.directory.shared.ldap.message.control.replication.SyncModifyDnType;
+
+
+/**
+ * A SyncModifyDnControl object, to send the parameters used in a MODIFYDN operation
+ * that was carried out on a syncrepl provider server.
+ *
+ * The consumer will use the values present in this control to perform the same operation
+ * on its local data, which helps in avoiding huge number of updates to the consumer.
+ *
+ * NOTE: syncrepl, defined in RFC 4533, doesn't mention about this approach, this is a special
+ * extension provided by Apache Directory Server
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev:$, $Date:
+ */
+public class SyncModifyDnControl extends AbstractControl
+{
+ /** This control OID */
+ public static final String CONTROL_OID = "1.3.6.1.4.1.4203.1.9.1.5";
+
+ /** the entry's DN to be changed */
+ private String entryDn;
+
+ /** target entry's new parent DN */
+ private String newSuperiorDn;
+
+ /** the new RDN */
+ private String newRdn;
+
+ /** flag to indicate whether to delete the old RDN */
+ private boolean deleteOldRdn = false;
+
+ private SyncModifyDnType modDnType;
+
+ /** global length for the control */
+ private int syncModDnSeqLength;
+
+ private int moveLen = 0;
+ private int renameLen = 0;
+ private int moveAndRenameLen = 0;
+
+
+ public SyncModifyDnControl()
+ {
+ super( CONTROL_OID );
+ decoder = new SyncModifyDnControlDecoder();
+ }
+
+
+ public SyncModifyDnControl( SyncModifyDnType type )
+ {
+ this();
+ this.modDnType = type;
+ }
+
+
+ /**
+ * Compute the SyncStateValue length.
+ *
+ * SyncStateValue :
+ * 0x30 L1
+ * |
+ * +--> 0x04 L2 uid=jim... (entryDn)
+ * [+--> 0x04 L3 ou=system... (newSuperior)
+ * [+--> 0x04 L4 uid=jack... (newRdn)
+ * [+--> 0x04 0x01 [0x00|0x01]... (deleteOldRdn)
+ *
+ */
+ public int computeLength()
+ {
+ syncModDnSeqLength = 1 + TLV.getNbBytes( entryDn.length() ) + entryDn.length();
+
+ switch ( modDnType )
+ {
+ case MOVE:
+ moveLen = 1 + TLV.getNbBytes( newSuperiorDn.length() ) + newSuperiorDn.length();
+ syncModDnSeqLength += 1 + TLV.getNbBytes( moveLen ) + moveLen;
+ break;
+
+ case RENAME:
+ renameLen = 1 + TLV.getNbBytes( newRdn.length() ) + newRdn.length();
+
+ // deleteOldRdn
+ renameLen += 1 + 1 + 1;
+
+ syncModDnSeqLength += 1 + TLV.getNbBytes( renameLen ) + renameLen;
+ break;
+
+ case MOVEANDREANAME:
+ moveAndRenameLen = 1 + TLV.getNbBytes( newSuperiorDn.length() ) + newSuperiorDn.length();
+ moveAndRenameLen += 1 + TLV.getNbBytes( newRdn.length() ) + newRdn.length();
+ // deleteOldRdn
+ moveAndRenameLen += 1 + 1 + 1;
+
+ syncModDnSeqLength += 1 + TLV.getNbBytes( moveAndRenameLen ) + moveAndRenameLen;
+ break;
+ }
+
+ valueLength = 1 + TLV.getNbBytes( syncModDnSeqLength ) + syncModDnSeqLength;
+
+ return super.computeLength( valueLength );
+ }
+
+
+ /**
+ * Encode the SyncStateValue control
+ *
+ * @param buffer The encoded sink
+ * @return A ByteBuffer that contains the encoded PDU
+ * @throws EncoderException If anything goes wrong.
+ */
+ public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+ {
+ if ( buffer == null )
+ {
+ throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
+ }
+
+ // Encode the Control envelop
+ super.encode( buffer );
+
+ // Encode the SEQ
+ buffer.put( UniversalTag.SEQUENCE_TAG );
+ buffer.put( TLV.getBytes( syncModDnSeqLength ) );
+
+ // the entryDn
+ Value.encode( buffer, entryDn );
+
+ switch ( modDnType )
+ {
+ case MOVE:
+ buffer.put( ( byte ) SyncModifyDnControlTags.MOVE_TAG.getValue() );
+ buffer.put( TLV.getBytes( moveLen ) );
+ Value.encode( buffer, newSuperiorDn );
+ break;
+
+ case RENAME:
+ buffer.put( ( byte ) SyncModifyDnControlTags.RENAME_TAG.getValue() );
+ buffer.put( TLV.getBytes( renameLen ) );
+ Value.encode( buffer, newRdn );
+ Value.encode( buffer, deleteOldRdn );
+ break;
+
+ case MOVEANDREANAME:
+ buffer.put( ( byte ) SyncModifyDnControlTags.MOVEANDRENAME_TAG.getValue()
);
+ buffer.put( TLV.getBytes( moveAndRenameLen ) );
+ Value.encode( buffer, newSuperiorDn );
+ Value.encode( buffer, newRdn );
+ Value.encode( buffer, deleteOldRdn );
+ break;
+ }
+
+ return buffer;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getValue()
+ {
+ if ( value == null )
+ {
+ try
+ {
+ computeLength();
+ ByteBuffer buffer = ByteBuffer.allocate( valueLength );
+
+ // Encode the SEQ
+ buffer.put( UniversalTag.SEQUENCE_TAG );
+ buffer.put( TLV.getBytes( syncModDnSeqLength ) );
+
+ // the entryDn
+ Value.encode( buffer, entryDn );
+
+ switch ( modDnType )
+ {
+ case MOVE:
+ buffer.put( ( byte ) SyncModifyDnControlTags.MOVE_TAG.getValue()
);
+ buffer.put( TLV.getBytes( moveLen ) );
+ Value.encode( buffer, newSuperiorDn );
+ break;
+
+ case RENAME:
+ buffer.put( ( byte ) SyncModifyDnControlTags.RENAME_TAG.getValue()
);
+ buffer.put( TLV.getBytes( renameLen ) );
+ Value.encode( buffer, newRdn );
+ Value.encode( buffer, deleteOldRdn );
+ break;
+
+ case MOVEANDREANAME:
+ buffer.put( ( byte ) SyncModifyDnControlTags.MOVEANDRENAME_TAG.getValue()
);
+ buffer.put( TLV.getBytes( moveAndRenameLen ) );
+ Value.encode( buffer, newSuperiorDn );
+ Value.encode( buffer, newRdn );
+ Value.encode( buffer, deleteOldRdn );
+ break;
+ }
+
+ value = buffer.array();
+ }
+ catch ( Exception e )
+ {
+ return null;
+ }
+ }
+
+ return value;
+ }
+
+
+ public String getEntryDn()
+ {
+ return entryDn;
+ }
+
+
+ public void setEntryDn( String entryDn )
+ {
+ this.entryDn = entryDn;
+ }
+
+
+ public String getNewSuperiorDn()
+ {
+ return newSuperiorDn;
+ }
+
+
+ public void setNewSuperiorDn( String newSuperiorDn )
+ {
+ this.newSuperiorDn = newSuperiorDn;
+ }
+
+
+ public String getNewRdn()
+ {
+ return newRdn;
+ }
+
+
+ public void setNewRdn( String newRdn )
+ {
+ this.newRdn = newRdn;
+ }
+
+
+ public boolean isDeleteOldRdn()
+ {
+ return deleteOldRdn;
+ }
+
+
+ public void setDeleteOldRdn( boolean deleteOldRdn )
+ {
+ this.deleteOldRdn = deleteOldRdn;
+ }
+
+
+ public SyncModifyDnType getModDnType()
+ {
+ return modDnType;
+ }
+
+
+ public void setModDnType( SyncModifyDnType modDnType )
+ {
+ if( this.modDnType != null )
+ {
+ throw new IllegalStateException( "cannot overwrite the existing modDnType value"
);
+ }
+ this.modDnType = modDnType;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( " SyncModifyDn control :\n" );
+ sb.append( " oid : '" ).append( getOid() ).append( '\n' );
+ sb.append( " critical : '" ).append( isCritical() ).append( '\n' );
+ sb.append( " entryDn : '" ).append( entryDn ).append( "'\n" );
+ sb.append( " newSuperior : '" ).append( newSuperiorDn ).append( "'\n" );
+ sb.append( " newRdn : '" ).append( newRdn ).append( "'\n" );
+ sb.append( " deleteOldRdn : '" ).append( deleteOldRdn ).append( "'\n" );
+
+ return sb.toString();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlContainer.java?rev=940504&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlContainer.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlContainer.java
Mon May 3 16:28:47 2010
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.controls.replication.syncmodifydn;
+
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+
+
+/**
+ * A container for the SyncModifyDnControl control
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 741888 $, $Date: 2009-02-07 13:57:03 +0100 (Sat, 07 Feb 2009) $,
+ */
+public class SyncModifyDnControlContainer extends AbstractContainer
+{
+ /** SyncModifyDnControl */
+ private SyncModifyDnControl control;
+
+
+ /**
+ * Creates a new SyncStateValueControlContainer object. We will store one grammar,
+ * it's enough ...
+ */
+ public SyncModifyDnControlContainer()
+ {
+ super();
+ stateStack = new int[1];
+ grammar = SyncModifyDnControlGrammar.getInstance();
+ states = SyncModifyDnControlStatesEnum.getInstance();
+ }
+
+
+ /**
+ * @return Returns the SyncModifyDnControl control.
+ */
+ public SyncModifyDnControl getSyncModifyDnControl()
+ {
+ return control;
+ }
+
+
+ /**
+ * Set a SyncModifyDnControl Object into the container. It will be completed by
+ * the ldapDecoder.
+ *
+ * @param control the SyncStateValueControl to set.
+ */
+ public void setSyncModifyDnControl( SyncModifyDnControl control )
+ {
+ this.control = control;
+ }
+
+ /**
+ * Clean the container
+ */
+ public void clean()
+ {
+ super.clean();
+ control = null;
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlDecoder.java?rev=940504&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlDecoder.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlDecoder.java
Mon May 3 16:28:47 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.controls.replication.syncmodifydn;
+
+
+import java.nio.ByteBuffer;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.asn1.Asn1Object;
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.ldap.codec.controls.ControlDecoder;
+import org.apache.directory.shared.ldap.message.control.Control;
+
+
+/**
+ * A decoder for SyncModifyDnControl
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 741888 $, $Date: 2009-02-07 13:57:03 +0100 (Sat, 07 Feb 2009) $,
+ */
+public class SyncModifyDnControlDecoder extends Asn1Decoder implements ControlDecoder
+{
+ /** An instance of this decoder */
+ private static final Asn1Decoder decoder = new Asn1Decoder();
+
+ /**
+ * Decode the SyncModifyDnControl control
+ *
+ * @param controlBytes The bytes array which contains the encoded SyncModifyDnControl
+ *
+ * @return A valid SyncModifyDnControl object
+ *
+ * @throws DecoderException If the decoding found an error
+ * @throws NamingException It will never be throw by this method
+ */
+ public Asn1Object decode( byte[] controlBytes, Control control ) throws DecoderException
+ {
+ ByteBuffer bb = ByteBuffer.wrap( controlBytes );
+ SyncModifyDnControlContainer container = new SyncModifyDnControlContainer();
+ container.setSyncModifyDnControl( (SyncModifyDnControl)control );
+
+ decoder.decode( bb, container );
+ return container.getSyncModifyDnControl();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlGrammar.java?rev=940504&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlGrammar.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlGrammar.java
Mon May 3 16:28:47 2010
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.controls.replication.syncmodifydn;
+
+
+import org.apache.directory.shared.asn1.ber.IAsn1Container;
+import org.apache.directory.shared.asn1.ber.grammar.AbstractGrammar;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.shared.asn1.ber.grammar.GrammarTransition;
+import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
+import org.apache.directory.shared.asn1.ber.grammar.IStates;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.ldap.message.control.replication.SyncModifyDnType;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the SyncModifyDnControl. All the actions are declared in
+ * this class. As it is a singleton, these declaration are only done once.
+ *
+ * The decoded grammar is the following :
+ *
+ * syncmodifyDnControl ::= SEQUENCE {
+ * entry-name LDAPDN,
+ * Operation
+ * }
+ *
+ * Operation ::= CHOICE {
+ * move-name [0] LDAPDN,
+ * rename [1] Rename,
+ * move-and-rename [2] MoveAndRename
+ * }
+ *
+ * Rename SEQUENCE {
+ * new-rdn RDN,
+ * delete-old-rdn BOOLEAN
+ * }
+ *
+ * MoveAndRename SEQUENCE {
+ * superior-name LDAPDN
+ * new-rd RDN,
+ * delete-old-rdn BOOLEAN
+ * }
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 741888 $, $Date: 2009-02-07 13:57:03 +0100 (Sat, 07 Feb 2009) $,
+ */
+public class SyncModifyDnControlGrammar extends AbstractGrammar
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( SyncModifyDnControlGrammar.class );
+
+ /** Speedup for logs */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. SyncStateValueControlGrammar is a singleton */
+ private static IGrammar instance = new SyncModifyDnControlGrammar();
+
+
+ /**
+ * Creates a new SyncModifyDnControlGrammar object.
+ */
+ private SyncModifyDnControlGrammar()
+ {
+ name = SyncModifyDnControlGrammar.class.getName();
+ statesEnum = SyncModifyDnControlStatesEnum.getInstance();
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[SyncModifyDnControlStatesEnum.LAST_SYNC_MODDN_VALUE_STATE][256];
+
+ /**
+ * Transition from initial state to SyncModifyDnControl sequence
+ * SyncModifyDnControl ::= SEQUENCE OF {
+ * ...
+ *
+ * Initialize the SyncModifyDnControl object
+ */
+ super.transitions[IStates.INIT_GRAMMAR_STATE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
+ IStates.INIT_GRAMMAR_STATE, SyncModifyDnControlStatesEnum.SYNC_MODDN_VALUE_SEQUENCE_STATE,
+ UniversalTag.SEQUENCE_TAG, null );
+
+ /**
+ * Transition from SyncModifyDnControl sequence to entryDn
+ * move-name ::= SEQUENCE OF {
+ * DN entryDN
+ * ...
+ *
+ * Stores the entryDn value
+ */
+ super.transitions[SyncModifyDnControlStatesEnum.SYNC_MODDN_VALUE_SEQUENCE_STATE][UniversalTag.OCTET_STRING_TAG]
= new GrammarTransition(
+ IStates.INIT_GRAMMAR_STATE,
+ SyncModifyDnControlStatesEnum.SYNC_MODDN_VALUE_SEQUENCE_STATE, UniversalTag.OCTET_STRING_TAG,
new GrammarAction(
+ "Set SyncModifyDnControl entryDn value" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncModifyDnControlContainer syncModifyDnControlContainer = ( SyncModifyDnControlContainer
) container;
+ Value value = syncModifyDnControlContainer.getCurrentTLV().getValue();
+
+ // Check that the value is into the allowed interval
+ String entryDn = StringTools.utf8ToString( value.getData() );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "ModDN entryDn = {}", entryDn );
+ }
+
+ syncModifyDnControlContainer.getSyncModifyDnControl().setEntryDn( entryDn
);
+
+ // move on to the next transistion
+ syncModifyDnControlContainer.grammarEndAllowed( false );
+ }
+ } );
+
+ /**
+ * Transition to move choice
+ * Operation ::= CHOICE {
+ * move-name [0] LDAPDN
+ * }
+ *
+ * Stores the newSuperiorDn value
+ */
+
+ super.transitions[IStates.INIT_GRAMMAR_STATE][SyncModifyDnControlTags.MOVE_TAG.getValue()]
= new GrammarTransition(
+ IStates.INIT_GRAMMAR_STATE, SyncModifyDnControlStatesEnum.MOVE_DN_STATE,
+ SyncModifyDnControlTags.MOVE_TAG.getValue(), new GrammarAction( "Set SyncModifyDnControl
newSuperiorDn" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncModifyDnControlContainer syncModifyDnControlContainer = ( SyncModifyDnControlContainer
) container;
+ syncModifyDnControlContainer.getSyncModifyDnControl().setModDnType( SyncModifyDnType.MOVE
);
+ // We need to read the move operation's superiorDN
+ syncModifyDnControlContainer.grammarEndAllowed( false );
+ }
+ } );
+
+ /**
+ * read the newSuperiorDn
+ * move-name [0] LDAPDN
+ */
+ super.transitions[SyncModifyDnControlStatesEnum.MOVE_DN_STATE][UniversalTag.OCTET_STRING_TAG]
= new GrammarTransition(
+ SyncModifyDnControlStatesEnum.MOVE_DN_STATE, SyncModifyDnControlStatesEnum.NEW_SUPERIOR_DN_STATE,
+ UniversalTag.OCTET_STRING_TAG, new GrammarAction( "Set SyncModifyDnControl newSuperiorDn"
)
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncModifyDnControlContainer syncModifyDnControlContainer = ( SyncModifyDnControlContainer
) container;
+ Value value = syncModifyDnControlContainer.getCurrentTLV().getValue();
+
+ String newSuperiorDn = StringTools.utf8ToString( value.getData() );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "newSuperiorDn = {}", newSuperiorDn );
+ }
+
+ syncModifyDnControlContainer.getSyncModifyDnControl().setNewSuperiorDn(
newSuperiorDn );
+
+ // We can have an END transition
+ syncModifyDnControlContainer.grammarEndAllowed( true );
+ }
+ } );
+
+ // elecharny, the below transitions are wrong, but if the above code for reading
the 'move' CHOICE's superiorDN is solved
+ // will take the cue from there and try fixing the below for 'rename' and 'moveAndRename'
CHOICE
+ /**
+ * Transition from entryDN to newRdn
+ *
+ * Rename SEQUENCE {
+ * new-rdn RDN,
+ * delete-old-rdn BOOLEAN
+ * }
+ *
+ * Stores the newRdn value
+ */
+ super.transitions[SyncModifyDnControlStatesEnum.NEW_SUPERIOR_DN_STATE][SyncModifyDnControlTags.RENAME_TAG.getValue()]
= new GrammarTransition(
+ SyncModifyDnControlStatesEnum.NEW_SUPERIOR_DN_STATE, SyncModifyDnControlStatesEnum.NEW_RDN_STATE,
+ UniversalTag.OCTET_STRING_TAG, new GrammarAction( "Set SyncModifyDnControl newRdn
value" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncModifyDnControlContainer syncModifyDnControlContainer = ( SyncModifyDnControlContainer
) container;
+ Value value = syncModifyDnControlContainer.getCurrentTLV().getValue();
+
+ String newRdn = StringTools.utf8ToString( value.getData() );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "newRdn = {}", newRdn );
+ }
+
+ syncModifyDnControlContainer.getSyncModifyDnControl().setNewRdn( newRdn
);
+
+ // terminal state
+ syncModifyDnControlContainer.grammarEndAllowed( true );
+ }
+ } );
+
+ /**
+ * Transition from entryDN to deleteOldRdn
+ * MoveAndRename SEQUENCE {
+ * superior-name LDAPDN
+ * new-rd RDN,
+ * delete-old-rdn BOOLEAN
+ * }
+ *
+ * Stores the deleteOldRdn flag
+ */
+ super.transitions[SyncModifyDnControlStatesEnum.NEW_RDN_STATE][UniversalTag.BOOLEAN_TAG]
= new GrammarTransition(
+ SyncModifyDnControlStatesEnum.NEW_RDN_STATE, SyncModifyDnControlStatesEnum.DEL_OLD_RDN_STATE,
+ UniversalTag.BOOLEAN_TAG, new GrammarAction( "Set SyncModifyDnControl deleteOldRdn
value" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncModifyDnControlContainer syncModifyDnControlContainer = ( SyncModifyDnControlContainer
) container;
+ Value value = syncModifyDnControlContainer.getCurrentTLV().getValue();
+
+ byte deleteOldRdn = value.getData()[0];
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "deleteOldRdn = {}", deleteOldRdn );
+ }
+
+ if( deleteOldRdn == 1 )
+ {
+ syncModifyDnControlContainer.getSyncModifyDnControl().setDeleteOldRdn(
true );
+ }
+
+ // terminal state
+ syncModifyDnControlContainer.grammarEndAllowed( true );
+ }
+ } );
+ }
+
+
+ /**
+ * This class is a singleton.
+ *
+ * @return An instance on this grammar
+ */
+ public static IGrammar getInstance()
+ {
+ return instance;
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlStatesEnum.java?rev=940504&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlStatesEnum.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlStatesEnum.java
Mon May 3 16:28:47 2010
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.controls.replication.syncmodifydn;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
+import org.apache.directory.shared.asn1.ber.grammar.IStates;
+
+
+/**
+ * This class store the SyncModifyDnControl's grammar constants. It is also used for
+ * debugging purposes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 741888 $, $Date: 2009-02-07 13:57:03 +0100 (Sat, 07 Feb 2009) $,
+ */
+public class SyncModifyDnControlStatesEnum implements IStates
+{
+ // ~ Static fields/initializers
+ // -----------------------------------------------------------------
+
+ // =========================================================================
+ // SyncModifyDnControl's control grammar states
+ // =========================================================================
+ /** Initial state */
+ public static final int START_SYNC_MODDN = 0;
+
+ /** Sequence Value */
+ public static final int SYNC_MODDN_VALUE_SEQUENCE_STATE = 1;
+
+// /** modDn control's entryDN */
+// public static final int ENTRY_DN_STATE = 1;
+
+ /** modDn control's move operation state */
+ public static final int MOVE_DN_STATE = 2;
+
+ /** modDn control's newSuperiorDN */
+ public static final int NEW_SUPERIOR_DN_STATE = 3;
+
+ /** modDn control's rename operation state */
+ public static final int RENAME_DN_STATE = 5;
+
+ /** modDn control's newRDN */
+ public static final int NEW_RDN_STATE = 6;
+
+ /** modDn control's rename operation state */
+ public static final int MOVE_AND_RENAME_DN_STATE = 7;
+
+ /** modDn control's deleteOldRdn flag */
+ public static final int DEL_OLD_RDN_STATE = 8;
+
+ /** terminal state */
+ public static final int LAST_SYNC_MODDN_VALUE_STATE = 9;
+
+ // =========================================================================
+ // States debug strings
+ // =========================================================================
+ /** A string representation of all the states */
+ private static String[] syncModifyDnString = new String[]
+ {
+ "START_SYNC_MODDN",
+// "SYNC_MODDN_VALUE_SEQUENCE_STATE",
+ "ENTRY_DN_STATE",
+ "MOVE_DN_STATE",
+ "NEW_SUPERIOR_DN_STATE",
+ "RENAME_DN_STATE",
+ "NEW_RDN_STATE",
+ "MOVE_AND_RENAME_DN_STATE",
+ "DEL_OLD_RDN_STATE"
+ };
+
+ /** The instance */
+ private static SyncModifyDnControlStatesEnum instance = new SyncModifyDnControlStatesEnum();
+
+
+ // ~ Constructors
+ // -------------------------------------------------------------------------------
+
+ /**
+ * This is a private constructor. This class is a singleton
+ */
+ private SyncModifyDnControlStatesEnum()
+ {
+ }
+
+
+ // ~ Methods
+ // ------------------------------------------------------------------------------------
+
+ /**
+ * Get an instance of this class
+ *
+ * @return An instance on this class
+ */
+ public static IStates getInstance()
+ {
+ return instance;
+ }
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar code
+ * @return The grammar name
+ */
+ public String getGrammarName( int grammar )
+ {
+ return "SYNC_MODIFYDN_GRAMMAR";
+ }
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar class
+ * @return The grammar name
+ */
+ public String getGrammarName( IGrammar grammar )
+ {
+ if ( grammar instanceof SyncModifyDnControlGrammar )
+ {
+ return "SYNC_MODIFYDN_GRAMMAR";
+ }
+
+ return "UNKNOWN GRAMMAR";
+ }
+
+
+ /**
+ * Get the string representing the state
+ *
+ * @param state The state number
+ * @return The String representing the state
+ */
+ public String getState( int state )
+ {
+ return ( ( state == GRAMMAR_END ) ? "SYNC_MODDN_VALUE_END_STATE" : syncModifyDnString[state]
);
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlTags.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlTags.java?rev=940504&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlTags.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlTags.java
Mon May 3 16:28:47 2010
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.controls.replication.syncmodifydn;
+
+
+/**
+ * TODO SyncModifyDnControlTags.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public enum SyncModifyDnControlTags
+{
+ MOVE_TAG(0x0080), RENAME_TAG(0x00A1), MOVEANDRENAME_TAG(0x00A2);
+
+ /** Internal value for each tag */
+ private int value;
+
+
+ private SyncModifyDnControlTags( int value )
+ {
+ this.value = value;
+ }
+
+
+ public int getValue()
+ {
+ return value;
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncModifyDnType.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncModifyDnType.java?rev=940504&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncModifyDnType.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncModifyDnType.java
Mon May 3 16:28:47 2010
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.message.control.replication;
+
+/**
+ * TODO SyncModifyDnControlEnum.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public enum SyncModifyDnType
+{
+ MOVE( 0 ),
+ RENAME( 1 ),
+ MOVEANDREANAME( 2 );
+
+ /** Internal value for each tag */
+ private int value;
+
+ private SyncModifyDnType( int value )
+ {
+ this.value = value;
+ }
+
+
+ /**
+ * @return The value associated with the current element.
+ */
+ public int getValue()
+ {
+ return value;
+ }
+
+
+ public static SyncModifyDnType getModifyDnType( int value )
+ {
+ switch( value )
+ {
+ case 0 : return MOVE;
+
+ case 1 : return RENAME;
+
+ case 2 : return MOVEANDREANAME;
+ }
+
+ throw new IllegalArgumentException( "unknown modify dn operantion type " + value
);
+ }
+}
Added: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncModifyDnControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncModifyDnControlTest.java?rev=940504&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncModifyDnControlTest.java
(added)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncModifyDnControlTest.java
Mon May 3 16:28:47 2010
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.directory.shared.ldap.codec.controls.replication;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.ldap.codec.controls.replication.syncmodifydn.SyncModifyDnControl;
+import org.apache.directory.shared.ldap.codec.controls.replication.syncmodifydn.SyncModifyDnControlContainer;
+import org.apache.directory.shared.ldap.codec.controls.replication.syncmodifydn.SyncModifyDnControlDecoder;
+import org.junit.Test;
+
+/**
+ * TODO SyncModifyDnControlTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SyncModifyDnControlTest
+{
+
+ @Test
+ public void testDecodeSyncModifyDnControlWithMoveOperation()
+ {
+ Asn1Decoder decoder = new SyncModifyDnControlDecoder();
+ ByteBuffer bb = ByteBuffer.allocate( 28 );
+ bb.put( new byte[]
+ {
+ 0x30, 0x1A, // SyncModifyDnControl ::= SEQUENCE
{
+ 0x04, 0x07, 'u','i','d','=','j','i','m', // entryDn LDAPDN
+ ( byte )0x0080, 0x07, // move
+ 0x04, 0x05, 'o','u','=','d','c' // newSuperiorDn LDAPDN
+ } );
+ bb.flip();
+
+ SyncModifyDnControlContainer container = new SyncModifyDnControlContainer();
+ container.setSyncModifyDnControl( new SyncModifyDnControl() );
+
+ try
+ {
+ decoder.decode( bb, container );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ SyncModifyDnControl syncmodDnControl = container.getSyncModifyDnControl();
+ assertEquals( "uid=jim", syncmodDnControl.getEntryDn() );
+ assertEquals( "ou=dc", syncmodDnControl.getNewSuperiorDn() );
+ assertFalse( syncmodDnControl.isDeleteOldRdn() );
+
+ /*
+ // Check the encoding
+ try
+ {
+
+ ByteBuffer buffer = ByteBuffer.allocate( 56 );
+ buffer.put( new byte[]
+ {
+ 0x30, 0x36, // Control
+ 0x04, 0x18, // OID (SuncStateValue)
+ '1', '.', '3', '.', '6', '.', '1', '.',
+ '4', '.', '1', '.', '4', '2', '0', '3',
+ '.', '1', '.', '9', '.', '1', '.', '5',
+ 0x04, 0x1A,
+ 0x30, 0x18,
+ 0x04, 0x07, 'u','i','d','=','j','i','m', // entryDn entryDn
+ 0x04, 0x05, 'u','i','d','=','j', // newSuperiorDn newSuperiorDn
OPTIONAL,
+ 0x04, 0x03, 'x', '=', 'y', // newRdn newRdn OPTIONAL,
+ 0x01, 0x01, 0x00 // deleteOldRdn deleteOldRdn
OPTIONAL
+ } );
+ buffer.flip();
+
+ ByteBuffer encoded = syncmodDnControl.encode( ByteBuffer.allocate( syncmodDnControl.computeLength()
) );
+ assertEquals( StringTools.dumpBytes( buffer.array() ), StringTools.dumpBytes(
encoded.array() ) );
+ }
+ catch ( EncoderException ee )
+ {
+ fail( ee.getMessage() );
+ }
+ */
+ }
+}
|