Author: elecharny
Date: Sun Feb 8 15:47:34 2009
New Revision: 742122
URL: http://svn.apache.org/viewvc?rev=742122&view=rev
Log:
Added the syncInfoValue decoder and tests
Added:
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlCodec.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlContainer.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlDecoder.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlGrammar.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlStatesEnum.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueTags.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueControl.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueNewCookieControl.java (with props)
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueRefreshDeleteControl.java
directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SynchronizationInfoEnum.java
directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncInfoValueControlTest.java
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlCodec.java?rev=742122&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlCodec.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlCodec.java Sun Feb 8 15:47:34 2009
@@ -0,0 +1,445 @@
+/*
+ * 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.syncInfoValue;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.shared.asn1.AbstractAsn1Object;
+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.ldap.message.control.replication.SynchronizationInfoEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+/**
+ * A syncInfoValue object, as defined in RFC 4533
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev:$, $Date:
+ */
+public class SyncInfoValueControlCodec extends AbstractAsn1Object
+{
+ /** The kind of syncInfoValue we are dealing with */
+ private SynchronizationInfoEnum type;
+
+ /** The cookie */
+ private byte[] cookie;
+
+ /** The refreshDone flag if we are dealing with refreshXXX syncInfo. Default to true */
+ private boolean refreshDone = true;
+
+ /** The refreshDeletes flag if we are dealing with syncIdSet syncInfo. Defaluts to false */
+ private boolean refreshDeletes = false;
+
+ /** The list of UUIDs if we are dealing with syncIdSet syncInfo */
+ private List<byte[]> syncUUIDs;
+
+ /** The syncUUIDs cumulative lentgh */
+ private int syncUUIDsLength;
+
+
+ /**
+ * The constructor for this codec.
+ * @param type The kind of syncInfo we will store. Can be newCookie,
+ * refreshPresent, refreshDelete or syncIdSet
+ */
+ public SyncInfoValueControlCodec( SynchronizationInfoEnum type )
+ {
+ this.type = type;
+
+ // Initialize the arrayList if needed
+ if ( type == SynchronizationInfoEnum.SYNC_ID_SET )
+ {
+ syncUUIDs = new ArrayList<byte[]>();
+ }
+ }
+
+
+ /** The global length for this control */
+ private int syncInfoValueLength;
+
+ /**
+ * Get the control type.
+ *
+ * @return the type : one of newCookie, refreshDelete, refreshPresent or syncIdSet
+ */
+ public SynchronizationInfoEnum getType()
+ {
+ return type;
+ }
+
+
+ /**
+ * @param syncMode the syncMode to set
+ */
+ public void setType( SynchronizationInfoEnum type )
+ {
+ this.type = type;
+ }
+
+
+ /**
+ * @return the cookie
+ */
+ public byte[] getCookie()
+ {
+ return cookie;
+ }
+
+
+ /**
+ * @param cookie the cookie to set
+ */
+ public void setCookie( byte[] cookie )
+ {
+ this.cookie = cookie;
+ }
+
+
+ /**
+ * @return the refreshDone
+ */
+ public boolean isRefreshDone()
+ {
+ return refreshDone;
+ }
+
+
+ /**
+ * @param refreshDone the refreshDone to set
+ */
+ public void setRefreshDone( boolean refreshDone )
+ {
+ this.refreshDone = refreshDone;
+ }
+
+
+ /**
+ * @return the refreshDeletes
+ */
+ public boolean isRefreshDeletes()
+ {
+ return refreshDeletes;
+ }
+
+
+ /**
+ * @param refreshDeletes the refreshDeletes to set
+ */
+ public void setRefreshDeletes( boolean refreshDeletes )
+ {
+ this.refreshDeletes = refreshDeletes;
+ }
+
+
+ /**
+ * @return the syncUUIDs
+ */
+ public List<byte[]> getSyncUUIDs()
+ {
+ return syncUUIDs;
+ }
+
+
+ /**
+ * @param syncUUIDs the syncUUIDs to set
+ */
+ public void setSyncUUIDs( List<byte[]> syncUUIDs )
+ {
+ this.syncUUIDs = syncUUIDs;
+ }
+
+
+ /**
+ * Compute the SyncInfoValue length.
+ *
+ * SyncInfoValue :
+ *
+ * 0xA0 L1 abcd // newCookie
+ * 0xA1 L2 // refreshDelete
+ * |
+ * [+--> 0x04 L3 abcd] // cookie
+ * [+--> 0x01 0x01 (0x00|0xFF) // refreshDone
+ * 0xA2 L4 // refreshPresent
+ * |
+ * [+--> 0x04 L5 abcd] // cookie
+ * [+--> 0x01 0x01 (0x00|0xFF) // refreshDone
+ * 0xA3 L6 // syncIdSet
+ * |
+ * [+--> 0x04 L7 abcd] // cookie
+ * [+--> 0x01 0x01 (0x00|0xFF) // refreshDeletes
+ * +--> 0x31 L8 // SET OF syncUUIDs
+ * |
+ * [+--> 0x04 L9 abcd] // syncUUID public static final int AND_FILTER_TAG = 0xA0;
+
+ public static final int OR_FILTER_TAG = 0xA1;
+
+ public static final int NOT_FILTER_TAG = 0xA2;
+
+ public static final int BIND_REQUEST_SASL_TAG = 0xA3;
+
+ */
+ public int computeLength()
+ {
+ // The mode length
+ syncInfoValueLength = 0;
+
+ switch ( type )
+ {
+ case NEW_COOKIE :
+ if ( cookie != null )
+ {
+ syncInfoValueLength = 1 + TLV.getNbBytes( cookie.length ) + cookie.length;
+ }
+ else
+ {
+ syncInfoValueLength = 1 + 1;
+ }
+
+ return syncInfoValueLength;
+
+ case REFRESH_DELETE :
+ case REFRESH_PRESENT :
+ if ( cookie != null )
+ {
+ syncInfoValueLength = 1 + TLV.getNbBytes( cookie.length ) + cookie.length;
+ }
+
+ // The refreshDone flag
+ syncInfoValueLength += 1 + 1 + 1;
+ break;
+
+ case SYNC_ID_SET :
+ if ( cookie != null )
+ {
+ syncInfoValueLength = 1 + TLV.getNbBytes( cookie.length ) + cookie.length;
+ }
+
+ // The refreshDeletes flag
+ syncInfoValueLength += 1 + 1 + 1;
+
+ // The syncUUIDs if any
+ syncUUIDsLength = 0;
+
+ if ( syncUUIDs.size() != 0 )
+ {
+ for ( byte[] syncUUID:syncUUIDs )
+ {
+ int uuidLength = 1 + TLV.getNbBytes( syncUUID.length ) + syncUUID.length;
+
+ syncUUIDsLength += 1 + TLV.getNbBytes( uuidLength ) + uuidLength;
+ }
+
+ // Add the tag and compute the length
+ syncUUIDsLength += 1 + TLV.getNbBytes( syncUUIDsLength ) + syncUUIDsLength;
+ }
+
+ syncInfoValueLength += 1 + TLV.getNbBytes( syncUUIDsLength ) + syncUUIDsLength;
+
+ break;
+ }
+
+ return 1 + TLV.getNbBytes( syncInfoValueLength ) + syncInfoValueLength;
+ }
+
+
+ /**
+ * Encode the SyncInfoValue control
+ *
+ * @param buffer The encoded sink
+ * @return A ByteBuffer that contains the encoded PDU
+ * @throws EncoderException If anything goes wrong.
+ */
+ public ByteBuffer encode( ByteBuffer bb ) throws EncoderException
+ {
+ // Allocate the bytes buffer.
+ if ( bb == null )
+ {
+ bb = ByteBuffer.allocate( computeLength() );
+ }
+
+ switch ( type )
+ {
+ case NEW_COOKIE :
+ // The first case : newCookie
+ bb.put( (byte)SyncInfoValueTags.NEW_COOKIE_TAG.getValue() );
+
+ // As the OCTET_STRING is absorbed by the Application tag,
+ // we have to store the L and V separately
+ if ( ( cookie == null ) || ( cookie.length == 0 ) )
+ {
+ bb.put( ( byte ) 0 );
+ }
+ else
+ {
+ bb.put( TLV.getBytes( cookie.length ) );
+ bb.put( cookie );
+ }
+
+ break;
+
+ case REFRESH_DELETE :
+ // The second case : refreshDelete
+ bb.put( (byte)SyncInfoValueTags.REFRESH_DELETE_TAG.getValue() );
+ bb.put( TLV.getBytes( syncInfoValueLength ) );
+
+ // The cookie, if any
+ if ( cookie != null )
+ {
+ Value.encode( bb, cookie );
+ }
+
+ // The refreshDone flag
+ Value.encode( bb, refreshDone );
+ break;
+
+ case REFRESH_PRESENT :
+ // The third case : refreshPresent
+ bb.put( (byte)SyncInfoValueTags.REFRESH_PRESENT_TAG.getValue() );
+ bb.put( TLV.getBytes( syncInfoValueLength ) );
+
+ // The cookie, if any
+ if ( cookie != null )
+ {
+ Value.encode( bb, cookie );
+ }
+
+ // The refreshDone flag
+ Value.encode( bb, refreshDone );
+ break;
+
+ case SYNC_ID_SET :
+ // The last case : syncIdSet
+ bb.put( (byte)SyncInfoValueTags.SYNC_ID_SET_TAG.getValue() );
+ bb.put( TLV.getBytes( syncInfoValueLength ) );
+
+ // The cookie, if any
+ if ( cookie != null )
+ {
+ Value.encode( bb, cookie );
+ }
+
+ // The refreshDeletes flag
+ Value.encode( bb, refreshDeletes );
+
+ // The syncUUIDs
+ bb.put( UniversalTag.SET_TAG );
+ bb.put( TLV.getBytes( syncUUIDsLength ) );
+
+ // Loop on the UUIDs if any
+ if ( syncUUIDs.size() != 0 )
+ {
+ for ( byte[] syncUUID:syncUUIDs )
+ {
+ Value.encode( bb , syncUUID );
+ }
+ }
+ }
+
+ return bb;
+ }
+
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append( " SyncInfoValue control :\n" );
+
+ switch ( type )
+ {
+ case NEW_COOKIE :
+ sb.append( " newCookie : '" ).
+ append( StringTools.dumpBytes( cookie ) ).append( "'\n" );
+ break;
+
+ case REFRESH_DELETE :
+ sb.append( " refreshDelete : \n" );
+
+ if ( cookie != null )
+ {
+ sb.append( " cookie : '" ).
+ append( StringTools.dumpBytes( cookie ) ).append( "'\n" );
+ }
+
+ sb.append( " refreshDone : " ).append( refreshDone ).append( '\n' );
+ break;
+
+ case REFRESH_PRESENT :
+ sb.append( " refreshPresent : \n" );
+
+ if ( cookie != null )
+ {
+ sb.append( " cookie : '" ).
+ append( StringTools.dumpBytes( cookie ) ).append( "'\n" );
+ }
+
+ sb.append( " refreshDone : " ).append( refreshDone ).append( '\n' );
+ break;
+
+ case SYNC_ID_SET :
+ sb.append( " syncIdSet : \n" );
+
+ if ( cookie != null )
+ {
+ sb.append( " cookie : '" ).
+ append( StringTools.dumpBytes( cookie ) ).append( "'\n" );
+ }
+
+ sb.append( " refreshDeletes : " ).append( refreshDeletes ).append( '\n' );
+ sb.append( " syncUUIDS : " );
+
+ if ( syncUUIDs.size() != 0 )
+ {
+ boolean isFirst = true;
+
+ for ( byte[] syncUUID:syncUUIDs )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ", " );
+ }
+
+ sb.append( syncUUID );
+ }
+
+ sb.append( '\n' );
+ }
+ else
+ {
+ sb.append( "empty\n" );
+ }
+
+ break;
+ }
+
+ return sb.toString();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlContainer.java?rev=742122&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlContainer.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlContainer.java Sun Feb 8 15:47:34 2009
@@ -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.syncInfoValue;
+
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+
+
+/**
+ * A container for the SyncInfoValue 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 SyncInfoValueControlContainer extends AbstractContainer
+{
+ /** SyncInfoValueControl */
+ private SyncInfoValueControlCodec control;
+
+
+ /**
+ * Creates a new SyncInfoValueControlContainer object. We will store one grammar,
+ * it's enough ...
+ */
+ public SyncInfoValueControlContainer()
+ {
+ super();
+ stateStack = new int[1];
+ grammar = SyncInfoValueControlGrammar.getInstance();
+ states = SyncInfoValueControlStatesEnum.getInstance();
+ }
+
+
+ /**
+ * @return Returns the syncInfoValue control.
+ */
+ public SyncInfoValueControlCodec getSyncInfoValueControl()
+ {
+ return control;
+ }
+
+
+ /**
+ * Set a SyncInfoValueControl Object into the container. It will be completed by
+ * the ldapDecoder.
+ *
+ * @param control the SyncInfoValueControlCodec to set.
+ */
+ public void setSyncInfoValueControl( SyncInfoValueControlCodec 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/syncInfoValue/SyncInfoValueControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlDecoder.java?rev=742122&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlDecoder.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlDecoder.java Sun Feb 8 15:47:34 2009
@@ -0,0 +1,70 @@
+/*
+ * 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.syncInfoValue;
+
+
+import java.nio.ByteBuffer;
+
+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.ControlDecoder;
+import org.apache.directory.shared.ldap.message.control.replication.SyncInfoValueControl;
+
+
+/**
+ * A decoder for SyncInfoValueControl.
+ *
+ * @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 SyncInfoValueControlDecoder extends Asn1Decoder implements ControlDecoder
+{
+ /** An instance of this decoder */
+ private static final Asn1Decoder decoder = new Asn1Decoder();
+
+ /**
+ * Return the syncInfoValue OID
+ *
+ * @see org.apache.directory.shared.ldap.codec.ControlDecoder#getControlType()
+ */
+ public String getControlType()
+ {
+ return SyncInfoValueControl.CONTROL_OID;
+ }
+
+ /**
+ * Decode the syncInfoValue control
+ *
+ * @param controlBytes The bytes array which contains the encoded syncInfoValue
+ *
+ * @return A valid SyncInfoValueControl object
+ *
+ * @throws DecoderException If the decoding found an error
+ * @throws NamingException It will never be throw by this method
+ */
+ public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+ {
+ ByteBuffer bb = ByteBuffer.wrap( controlBytes );
+ SyncInfoValueControlContainer container = new SyncInfoValueControlContainer();
+ decoder.decode( bb, container );
+ return container.getSyncInfoValueControl();
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlGrammar.java?rev=742122&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlGrammar.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlGrammar.java Sun Feb 8 15:47:34 2009
@@ -0,0 +1,814 @@
+/*
+ * 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.syncInfoValue;
+
+
+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.asn1.util.BooleanDecoder;
+import org.apache.directory.shared.asn1.util.BooleanDecoderException;
+import org.apache.directory.shared.ldap.message.control.replication.SynchronizationInfoEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class implements the SyncInfoValueControl. 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 :
+ *
+ * syncInfoValue ::= CHOICE {
+ * newcookie [0] syncCookie,
+ * refreshDelete [1] SEQUENCE {
+ * cookie syncCookie OPTIONAL,
+ * refreshDone BOOLEAN DEFAULT TRUE
+ * },
+ * refreshPresent [2] SEQUENCE {
+ * cookie syncCookie OPTIONAL,
+ * refreshDone BOOLEAN DEFAULT TRUE
+ * },
+ * syncIdSet [3] SEQUENCE {
+ * cookie syncCookie OPTIONAL,
+ * refreshDeletes BOOLEAN DEFAULT FALSE,
+ * syncUUIDs SET OF syncUUID
+ * }
+ * }
+ *
+ * @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 SyncInfoValueControlGrammar extends AbstractGrammar
+{
+ /** The logger */
+ static final Logger LOG = LoggerFactory.getLogger( SyncInfoValueControlGrammar.class );
+
+ /** Speedup for logs */
+ static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+ /** The instance of grammar. SyncInfoValueControlGrammar is a singleton */
+ private static IGrammar instance = new SyncInfoValueControlGrammar();
+
+
+ /**
+ * Creates a new SyncInfoValueControlGrammar object.
+ */
+ private SyncInfoValueControlGrammar()
+ {
+ name = SyncInfoValueControlGrammar.class.getName();
+ statesEnum = SyncInfoValueControlStatesEnum.getInstance();
+
+ // Create the transitions table
+ super.transitions = new GrammarTransition[SyncInfoValueControlStatesEnum.LAST_SYNC_INFO_VALUE_STATE][256];
+
+ /**
+ * Transition from initial state to SyncInfoValue newCookie choice
+ * SyncInfoValue ::= CHOICE {
+ * newCookie [0] syncCookie,
+ * ...
+ *
+ * Initialize the syncInfoValue object
+ */
+ super.transitions[IStates.INIT_GRAMMAR_STATE][SyncInfoValueTags.NEW_COOKIE_TAG.getValue()] =
+ new GrammarTransition( IStates.INIT_GRAMMAR_STATE,
+ SyncInfoValueControlStatesEnum.NEW_COOKIE_STATE,
+ SyncInfoValueTags.NEW_COOKIE_TAG.getValue(),
+ new GrammarAction( "NewCookie choice for SyncInfoValueControl" )
+ {
+ public void action( IAsn1Container container )
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control =
+ new SyncInfoValueControlCodec( SynchronizationInfoEnum.NEW_COOKIE);
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ byte[] newCookie = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "newcookie = " + StringTools.dumpBytes( newCookie ) );
+ }
+
+ control.setCookie( newCookie );
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+ }
+ } );
+
+
+ /**
+ * Transition from initial state to SyncInfoValue refreshDelete choice
+ * SyncInfoValue ::= CHOICE {
+ * ...
+ * refreshDelete [1] SEQUENCE {
+ * ...
+ *
+ * Initialize the syncInfoValue object
+ */
+ super.transitions[IStates.INIT_GRAMMAR_STATE][SyncInfoValueTags.REFRESH_DELETE_TAG.getValue()] =
+ new GrammarTransition( IStates.INIT_GRAMMAR_STATE,
+ SyncInfoValueControlStatesEnum.REFRESH_DELETE_STATE,
+ SyncInfoValueTags.REFRESH_DELETE_TAG.getValue(),
+ new GrammarAction( "RefreshDelete choice for SyncInfoValueControl" )
+ {
+ public void action( IAsn1Container container )
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control =
+ new SyncInfoValueControlCodec( SynchronizationInfoEnum.REFRESH_DELETE);
+
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from refreshDelete state to cookie
+ * refreshDelete [1] SEQUENCE {
+ * cookie syncCookie OPTIONAL,
+ * ...
+ *
+ * Load the cookie object
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.REFRESH_DELETE_STATE][UniversalTag.OCTET_STRING_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.REFRESH_DELETE_STATE,
+ SyncInfoValueControlStatesEnum.REFRESH_DELETE_COOKIE_STATE,
+ UniversalTag.OCTET_STRING_TAG,
+ new GrammarAction( "RefreshDelete cookie" )
+ {
+ public void action( IAsn1Container container )
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ byte[] cookie = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "cookie = " + StringTools.dumpBytes( cookie ) );
+ }
+
+ syncInfoValueContainer.getSyncInfoValueControl().setCookie( cookie );
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from refreshDelete cookie state to refreshDone
+ * refreshDelete [1] SEQUENCE {
+ * ....
+ * refreshDone BOOLEAN DEFAULT TRUE
+ * }
+ *
+ * Load the refreshDone flag
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.REFRESH_DELETE_COOKIE_STATE][UniversalTag.BOOLEAN_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.REFRESH_DELETE_COOKIE_STATE,
+ SyncInfoValueControlStatesEnum.LAST_SYNC_INFO_VALUE_STATE,
+ UniversalTag.BOOLEAN_TAG,
+ new GrammarAction( "RefreshDelete refreshDone flag" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ try
+ {
+ boolean refreshDone = BooleanDecoder.parse( value );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "refreshDone = {}", refreshDone );
+ }
+
+ control.setRefreshDone( refreshDone );
+
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+
+ // the END transition for grammar
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ catch ( BooleanDecoderException be )
+ {
+ String msg = "failed to decode the refreshDone flag for SyncInfoValueControl";
+ LOG.error( msg, be );
+ throw new DecoderException( msg );
+ }
+
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from refreshDelete choice state to refreshDone
+ * refreshDelete [1] SEQUENCE {
+ * ....
+ * refreshDone BOOLEAN DEFAULT TRUE
+ * }
+ *
+ * Load the refreshDone flag
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.REFRESH_DELETE_STATE][UniversalTag.BOOLEAN_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.REFRESH_DELETE_STATE,
+ SyncInfoValueControlStatesEnum.LAST_SYNC_INFO_VALUE_STATE,
+ UniversalTag.BOOLEAN_TAG,
+ new GrammarAction( "RefreshDelete refreshDone flag" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ try
+ {
+ boolean refreshDone = BooleanDecoder.parse( value );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "refreshDone = {}", refreshDone );
+ }
+
+ control.setRefreshDone( refreshDone );
+
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+
+ // the END transition for grammar
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ catch ( BooleanDecoderException be )
+ {
+ String msg = "failed to decode the refreshDone flag for SyncInfoValueControl";
+ LOG.error( msg, be );
+ throw new DecoderException( msg );
+ }
+
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from initial state to SyncInfoValue refreshPresent choice
+ * SyncInfoValue ::= CHOICE {
+ * ...
+ * refreshPresent [2] SEQUENCE {
+ * ...
+ *
+ * Initialize the syncInfoValue object
+ */
+ super.transitions[IStates.INIT_GRAMMAR_STATE][SyncInfoValueTags.REFRESH_PRESENT_TAG.getValue()] =
+ new GrammarTransition( IStates.INIT_GRAMMAR_STATE,
+ SyncInfoValueControlStatesEnum.REFRESH_PRESENT_STATE,
+ SyncInfoValueTags.REFRESH_PRESENT_TAG.getValue(),
+ new GrammarAction( "RefreshDelete choice for SyncInfoValueControl" )
+ {
+ public void action( IAsn1Container container )
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control =
+ new SyncInfoValueControlCodec( SynchronizationInfoEnum.REFRESH_PRESENT);
+
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from refreshPresent state to cookie
+ * refreshPresent [2] SEQUENCE {
+ * cookie syncCookie OPTIONAL,
+ * ...
+ *
+ * Load the cookie object
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.REFRESH_PRESENT_STATE][UniversalTag.OCTET_STRING_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.REFRESH_PRESENT_STATE,
+ SyncInfoValueControlStatesEnum.REFRESH_PRESENT_COOKIE_STATE,
+ UniversalTag.OCTET_STRING_TAG,
+ new GrammarAction( "RefreshPresent cookie" )
+ {
+ public void action( IAsn1Container container )
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ byte[] cookie = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "cookie = " + StringTools.dumpBytes( cookie ) );
+ }
+
+ syncInfoValueContainer.getSyncInfoValueControl().setCookie( cookie );
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+
+
+ /**
+ * Transition from refreshPresent cookie state to refreshDone
+ * refreshPresent [2] SEQUENCE {
+ * ....
+ * refreshDone BOOLEAN DEFAULT TRUE
+ * }
+ *
+ * Load the refreshDone flag
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.REFRESH_PRESENT_COOKIE_STATE][UniversalTag.BOOLEAN_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.REFRESH_PRESENT_COOKIE_STATE,
+ SyncInfoValueControlStatesEnum.LAST_SYNC_INFO_VALUE_STATE,
+ UniversalTag.BOOLEAN_TAG,
+ new GrammarAction( "RefreshPresent refreshDone flag" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ try
+ {
+ boolean refreshDone = BooleanDecoder.parse( value );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "refreshDone = {}", refreshDone );
+ }
+
+ control.setRefreshDone( refreshDone );
+
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+
+ // the END transition for grammar
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ catch ( BooleanDecoderException be )
+ {
+ String msg = "failed to decode the refreshDone flag for SyncInfoValueControl";
+ LOG.error( msg, be );
+ throw new DecoderException( msg );
+ }
+
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from refreshPresent choice state to refreshDone
+ * refreshPresent [1] SEQUENCE {
+ * ....
+ * refreshDone BOOLEAN DEFAULT TRUE
+ * }
+ *
+ * Load the refreshDone flag
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.REFRESH_PRESENT_STATE][UniversalTag.BOOLEAN_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.REFRESH_PRESENT_STATE,
+ SyncInfoValueControlStatesEnum.LAST_SYNC_INFO_VALUE_STATE,
+ UniversalTag.BOOLEAN_TAG,
+ new GrammarAction( "RefreshPresent refreshDone flag" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ try
+ {
+ boolean refreshDone = BooleanDecoder.parse( value );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "refreshDone = {}", refreshDone );
+ }
+
+ control.setRefreshDone( refreshDone );
+
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+
+ // the END transition for grammar
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ catch ( BooleanDecoderException be )
+ {
+ String msg = "failed to decode the refreshDone flag for SyncInfoValueControl";
+ LOG.error( msg, be );
+ throw new DecoderException( msg );
+ }
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from initial state to SyncInfoValue syncIdSet choice
+ * SyncInfoValue ::= CHOICE {
+ * ...
+ * syncIdSet [3] SEQUENCE {
+ * ...
+ *
+ * Initialize the syncInfoValue object
+ */
+ super.transitions[IStates.INIT_GRAMMAR_STATE][SyncInfoValueTags.SYNC_ID_SET_TAG.getValue()] =
+ new GrammarTransition( IStates.INIT_GRAMMAR_STATE,
+ SyncInfoValueControlStatesEnum.SYNC_ID_SET_STATE,
+ SyncInfoValueTags.SYNC_ID_SET_TAG.getValue(),
+ new GrammarAction( "SyncIdSet choice for SyncInfoValueControl" )
+ {
+ public void action( IAsn1Container container )
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control =
+ new SyncInfoValueControlCodec( SynchronizationInfoEnum.SYNC_ID_SET);
+
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+ }
+ } );
+
+
+ /**
+ * Transition from syncIdSet state to cookie
+ * syncIdSet [3] SEQUENCE {
+ * cookie syncCookie OPTIONAL,
+ * ...
+ *
+ * Load the cookie object
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.SYNC_ID_SET_STATE][UniversalTag.OCTET_STRING_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.SYNC_ID_SET_STATE,
+ SyncInfoValueControlStatesEnum.SYNC_ID_SET_COOKIE_STATE,
+ UniversalTag.OCTET_STRING_TAG,
+ new GrammarAction( "SyncIdSet cookie" )
+ {
+ public void action( IAsn1Container container )
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ byte[] cookie = value.getData();
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "cookie = " + StringTools.dumpBytes( cookie ) );
+ }
+
+ syncInfoValueContainer.getSyncInfoValueControl().setCookie( cookie );
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+ }
+ } );
+
+
+ /**
+ * Transition from syncIdSet state to refreshDeletes
+ * syncIdSet [3] SEQUENCE {
+ * ...
+ * refreshDeletes BOOLEAN DEFAULT FALSE,
+ * ...
+ *
+ * Load the refreshDeletes flag
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.SYNC_ID_SET_STATE][UniversalTag.BOOLEAN_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.SYNC_ID_SET_STATE,
+ SyncInfoValueControlStatesEnum.SYNC_ID_SET_REFRESH_DELETES_STATE,
+ UniversalTag.BOOLEAN_TAG,
+ new GrammarAction( "SyncIdSet refreshDeletes" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ try
+ {
+ boolean refreshDeletes = BooleanDecoder.parse( value );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "refreshDeletes = {}", refreshDeletes );
+ }
+
+ control.setRefreshDeletes( refreshDeletes );
+
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+ }
+ catch ( BooleanDecoderException be )
+ {
+ String msg = "failed to decode the refreshDeletes flag for SyncInfoValueControl";
+ LOG.error( msg, be );
+ throw new DecoderException( msg );
+ }
+ }
+ } );
+
+
+ /**
+ * Transition from syncIdSet cookie state to refreshDeletes
+ * syncIdSet [3] SEQUENCE {
+ * ...
+ * refreshDeletes BOOLEAN DEFAULT FALSE,
+ * ...
+ *
+ * Load the refreshDeletes flag
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.SYNC_ID_SET_COOKIE_STATE][UniversalTag.BOOLEAN_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.SYNC_ID_SET_COOKIE_STATE,
+ SyncInfoValueControlStatesEnum.SYNC_ID_SET_REFRESH_DELETES_STATE,
+ UniversalTag.BOOLEAN_TAG,
+ new GrammarAction( "SyncIdSet refreshDeletes" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ try
+ {
+ boolean refreshDeletes = BooleanDecoder.parse( value );
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "refreshDeletes = {}", refreshDeletes );
+ }
+
+ control.setRefreshDeletes( refreshDeletes );
+
+ syncInfoValueContainer.setSyncInfoValueControl( control );
+ }
+ catch ( BooleanDecoderException be )
+ {
+ String msg = "failed to decode the refreshDeletes flag for SyncInfoValueControl";
+ LOG.error( msg, be );
+ throw new DecoderException( msg );
+ }
+ }
+ } );
+
+
+ /**
+ * Transition from syncIdSet state to syncUUIDs
+ * syncIdSet [3] SEQUENCE {
+ * ...
+ * syncUUIDs *SET OF* syncUUID
+ * }
+ *
+ * Initialize the UUID set : no action associated, except allowing a grammar end
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.SYNC_ID_SET_STATE][UniversalTag.SET_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.SYNC_ID_SET_STATE,
+ SyncInfoValueControlStatesEnum.SYNC_ID_SET_SET_OF_UUIDS_STATE,
+ UniversalTag.SET_TAG,
+ new GrammarAction( "SyncIdSet syncUUIDs" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from syncIdSet cookie state to syncUUIDs
+ * syncIdSet [3] SEQUENCE {
+ * ...
+ * syncUUIDs *SET OF* syncUUID
+ * }
+ *
+ * Initialize the UUID set : no action associated
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.SYNC_ID_SET_COOKIE_STATE][UniversalTag.SET_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.SYNC_ID_SET_COOKIE_STATE,
+ SyncInfoValueControlStatesEnum.SYNC_ID_SET_SET_OF_UUIDS_STATE,
+ UniversalTag.SET_TAG,
+ new GrammarAction( "SyncIdSet syncUUIDs" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from syncIdSet refreshDeletes state to syncUUIDs
+ * syncIdSet [3] SEQUENCE {
+ * ...
+ * syncUUIDs *SET OF* syncUUID
+ * }
+ *
+ * Initialize the UUID set : no action associated
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.SYNC_ID_SET_REFRESH_DELETES_STATE][UniversalTag.SET_TAG] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.SYNC_ID_SET_REFRESH_DELETES_STATE,
+ SyncInfoValueControlStatesEnum.SYNC_ID_SET_SET_OF_UUIDS_STATE,
+ UniversalTag.SET_TAG,
+ new GrammarAction( "SyncIdSet syncUUIDs" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from syncIdSet syncUUIDs to syncUUID
+ * syncIdSet [3] SEQUENCE {
+ * ...
+ * syncUUIDs SET OF *syncUUID*
+ * }
+ *
+ * Add the first UUID in the UUIDs list
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.SYNC_ID_SET_SET_OF_UUIDS_STATE][UniversalTag.OCTET_STRING] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.SYNC_ID_SET_SET_OF_UUIDS_STATE,
+ SyncInfoValueControlStatesEnum.SYNC_ID_SET_UUID_STATE,
+ UniversalTag.OCTET_STRING,
+ new GrammarAction( "SyncIdSet first UUID" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ byte[] uuid = value.getData();
+
+ // UUID must be exactly 16 bytes long
+ if ( ( uuid == null ) || ( uuid.length != 16 ) )
+ {
+ String msg = "Bad UUID value, its length is incorrect ( it should be 16 bytes long)";
+ LOG.error( msg );
+ throw new DecoderException( msg );
+ }
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "UUID = " + StringTools.dumpBytes( uuid ) );
+ }
+
+ // Store the UUID in the UUIDs list
+ control.getSyncUUIDs().add( uuid );
+
+ // We can have an END transition
+ syncInfoValueContainer.grammarEndAllowed( true );
+ }
+ } );
+
+
+ /**
+ * Transition from syncIdSet syncUUID to syncUUID
+ * syncIdSet [3] SEQUENCE {
+ * ...
+ * syncUUIDs SET OF *syncUUID*
+ * }
+ *
+ * Add a new UUID in the UUIDs list
+ */
+ super.transitions[SyncInfoValueControlStatesEnum.SYNC_ID_SET_UUID_STATE][UniversalTag.OCTET_STRING] =
+ new GrammarTransition( SyncInfoValueControlStatesEnum.SYNC_ID_SET_UUID_STATE,
+ SyncInfoValueControlStatesEnum.SYNC_ID_SET_UUID_STATE,
+ UniversalTag.OCTET_STRING,
+ new GrammarAction( "SyncIdSet UUID" )
+ {
+ public void action( IAsn1Container container ) throws DecoderException
+ {
+ SyncInfoValueControlContainer syncInfoValueContainer =
+ ( SyncInfoValueControlContainer ) container;
+ SyncInfoValueControlCodec control = syncInfoValueContainer.getSyncInfoValueControl();
+
+ Value value = syncInfoValueContainer.getCurrentTLV().getValue();
+
+ byte[] uuid = value.getData();
+
+ // UUID must be exactly 16 bytes long
+ if ( ( uuid == null ) || ( uuid.length != 16 ) )
+ {
+ String msg = "Bad UUID value, its length is incorrect ( it should be 16 bytes long)";
+ LOG.error( msg );
+ throw new DecoderException( msg );
+ }
+
+ if ( IS_DEBUG )
+ {
+ LOG.debug( "UUID = " + StringTools.dumpBytes( uuid ) );
+ }
+
+ // Store the UUID in the UUIDs list
+ control.getSyncUUIDs().add( uuid );
+
+ // We can have an END transition
+ syncInfoValueContainer.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/syncInfoValue/SyncInfoValueControlStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlStatesEnum.java?rev=742122&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlStatesEnum.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueControlStatesEnum.java Sun Feb 8 15:47:34 2009
@@ -0,0 +1,173 @@
+/*
+ * 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.syncInfoValue;
+
+
+import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
+import org.apache.directory.shared.asn1.ber.grammar.IStates;
+
+
+/**
+ * This class store the SyncInfoValueControl'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 SyncInfoValueControlStatesEnum implements IStates
+{
+ // ~ Static fields/initializers
+ // -----------------------------------------------------------------
+
+ // =========================================================================
+ // SyncRequestValue control grammar states
+ // =========================================================================
+ /** Initial state */
+ public static final int START_STATE = 0;
+
+ /** NewCookie state */
+ public static final int NEW_COOKIE_STATE = 1;
+
+ /** RefreshDelete state */
+ public static final int REFRESH_DELETE_STATE = 2;
+
+ /** RefreshDelete cookie state */
+ public static final int REFRESH_DELETE_COOKIE_STATE = 3;
+
+ /** RefreshDelete refreshDone state */
+ public static final int REFRESH_DELETE_REFRESH_DONE_STATE = 4;
+
+ /** RefreshPresent state */
+ public static final int REFRESH_PRESENT_STATE = 5;
+
+ /** RefreshPresent cookie state */
+ public static final int REFRESH_PRESENT_COOKIE_STATE = 6;
+
+ /** RefreshPresent refreshDone state */
+ public static final int REFRESH_PRESENT_REFRESH_DONE_STATE = 7;
+
+ /** SyncIdSet state */
+ public static final int SYNC_ID_SET_STATE = 8;
+
+ /** SyncIdSet cookie state */
+ public static final int SYNC_ID_SET_COOKIE_STATE = 9;
+
+ /** SyncIdSet refreshDone state */
+ public static final int SYNC_ID_SET_REFRESH_DELETES_STATE = 10;
+
+ /** SyncIdSet SET OF UUIDs state */
+ public static final int SYNC_ID_SET_SET_OF_UUIDS_STATE = 11;
+
+ /** SyncIdSet UUID state */
+ public static final int SYNC_ID_SET_UUID_STATE = 12;
+
+ /** terminal state */
+ public static final int LAST_SYNC_INFO_VALUE_STATE = 13;
+
+ // =========================================================================
+ // States debug strings
+ // =========================================================================
+ /** A string representation of all the states */
+ private static String[] syncInfoValueString = new String[]
+ {
+ "START_STATE",
+ "NEW_COOKIE_STATE",
+ "REFRESH_DELETE_STATE",
+ "REFRESH_DELETE_COOKIE_STATE",
+ "REFRESH_DELETE_REFRESH_DONE_STATE",
+ "REFRESH_PRESENT_STATE",
+ "REFRESH_PRESENT_COOKIE_STATE",
+ "REFRESH_PRESENT_REFRESH_DONE_STATE",
+ "SYNC_ID_SET_STATE",
+ "SYNC_ID_SET_COOKIE_STATE",
+ "SYNC_ID_SET_REFRESH_DELETES_STATE",
+ "SYNC_ID_SET_SET_OF_UUIDS_STATE",
+ "int SYNC_ID_SET_UUID_STATE"
+ };
+
+ /** The instance */
+ private static SyncInfoValueControlStatesEnum instance = new SyncInfoValueControlStatesEnum();
+
+
+ // ~ Constructors
+ // -------------------------------------------------------------------------------
+
+ /**
+ * This is a private constructor. This class is a singleton
+ */
+ private SyncInfoValueControlStatesEnum()
+ {
+ }
+
+
+ // ~ 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_INFO_VALUE_GRAMMAR";
+ }
+
+
+ /**
+ * Get the grammar name
+ *
+ * @param grammar The grammar class
+ * @return The grammar name
+ */
+ public String getGrammarName( IGrammar grammar )
+ {
+ if ( grammar instanceof SyncInfoValueControlGrammar )
+ {
+ return "SYNC_INFO_VALUE_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_INFO_VALUE_END_STATE" : syncInfoValueString[state] );
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueTags.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueTags.java?rev=742122&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueTags.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncInfoValue/SyncInfoValueTags.java Sun Feb 8 15:47:34 2009
@@ -0,0 +1,56 @@
+/*
+ * 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.syncInfoValue;
+
+/**
+ * An enumeration to store the tags used to encode and decode the syncInfoValue control.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev:$, $Date:
+ */
+public enum SyncInfoValueTags
+{
+ /** The tags */
+ NEW_COOKIE_TAG( 0x0080 ),
+ REFRESH_DELETE_TAG( 0x00A1 ),
+ REFRESH_PRESENT_TAG( 0x00A2 ),
+ SYNC_ID_SET_TAG( 0x00A3 );
+
+ /** Internal value for each tag */
+ private int value;
+
+ /**
+ * Create the private instance
+ * @param value The internal tag value
+ */
+ private SyncInfoValueTags( int value )
+ {
+ this.value = value;
+ }
+
+
+ /**
+ * @return The ASN.1 BER value for this tag.
+ */
+ public int getValue()
+ {
+ return value;
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueControl.java?rev=742122&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueControl.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueControl.java Sun Feb 8 15:47:34 2009
@@ -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;
+
+
+/**
+ * This interface is the base for the Sync Info Control, as described by RFC 4533.
+ * The structure for this control is :
+ *
+ * syncInfoValue ::= CHOICE {
+ * newcookie [0] syncCookie,
+ * refreshDelete [1] SEQUENCE {
+ * cookie syncCookie OPTIONAL,
+ * refreshDone BOOLEAN DEFAULT TRUE
+ * },
+ * refreshPresent [2] SEQUENCE {
+ * cookie syncCookie OPTIONAL,
+ * refreshDone BOOLEAN DEFAULT TRUE
+ * },
+ * syncIdSet [3] SEQUENCE {
+ * cookie syncCookie OPTIONAL,
+ * refreshDeletes BOOLEAN DEFAULT FALSE,
+ * syncUUIDs SET OF syncUUID
+ * }
+ * }
+ *
+ * This control OID is 1.3.6.1.4.1.4203.1.9.1.4
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc4533.html">RFC 4533</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ */
+public interface SyncInfoValueControl
+{
+ /** This control OID */
+ static final String CONTROL_OID = "1.3.6.1.4.1.4203.1.9.1.4";
+
+
+ /**
+ * @return the cookie
+ */
+ byte[] getCookie();
+
+
+ /**
+ * @param cookie the cookie to set
+ */
+ void setCookie( byte[] cookie );
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueNewCookieControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueNewCookieControl.java?rev=742122&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueNewCookieControl.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueNewCookieControl.java Sun Feb 8 15:47:34 2009
@@ -0,0 +1,91 @@
+/*
+ * 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;
+
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.controls.replication.syncInfoValue.SyncInfoValueControlCodec;
+import org.apache.directory.shared.ldap.message.control.AbstractMutableControlImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class implement the SyncInfoValue interface, and represent the first
+ * choice : newcookie.
+ * The structure for this control is :
+ *
+ * syncInfoValue ::= CHOICE {
+ * newcookie [0] syncCookie,
+ * ...
+ * }
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc4533.html">RFC 4533</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ *
+ */
+public class SyncInfoValueNewCookieControl extends AbstractMutableControlImpl implements SyncInfoValueControl
+{
+ /** As this class is serializable, defined its serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /** The Logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( SyncInfoValueNewCookieControl.class );
+
+ /** The new cookie */
+ private byte[] newCookie;
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getCookie()
+ {
+ return newCookie;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setCookie( byte[] newCookie )
+ {
+ this.newCookie = newCookie;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getEncodedValue()
+ {
+ SyncInfoValueControlCodec syncInfoValueCtlCodec = new SyncInfoValueControlCodec( SynchronizationInfoEnum.NEW_COOKIE );
+ syncInfoValueCtlCodec.setCookie( newCookie );
+
+ try
+ {
+ return syncInfoValueCtlCodec.encode( null ).array();
+ }
+ catch ( EncoderException e )
+ {
+ LOG.error( "Failed to encode syncInfoValue control", e );
+ throw new IllegalStateException( "Failed to encode control with encoder.", e );
+ }
+ }
+}
Propchange: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueNewCookieControl.java
------------------------------------------------------------------------------
svn:mergeinfo =
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueRefreshDeleteControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueRefreshDeleteControl.java?rev=742122&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueRefreshDeleteControl.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SyncInfoValueRefreshDeleteControl.java Sun Feb 8 15:47:34 2009
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.codec.controls.replication.syncInfoValue.SyncInfoValueControlCodec;
+import org.apache.directory.shared.ldap.message.control.AbstractMutableControlImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class implement the SyncInfoValue interface, and represent the second
+ * choice : refreshDelete.
+ * The structure for this control is :
+ *
+ * syncInfoValue ::= CHOICE {
+ * ...
+ * refreshDelete [1] SEQUENCE {
+ * cookie syncCookie OPTIONAL,
+ * refreshDone BOOLEAN DEFAULT TRUE
+ * },
+ * ...
+ * }
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc4533.html">RFC 4533</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ *
+ */
+public class SyncInfoValueRefreshDeleteControl extends AbstractMutableControlImpl implements SyncInfoValueControl
+{
+ /** As this class is serializable, defined its serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /** The Logger for this class */
+ private static final Logger LOG = LoggerFactory.getLogger( SyncInfoValueRefreshDeleteControl.class );
+
+ /** The cookie */
+ private byte[] cookie;
+
+
+ /** The refreshDone flag, default to true */
+ private boolean refreshDone = true;
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getCookie()
+ {
+ return cookie;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setCookie( byte[] cookie )
+ {
+ this.cookie = cookie;
+ }
+
+
+ /**
+ * @return the refreshDone
+ */
+ public boolean isRefreshDone()
+ {
+ return refreshDone;
+ }
+
+
+ /**
+ * @param refreshDone the refreshDone to set
+ */
+ public void setRefreshDone( boolean refreshDone )
+ {
+ this.refreshDone = refreshDone;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public byte[] getEncodedValue()
+ {
+ SyncInfoValueControlCodec syncInfoValueCtlCodec =
+ new SyncInfoValueControlCodec( SynchronizationInfoEnum.REFRESH_DELETE );
+ syncInfoValueCtlCodec.setCookie( cookie );
+
+ try
+ {
+ return syncInfoValueCtlCodec.encode( null ).array();
+ }
+ catch ( EncoderException e )
+ {
+ LOG.error( "Failed to encode syncInfoValue control", e );
+ throw new IllegalStateException( "Failed to encode control with encoder.", e );
+ }
+ }
+}
Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SynchronizationInfoEnum.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SynchronizationInfoEnum.java?rev=742122&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SynchronizationInfoEnum.java (added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/control/replication/SynchronizationInfoEnum.java Sun Feb 8 15:47:34 2009
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+/**
+ * This class describes the four possible Info values :
+ * <ul>
+ * <li>newcookie</li>
+ * <li>refreshDelete</li>
+ * <li>refreshpresent</li>
+ * <li>syncIdSet</li>
+ * </ul>
+ *
+ * @see <a href="http://www.faqs.org/rfcs/rfc4533.html">RFC 4533</a>
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $
+ *
+ */
+public enum SynchronizationInfoEnum
+{
+ NEW_COOKIE(0),
+ REFRESH_DELETE(1),
+ REFRESH_PRESENT(2),
+ SYNC_ID_SET(3);
+
+ /** The internal value */
+ private int value;
+
+
+ /**
+ * Private constructor so no other instances can be created other than the
+ * public static constants in this class.
+ *
+ * @param value the integer value of the enumeration.
+ */
+ private SynchronizationInfoEnum( int value )
+ {
+ this.value = value;
+ }
+
+
+ /**
+ * @return The value associated with the current element.
+ */
+ public int getValue()
+ {
+ return value;
+ }
+
+
+ /**
+ * Get the {@link SynchronizationInfoEnum} instance from an integer value.
+ *
+ * @param value The value we want the enum element from
+ * @return The enum element associated with this integer
+ */
+ public static SynchronizationInfoEnum getSyncMode( int value )
+ {
+ if ( value == NEW_COOKIE.getValue() )
+ {
+ return NEW_COOKIE;
+ }
+ else if ( value == REFRESH_DELETE.getValue() )
+ {
+ return REFRESH_DELETE;
+ }
+ else if ( value == REFRESH_PRESENT.getValue() )
+ {
+ return REFRESH_PRESENT;
+ }
+ else
+ {
+ return SYNC_ID_SET;
+ }
+ }
+}
|