directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r742026 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/ test/java/org/apache/directory/shared/ldap/codec/controls/replication/
Date Sun, 08 Feb 2009 08:48:43 GMT
Author: kayyagari
Date: Sun Feb  8 08:48:43 2009
New Revision: 742026

URL: http://svn.apache.org/viewvc?rev=742026&view=rev
Log:
o code for syncDoneValueControl

Added:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlContainer.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlDecoder.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlStatesEnum.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java?rev=742026&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java
Sun Feb  8 08:48:43 2009
@@ -0,0 +1,149 @@
+/*
+ *  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.syncDoneValue;
+
+
+import java.nio.ByteBuffer;
+
+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.util.StringTools;
+
+
+/**
+ * 
+ * A syncDoneValue object as described in rfc4533.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SyncDoneValueControlCodec extends AbstractAsn1Object
+{
+    /** The Sync cookie */
+    private byte[] cookie;
+
+    /** the refreshDeletes flag */
+    private boolean refreshDeletes;
+
+    /** The global length for this control */
+    private int syncDoneValueLength;
+
+
+    /**
+     * Compute the syncDoneValue length.
+     * 0x30 L1
+     * |
+     * +--> 0x04 L2 xkcd!!!...     (cookie)
+     * +--> 0x01 0x01 [0x00|0xFF]  (refreshDeletes)
+     */
+    @Override
+    public int computeLength()
+    {
+        // cookie's length
+        if ( cookie != null )
+        {
+            syncDoneValueLength = 1 + TLV.getNbBytes( cookie.length ) + cookie.length;
+        }
+
+        // the refreshDeletes flag length
+        syncDoneValueLength = 1 + 1 + 1;
+
+        return 1 + TLV.getNbBytes( syncDoneValueLength ) + syncDoneValueLength;
+    }
+
+
+    /**
+     * Encode the SyncDoneValue control
+     * 
+     * @param buffer The encoded sink
+     * @return A ByteBuffer that contains the encoded PDU
+     * @throws EncoderException If anything goes wrong while encoding.
+     */
+    @Override
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
+        bb.put( UniversalTag.SEQUENCE_TAG );
+        bb.put( TLV.getBytes( syncDoneValueLength ) );
+
+        if ( cookie != null )
+        {
+            Value.encode( bb, cookie );
+        }
+
+        Value.encode( bb, refreshDeletes );
+
+        return bb;
+    }
+
+
+    /**
+     * @return the cookie
+     */
+    public byte[] getCookie()
+    {
+        return cookie;
+    }
+
+
+    /**
+     * @param cookie cookie to be set
+     */
+    public void setCookie( byte[] cookie )
+    {
+        this.cookie = cookie;
+    }
+
+
+    /**
+     * @return true, if refreshDeletes flag is set, false otherwise
+     */
+    public boolean isRefreshDeletes()
+    {
+        return refreshDeletes;
+    }
+
+
+    /**
+     * @param refreshDeletes set the refreshDeletes flag 
+     */
+    public void setRefreshDeletes( boolean refreshDeletes )
+    {
+        this.refreshDeletes = refreshDeletes;
+    }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+
+        sb.append( "    SyncDoneValue control :\n" );
+        sb.append( "        cookie            : '" ).append( StringTools.dumpBytes( cookie
) ).append( "'\n" );
+        sb.append( "        refreshDeletes : '" ).append( refreshDeletes ).append( "'\n"
);
+
+        return sb.toString();
+    }
+}
\ No newline at end of file

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlContainer.java?rev=742026&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlContainer.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlContainer.java
Sun Feb  8 08:48:43 2009
@@ -0,0 +1,84 @@
+/*
+ *  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.syncDoneValue;
+
+
+import org.apache.directory.shared.asn1.ber.AbstractContainer;
+
+
+/**
+ * 
+ * ASN.1 container for SyncDoneValueControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SyncDoneValueControlContainer extends AbstractContainer
+{
+    /** syncDoneValue*/
+    private SyncDoneValueControlCodec control;
+
+
+    /**
+     * 
+     * Creates a new SyncDoneValueControlContainer object.
+     *
+     */
+    public SyncDoneValueControlContainer()
+    {
+        super();
+        stateStack = new int[1];
+        grammar = SyncDoneValueControlGrammar.getInstance();
+        states = SyncDoneValueControlStatesEnum.getInstance();
+    }
+
+
+    /**
+     * @return the SyncDoneValueControlCodec object
+     */
+    public SyncDoneValueControlCodec getSyncDoneValueControl()
+    {
+        return control;
+    }
+
+
+    /**
+     * Set a SyncDoneValueControlCodec Object into the container. It will be completed
+     * by the ldapDecoder.
+     * 
+     * @param control the SyncDoneValueControlCodec to set.
+     */
+    public void setSyncDoneValueControl( SyncDoneValueControlCodec control )
+    {
+        this.control = control;
+    }
+
+
+    /**
+     * clean the container
+     */
+    @Override
+    public void clean()
+    {
+        super.clean();
+        control = null;
+    }
+
+}

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlDecoder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlDecoder.java?rev=742026&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlDecoder.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlDecoder.java
Sun Feb  8 08:48:43 2009
@@ -0,0 +1,77 @@
+/*
+ *  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.syncDoneValue;
+
+
+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.ControlDecoder;
+
+
+/**
+ * 
+ * A ASN.1 decoder for SyncDoneValueControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SyncDoneValueControlDecoder extends Asn1Decoder implements ControlDecoder
+{
+
+    /** The syncDoneValueControl OID */
+    private final static String CONTROL_TYPE_OID = "1.3.6.1.4.1.4203.1.9.1.3";
+
+    /** An instance of this decoder */
+    private static final Asn1Decoder decoder = new Asn1Decoder();
+
+
+    /**
+     * Decode the syncDoneValueControl
+     * 
+     * @param controlBytes The bytes array which contains the encoded syncDoneValueControl
+     * 
+     * @return A valid SyncDoneValueControl 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 );
+        SyncDoneValueControlContainer container = new SyncDoneValueControlContainer();
+        decoder.decode( bb, container );
+        return container.getSyncDoneValueControl();
+    }
+
+
+    /**
+     * @return the syncDoneValueControl's OID
+     */
+    public String getControlType()
+    {
+        return CONTROL_TYPE_OID;
+    }
+
+}

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java?rev=742026&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java
Sun Feb  8 08:48:43 2009
@@ -0,0 +1,178 @@
+/*
+ *  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.syncDoneValue;
+
+
+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.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * 
+ * Implementation of SyncDoneValueControl. All the actions are declared in
+ * this class. As it is a singleton, these declaration are only done once.
+ *
+ *  The decoded grammar is as follows :
+ *  
+ *  syncDoneValue ::= SEQUENCE 
+ *  {
+ *       cookie          syncCookie OPTIONAL,
+ *       refreshDeletes  BOOLEAN DEFAULT FALSE
+ *  }
+ *  
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SyncDoneValueControlGrammar extends AbstractGrammar
+{
+
+    /** the logger */
+    private static final Logger LOG = LoggerFactory.getLogger( SyncDoneValueControlGrammar.class
);
+
+    /** speedup for logger */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** SyncDoneValueControlGrammar singleton instance */
+    private static final SyncDoneValueControlGrammar INSTANCE = new SyncDoneValueControlGrammar();
+
+
+    /**
+     * 
+     * Creates a new instance of SyncDoneValueControlGrammar.
+     *
+     */
+    private SyncDoneValueControlGrammar()
+    {
+        name = SyncDoneValueControlGrammar.class.getName();
+        statesEnum = SyncDoneValueControlStatesEnum.getInstance();
+
+        super.transitions = new GrammarTransition[SyncDoneValueControlStatesEnum.LAST_SYNC_DONE_VALUE_STATE][256];
+
+        /** 
+         * Transition from initial state to SyncDoneValue sequence
+         * SyncDoneValue ::= SEQUENCE {
+         *     ...
+         *     
+         * Initialize the syncDoneValue object
+         */
+        super.transitions[IStates.INIT_GRAMMAR_STATE][UniversalTag.SEQUENCE_TAG] = new GrammarTransition(
+            IStates.INIT_GRAMMAR_STATE, SyncDoneValueControlStatesEnum.SYNC_DONE_VALUE_SEQUENCE_STATE,
UniversalTag.SEQUENCE_TAG,
+            new GrammarAction( "Init SyncDoneValueControl" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+                    SyncDoneValueControlContainer syncDoneValueContainer = ( SyncDoneValueControlContainer
) container;
+                    SyncDoneValueControlCodec control = new SyncDoneValueControlCodec();
+                    syncDoneValueContainer.setSyncDoneValueControl( control );
+                }
+            } );
+
+        /**
+         * transition from start to cookie
+         * {
+         *    cookie          syncCookie OPTIONAL
+         *    ....
+         * }
+         */
+        super.transitions[SyncDoneValueControlStatesEnum.SYNC_DONE_VALUE_SEQUENCE_STATE][UniversalTag.OCTET_STRING_TAG]
= new GrammarTransition(
+            SyncDoneValueControlStatesEnum.SYNC_DONE_VALUE_SEQUENCE_STATE, SyncDoneValueControlStatesEnum.COOKIE_STATE,
+            UniversalTag.OCTET_STRING_TAG, new GrammarAction( "Set SyncDoneValueControl cookie"
)
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+                    SyncDoneValueControlContainer syncDoneValueContainer = ( SyncDoneValueControlContainer
) container;
+                    Value value = syncDoneValueContainer.getCurrentTLV().getValue();
+
+                    byte[] cookie = value.getData();
+
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "cookie = {}", StringTools.dumpBytes( cookie ) );
+                    }
+
+                    syncDoneValueContainer.getSyncDoneValueControl().setCookie( cookie );
+
+                    // there is still a boolean flag left in the sequence
+                    syncDoneValueContainer.grammarEndAllowed( false );
+                }
+            } );
+
+        /**
+         * transition from cookie
+         * {
+         *    ....
+         *    refreshDeletes BOOLEAN DEFAULT FALSE
+         * }
+         */
+        super.transitions[SyncDoneValueControlStatesEnum.COOKIE_STATE][UniversalTag.BOOLEAN_TAG]
= new GrammarTransition(
+            SyncDoneValueControlStatesEnum.COOKIE_STATE, SyncDoneValueControlStatesEnum.REFRESH_DELETES_STATE,
+            UniversalTag.BOOLEAN_TAG, new GrammarAction( "set SyncDoneValueControl refreshDeletes
flag" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+                    SyncDoneValueControlContainer syncDoneValueContainer = ( SyncDoneValueControlContainer
) container;
+                    Value value = syncDoneValueContainer.getCurrentTLV().getValue();
+
+                    try
+                    {
+                        boolean refreshDeletes = BooleanDecoder.parse( value );
+
+                        if ( IS_DEBUG )
+                        {
+                            LOG.debug( "refreshDeletes = {}", refreshDeletes );
+                        }
+
+                        syncDoneValueContainer.getSyncDoneValueControl().setRefreshDeletes(
refreshDeletes );
+
+                        // the END transition for grammar
+                        syncDoneValueContainer.grammarEndAllowed( true );
+                    }
+                    catch ( BooleanDecoderException be )
+                    {
+                        String msg = "failed to decode the refreshDeletes flag for SyncDoneValueControl";
+                        LOG.error( msg, be );
+                        throw new DecoderException( msg );
+                    }
+
+                }
+            } );
+    }
+
+
+    /**
+     * @return the singleton instance of the SyncDoneValueControlGrammar
+     */
+    public static IGrammar getInstance()
+    {
+        return INSTANCE;
+    }
+}

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlStatesEnum.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlStatesEnum.java?rev=742026&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlStatesEnum.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlStatesEnum.java
Sun Feb  8 08:48:43 2009
@@ -0,0 +1,114 @@
+/*
+ *  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.syncDoneValue;
+
+import org.apache.directory.shared.asn1.ber.grammar.IGrammar;
+import org.apache.directory.shared.asn1.ber.grammar.IStates;
+
+/**
+ * 
+ * ASN.1 grammer constants of SyncDoneValueControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SyncDoneValueControlStatesEnum implements IStates
+{
+    /***/
+    public static final int START_STATE = 0;
+    
+    /** sequence start state */
+    public static final int SYNC_DONE_VALUE_SEQUENCE_STATE = 1;
+    
+    /** cookie value state */
+    public static final int COOKIE_STATE = 2;
+    
+    /** refreshDeletes value state */
+    public static final int REFRESH_DELETES_STATE = 3;
+    
+    /** terminal state */
+    public static final int LAST_SYNC_DONE_VALUE_STATE = 4;
+    
+    public static String[] syncDoneValueString = new String[]
+       {
+       "START_STATE",
+       "SYNC_DONE_VALUE_SEQUENCE_STATE",
+       "COOKIE_STATE",
+       "REFRESH_DELETES_STATE",
+       };
+    
+    private static SyncDoneValueControlStatesEnum instance = new SyncDoneValueControlStatesEnum();
+    
+    private SyncDoneValueControlStatesEnum()
+    {
+    }
+    
+    /**
+     * 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_DONE_VALUE_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( IGrammar grammar )
+    {
+        if ( grammar instanceof SyncDoneValueControlGrammar )
+        {
+            return "SYNC_DONE_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_DONE_VALUE_GRAMMAR" : syncDoneValueString[state]
);
+    }
+    
+}

Added: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java?rev=742026&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java
(added)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java
Sun Feb  8 08:48:43 2009
@@ -0,0 +1,104 @@
+/*
+ *  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.*;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlCodec;
+import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlContainer;
+import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlDecoder;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+
+
+/**
+ * 
+ * TestCase for SyncDoneValueControlCodec .
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SyncDoneValueControlTest
+{
+
+    @Test
+    public void testSyncDoneValueControl()
+    {
+        Asn1Decoder decoder = new SyncDoneValueControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 11 );
+
+        bb.put( new byte[]
+            { 0x30, 0x09, 0x04, 0x04, 'x', 'k', 'c', 'd', // the cookie 
+                0x01, 0x01, 0x01 // refreshDeletes flag TRUE
+            } );
+
+        bb.flip();
+
+        SyncDoneValueControlContainer container = new SyncDoneValueControlContainer();
+
+        try
+        {
+            decoder.decode( bb, container );
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        SyncDoneValueControlCodec control = container.getSyncDoneValueControl();
+        assertEquals( "xkcd", StringTools.utf8ToString( control.getCookie() ) );
+        assertTrue( control.isRefreshDeletes() );
+    }
+
+
+    @Test
+    public void testSyncDoneValueControlWithoutCookie()
+    {
+        Asn1Decoder decoder = new SyncDoneValueControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 7 );
+
+        bb.put( new byte[]
+            { 0x30, 0x05, 0x04, 0x00, // null cookie
+                0x01, 0x01, 0x00 // refreshDeletes flag FALSE
+            } );
+
+        bb.flip();
+
+        SyncDoneValueControlContainer container = new SyncDoneValueControlContainer();
+
+        try
+        {
+            decoder.decode( bb, container );
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        SyncDoneValueControlCodec control = container.getSyncDoneValueControl();
+        assertNull( control.getCookie() );
+        assertFalse( control.isRefreshDeletes() );
+    }
+
+}



Mime
View raw message