directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1553092 - in /directory/shared/trunk/ldap: codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/ codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/ model/src/main/java/org/apache/directory/api/ldap/mod...
Date Mon, 23 Dec 2013 10:43:10 GMT
Author: kayyagari
Date: Mon Dec 23 10:43:10 2013
New Revision: 1553092

URL: http://svn.apache.org/r1553092
Log:
codec for server side sort control as specified in RFC 2891 (DIRAPI-137)

Added:
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestContainer.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestDecorator.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestFactory.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestGrammar.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestStates.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseContainer.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseDecorator.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseFactory.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseGrammar.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseStates.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/StoreSortResponseResultCode.java
    directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/
    directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/SortRequestControlTest.java
    directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/SortResponseControlTest.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequestControl.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequestControlImpl.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResponseControl.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResponseControlImpl.java
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResultCode.java
Modified:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortKey.java

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestContainer.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestContainer.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestContainer.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,133 @@
+/*
+ *   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.api.ldap.codec.controls.sort;
+
+
+import org.apache.directory.api.asn1.ber.AbstractContainer;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.model.message.controls.SortKey;
+import org.apache.directory.api.ldap.model.message.controls.SortRequestControl;
+
+
+/**
+ * Container for SortRequestControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SortRequestContainer extends AbstractContainer
+{
+    /** the sort request control decorator */
+    private SortRequestDecorator control;
+
+    /** the LDAP codec */
+    private LdapApiService codec;
+
+    /** current key that is being decoded */
+    private SortKey currentKey;
+
+    /**
+     * Creates a new instance of SortRequestContainer.
+     *
+     * @param codec the LDAP codec
+     */
+    public SortRequestContainer( LdapApiService codec )
+    {
+        super();
+        this.codec = codec;
+        grammar = SortRequestGrammar.getInstance();
+        setTransition( SortRequestStates.START_STATE );
+    }
+
+
+    /**
+     * Creates a new instance of SortRequestContainer.
+     *
+     * @param codec the LDAP codec
+     * @param control the sort request control
+     */
+    public SortRequestContainer( LdapApiService codec, SortRequestControl control )
+    {
+        this( codec );
+        decorate( control );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void decorate( SortRequestControl control )
+    {
+        if ( control instanceof SortRequestDecorator )
+        {
+            this.control = ( SortRequestDecorator ) control;
+        }
+        else
+        {
+            this.control = new SortRequestDecorator( codec, control );
+        }
+    }
+
+
+    /**
+     * @return the control
+     */
+    public SortRequestDecorator getControl()
+    {
+        return control;
+    }
+
+
+    /**
+     * @param control the control to set
+     */
+    public void setControl( SortRequestDecorator control )
+    {
+        this.control = control;
+    }
+
+
+    /**
+     * Clean the container
+     */
+    public void clean()
+    {
+        super.clean();
+        control = null;
+    }
+
+
+    /**
+     * @return the currentKey
+     */
+    public SortKey getCurrentKey()
+    {
+        return currentKey;
+    }
+
+
+    /**
+     * @param currentKey the currentKey to set
+     */
+    public void setCurrentKey( SortKey currentKey )
+    {
+        this.currentKey = currentKey;
+    }
+    
+}

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestDecorator.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestDecorator.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestDecorator.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,207 @@
+/*
+ *   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.api.ldap.codec.controls.sort;
+
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.api.asn1.Asn1Object;
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.ber.tlv.TLV;
+import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.codec.api.ControlDecorator;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.model.message.controls.SortKey;
+import org.apache.directory.api.ldap.model.message.controls.SortRequestControl;
+import org.apache.directory.api.ldap.model.message.controls.SortRequestControlImpl;
+import org.apache.directory.api.util.Strings;
+
+
+/**
+ * Decorator of SortRequestControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SortRequestDecorator extends ControlDecorator<SortRequestControl> implements SortRequestControl
+{
+    private Asn1Decoder decoder = new Asn1Decoder();
+
+    private int sortReqLen = 0;
+
+    private List<Integer> sortKeyLenList = new ArrayList<Integer>();
+
+
+    /**
+     * Creates a new instance of SortRequestDecorator.
+     *
+     * @param codec the LDAP codec
+     */
+    public SortRequestDecorator( LdapApiService codec )
+    {
+        super( codec, new SortRequestControlImpl() );
+    }
+
+
+    /**
+     * Creates a new instance of SortRequestDecorator.
+     *
+     * @param codec the LDAP codec
+     * @param control the control instance
+     */
+    public SortRequestDecorator( LdapApiService codec, SortRequestControl control )
+    {
+        super( codec, control );
+    }
+
+
+    /**
+     * 
+     */
+    @Override
+    public int computeLength()
+    {
+        sortReqLen = 0;
+        sortKeyLenList.clear();
+        valueLength = 0;
+
+        for ( SortKey sk : getSortKeys() )
+        {
+            int skLen = 0;
+
+            byte[] atBytes = Strings.getBytesUtf8( sk.getAttributeTypeDesc() );
+            skLen += 1 + TLV.getNbBytes( atBytes.length ) + atBytes.length;
+
+            if ( sk.getMatchingRuleId() != null )
+            {
+                byte[] mrBytes = Strings.getBytesUtf8( sk.getMatchingRuleId() );
+                skLen += 1 + TLV.getNbBytes( mrBytes.length ) + mrBytes.length;
+            }
+
+            // reverse order flag
+            skLen += 1 + 1 + 1;
+
+            sortKeyLenList.add( skLen );
+
+            // the sequence
+            sortReqLen += 1 + TLV.getNbBytes( skLen ) + skLen;
+        }
+
+        valueLength = 1 + TLV.getNbBytes( sortReqLen ) + sortReqLen;
+
+        return valueLength;
+    }
+
+
+    @Override
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
+        }
+
+        buffer.put( UniversalTag.SEQUENCE.getValue() );
+        buffer.put( TLV.getBytes( sortReqLen ) );
+
+        List<SortKey> lst = getSortKeys();
+
+        for ( int i = 0; i < lst.size(); i++ )
+        {
+            SortKey sk = lst.get( i );
+            int skLen = sortKeyLenList.get( i );
+
+            buffer.put( UniversalTag.SEQUENCE.getValue() );
+            buffer.put( TLV.getBytes( skLen ) );
+
+            BerValue.encode( buffer, sk.getAttributeTypeDesc() );
+
+            if ( sk.getMatchingRuleId() != null )
+            {
+                BerValue.encode( buffer, sk.getMatchingRuleId() );
+            }
+
+            BerValue.encode( buffer, sk.isReverseOrder() );
+        }
+
+        return buffer;
+    }
+
+
+    @Override
+    public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+    {
+        ByteBuffer buffer = ByteBuffer.wrap( controlBytes );
+        SortRequestContainer container = new SortRequestContainer( getCodecService(), this );
+        decoder.decode( buffer, container );
+        return this;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public byte[] getValue()
+    {
+        if ( value == null )
+        {
+            try
+            {
+                computeLength();
+                ByteBuffer buffer = ByteBuffer.allocate( valueLength );
+
+                value = encode( buffer ).array();
+            }
+            catch ( Exception e )
+            {
+                return null;
+            }
+        }
+
+        return value;
+    }
+
+
+    @Override
+    public void setSortKeys( List<SortKey> sortKeys )
+    {
+        getDecorated().setSortKeys( sortKeys );
+    }
+
+
+    @Override
+    public List<SortKey> getSortKeys()
+    {
+        return getDecorated().getSortKeys();
+    }
+
+
+    @Override
+    public void addSortKey( SortKey sortKey )
+    {
+        getDecorated().addSortKey( sortKey );
+    }
+
+}

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestFactory.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestFactory.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestFactory.java Mon Dec 23 10:43:10 2013
@@ -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.api.ldap.codec.controls.sort;
+
+
+import org.apache.directory.api.ldap.codec.api.ControlFactory;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.model.message.controls.PagedResults;
+import org.apache.directory.api.ldap.model.message.controls.SortRequestControl;
+
+
+/**
+ * A {@link ControlFactory} for SortRequestControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SortRequestFactory implements ControlFactory<SortRequestControl, SortRequestDecorator>
+{
+    /** The LDAP codec service */
+    private LdapApiService codec;
+
+
+    /**
+     * Creates a new instance of SortRequestFactory.
+     *
+     * @param codec The LDAP codec.
+     */
+    public SortRequestFactory( LdapApiService codec )
+    {
+        this.codec = codec;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getOid()
+    {
+        return PagedResults.OID;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public SortRequestDecorator newCodecControl()
+    {
+        return new SortRequestDecorator( codec );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public SortRequestDecorator newCodecControl( SortRequestControl control )
+    {
+        return new SortRequestDecorator( codec, control );
+    }
+}

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestGrammar.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestGrammar.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestGrammar.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,177 @@
+/*
+ *   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.api.ldap.codec.controls.sort;
+
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
+import org.apache.directory.api.asn1.ber.grammar.Grammar;
+import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.ber.tlv.BooleanDecoder;
+import org.apache.directory.api.asn1.ber.tlv.BooleanDecoderException;
+import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.api.ldap.model.message.controls.SortKey;
+import org.apache.directory.api.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Grammar used for decoding a SortRequestControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SortRequestGrammar extends AbstractGrammar<SortRequestContainer>
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( SortRequestGrammar.class );
+
+    /** Speedup for logs */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. SortRequestGrammar is a singleton */
+    private static Grammar<?> instance = new SortRequestGrammar();
+
+
+    private SortRequestGrammar()
+    {
+        setName( SortRequestGrammar.class.getName() );
+
+        GrammarAction<SortRequestContainer> addSortKey = new GrammarAction<SortRequestContainer>()
+        {
+
+            @Override
+            public void action( SortRequestContainer container ) throws DecoderException
+            {
+                BerValue value = container.getCurrentTLV().getValue();
+
+                String atDesc = Strings.utf8ToString( value.getData() );
+                if ( IS_DEBUG )
+                {
+                    LOG.debug( "AttributeTypeDesc = " + atDesc );
+                }
+                
+                SortKey sk = new SortKey( atDesc );
+                container.setCurrentKey( sk );
+                container.getControl().addSortKey( sk );
+            }
+
+        };
+
+        GrammarAction<SortRequestContainer> storeReverseOrder = new GrammarAction<SortRequestContainer>()
+        {
+
+            @Override
+            public void action( SortRequestContainer container ) throws DecoderException
+            {
+                BerValue value = container.getCurrentTLV().getValue();
+
+                try
+                {
+                    boolean reverseOrder = BooleanDecoder.parse( value );
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "ReverseOrder = " + reverseOrder );
+                    }
+                    
+                    container.getCurrentKey().setReverseOrder( reverseOrder );
+                    
+                    container.setGrammarEndAllowed( true );
+                }
+                catch ( BooleanDecoderException e )
+                {
+                    //String msg = I18n.err( I18n.ERR_04050 );
+                    //LOG.error( msg, e );
+                    throw new DecoderException( e.getMessage() );
+                }
+            }
+
+        };
+        
+        // Create the transitions table
+        super.transitions = new GrammarTransition[SortRequestStates.END_STATE.ordinal()][256];
+
+        super.transitions[SortRequestStates.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
+            new GrammarTransition<SortRequestContainer>( SortRequestStates.START_STATE,
+                SortRequestStates.SEQUENCE_OF_SEQUENCE_STATE,
+                UniversalTag.SEQUENCE.getValue(), null );
+
+        super.transitions[SortRequestStates.SEQUENCE_OF_SEQUENCE_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
+            new GrammarTransition<SortRequestContainer>( SortRequestStates.SEQUENCE_OF_SEQUENCE_STATE,
+                SortRequestStates.SORT_KEY_SEQUENCE_STATE,
+                UniversalTag.SEQUENCE.getValue(), null );
+
+        super.transitions[SortRequestStates.SORT_KEY_SEQUENCE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
+            new GrammarTransition<SortRequestContainer>( SortRequestStates.SORT_KEY_SEQUENCE_STATE,
+                SortRequestStates.AT_DESC_STATE,
+                UniversalTag.OCTET_STRING.getValue(), addSortKey );
+        
+        super.transitions[SortRequestStates.AT_DESC_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
+            new GrammarTransition<SortRequestContainer>( SortRequestStates.AT_DESC_STATE,
+                SortRequestStates.ORDER_RULE_STATE,
+                UniversalTag.OCTET_STRING.getValue(), new GrammarAction<SortRequestContainer>()
+                {
+
+                    @Override
+                    public void action( SortRequestContainer container ) throws DecoderException
+                    {
+                        BerValue value = container.getCurrentTLV().getValue();
+
+                        String matchingRuleOid = Strings.utf8ToString( value.getData() );
+                        if ( IS_DEBUG )
+                        {
+                            LOG.debug( "MatchingRuleOid = " + matchingRuleOid );
+                        }
+                        
+                        container.getCurrentKey().setMatchingRuleId( matchingRuleOid );
+                    }
+
+                } );
+        
+        super.transitions[SortRequestStates.ORDER_RULE_STATE.ordinal()][UniversalTag.BOOLEAN.getValue()] =
+            new GrammarTransition<SortRequestContainer>( SortRequestStates.ORDER_RULE_STATE,
+                SortRequestStates.REVERSE_ORDER_STATE,
+                UniversalTag.BOOLEAN.getValue(), storeReverseOrder );
+        
+        super.transitions[SortRequestStates.AT_DESC_STATE.ordinal()][UniversalTag.BOOLEAN.getValue()] =
+            new GrammarTransition<SortRequestContainer>( SortRequestStates.AT_DESC_STATE,
+                SortRequestStates.REVERSE_ORDER_STATE,
+                UniversalTag.BOOLEAN.getValue(), storeReverseOrder );
+
+        super.transitions[SortRequestStates.REVERSE_ORDER_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
+            new GrammarTransition<SortRequestContainer>( SortRequestStates.REVERSE_ORDER_STATE,
+                SortRequestStates.SORT_KEY_SEQUENCE_STATE,
+                UniversalTag.SEQUENCE.getValue(), null );
+
+    }
+
+
+    /**
+     * This class is a singleton.
+     * 
+     * @return An instance on this grammar
+     */
+    public static Grammar<?> getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestStates.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestStates.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestStates.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestStates.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,102 @@
+/*
+ *   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.api.ldap.codec.controls.sort;
+
+
+import org.apache.directory.api.asn1.ber.grammar.Grammar;
+import org.apache.directory.api.asn1.ber.grammar.States;
+
+
+/**
+ * Codec states for SortRequestControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum SortRequestStates implements States
+{
+    START_STATE,
+
+    SEQUENCE_OF_SEQUENCE_STATE,
+    
+    SORT_KEY_SEQUENCE_STATE,
+
+    AT_DESC_STATE,
+
+    ORDER_RULE_STATE,
+
+    REVERSE_ORDER_STATE,
+
+    END_STATE;
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "SORT_REQUEST_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar<?> grammar )
+    {
+        if ( grammar instanceof SortRequestGrammar )
+        {
+            return "SORT_REQUEST_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 == END_STATE.ordinal() ) ? "SORT_REQUEST_END_STATE" : name() );
+    }
+
+
+    @Override
+    public boolean isEndState()
+    {
+        return ( this == END_STATE );
+    }
+
+
+    @Override
+    public Enum<?> getStartState()
+    {
+        return START_STATE;
+    }
+
+}

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseContainer.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseContainer.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseContainer.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,111 @@
+/*
+ *   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.api.ldap.codec.controls.sort;
+
+
+import org.apache.directory.api.asn1.ber.AbstractContainer;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.model.message.controls.SortResponseControl;
+
+
+/**
+ * Container for SortResponseControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SortResponseContainer extends AbstractContainer
+{
+    /** the decorator instance of sort response control */
+    private SortResponseDecorator control;
+
+    /** LDAP codec */
+    private LdapApiService codec;
+
+    /**
+     * Creates a new instance of SortResponseContainer.
+     *
+     * @param codec the LDAP codec
+     */
+    public SortResponseContainer( LdapApiService codec )
+    {
+        super();
+        this.codec = codec;
+        grammar = SortResponseGrammar.getInstance();
+        setTransition( SortResponseStates.START_STATE );
+    }
+
+
+    /**
+     * Creates a new instance of SortResponseContainer.
+     *
+     * @param codec the LDAP codec
+     * @param control the sort response control
+     */
+    public SortResponseContainer( LdapApiService codec, SortResponseControl control )
+    {
+        this( codec );
+        decorate( control );
+    }
+
+
+    /**
+     * {@inheritDoc} 
+     */
+    public void decorate( SortResponseControl control )
+    {
+        if ( control instanceof SortResponseDecorator )
+        {
+            this.control = ( SortResponseDecorator ) control;
+        }
+        else
+        {
+            this.control = new SortResponseDecorator( codec, control );
+        }
+    }
+
+
+    /**
+     * @return the control
+     */
+    public SortResponseDecorator getControl()
+    {
+        return control;
+    }
+
+
+    /**
+     * @param control the control to set
+     */
+    public void setControl( SortResponseDecorator control )
+    {
+        this.control = control;
+    }
+
+
+    /**
+     * Clean the container
+     */
+    public void clean()
+    {
+        super.clean();
+        control = null;
+    }
+
+}

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseDecorator.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseDecorator.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseDecorator.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,186 @@
+/*
+ *   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.api.ldap.codec.controls.sort;
+
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.api.asn1.Asn1Object;
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.EncoderException;
+import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.ber.tlv.TLV;
+import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.api.i18n.I18n;
+import org.apache.directory.api.ldap.codec.api.ControlDecorator;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.model.message.controls.SortResponseControl;
+import org.apache.directory.api.ldap.model.message.controls.SortResponseControlImpl;
+import org.apache.directory.api.ldap.model.message.controls.SortResultCode;
+import org.apache.directory.api.util.Strings;
+
+
+/**
+ * Decorator class for SortResponseControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SortResponseDecorator extends ControlDecorator<SortResponseControl> implements SortResponseControl
+{
+    private Asn1Decoder decoder = new Asn1Decoder();
+
+    private int sortRespLen = 0;
+
+
+    /**
+     * Creates a new instance of SortResponseDecorator.
+     *
+     * @param codec the LDAP codec
+     */
+    public SortResponseDecorator( LdapApiService codec )
+    {
+        super( codec, new SortResponseControlImpl() );
+    }
+
+
+    /**
+     * Creates a new instance of SortResponseDecorator.
+     *
+     * @param codec the LDAP codec
+     * @param control the sort response control
+     */
+    public SortResponseDecorator( LdapApiService codec, SortResponseControl control )
+    {
+        super( codec, control );
+    }
+
+
+    /**
+     * 
+     */
+    @Override
+    public int computeLength()
+    {
+        sortRespLen = 0;
+        valueLength = 0;
+
+        // result code value
+        sortRespLen += 1 + 1 + 1;
+        
+        if( getAttibuteName() != null )
+        {
+            byte[] data = Strings.getBytesUtf8( getAttibuteName() );
+            sortRespLen += 1 + TLV.getNbBytes( data.length ) + data.length;
+        }
+        
+        valueLength = 1 + TLV.getNbBytes( sortRespLen ) + sortRespLen;
+
+        return valueLength;
+    }
+
+
+    @Override
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04023 ) );
+        }
+
+        buffer.put( UniversalTag.SEQUENCE.getValue() );
+        buffer.put( TLV.getBytes( sortRespLen ) );
+        
+        BerValue.encodeEnumerated( buffer, getSortResult().getVal() );
+        
+        if( getAttibuteName() != null )
+        {
+            BerValue.encode( buffer, getAttibuteName() );
+        }
+        
+        return buffer;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Asn1Object decode( byte[] controlBytes ) throws DecoderException
+    {
+        ByteBuffer buffer = ByteBuffer.wrap( controlBytes );
+        SortResponseContainer container = new SortResponseContainer( getCodecService(), this );
+        decoder.decode( buffer, container );
+        return this;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public byte[] getValue()
+    {
+        if ( value == null )
+        {
+            try
+            {
+                computeLength();
+                ByteBuffer buffer = ByteBuffer.allocate( valueLength );
+
+                value = encode( buffer ).array();
+            }
+            catch ( Exception e )
+            {
+                return null;
+            }
+        }
+
+        return value;
+    }
+
+
+    @Override
+    public void setSortResult( SortResultCode result )
+    {
+        getDecorated().setSortResult( result );
+    }
+
+
+    @Override
+    public SortResultCode getSortResult()
+    {
+        return getDecorated().getSortResult();
+    }
+
+
+    @Override
+    public void setAttibuteName( String attributeName )
+    {
+        getDecorated().setAttibuteName( attributeName );
+    }
+
+
+    @Override
+    public String getAttibuteName()
+    {
+        return getDecorated().getAttibuteName();
+    }
+
+}

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseFactory.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseFactory.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseFactory.java Mon Dec 23 10:43:10 2013
@@ -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.api.ldap.codec.controls.sort;
+
+
+import org.apache.directory.api.ldap.codec.api.ControlFactory;
+import org.apache.directory.api.ldap.codec.api.LdapApiService;
+import org.apache.directory.api.ldap.model.message.controls.PagedResults;
+import org.apache.directory.api.ldap.model.message.controls.SortResponseControl;
+
+
+/**
+ * A {@link ControlFactory} for SortResponseControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SortResponseFactory implements ControlFactory<SortResponseControl, SortResponseDecorator>
+{
+    /** The LDAP codec service */
+    private LdapApiService codec;
+
+
+    /**
+     * Creates a new instance of SortResponseFactory.
+     *
+     * @param codec The LDAP codec.
+     */
+    public SortResponseFactory( LdapApiService codec )
+    {
+        this.codec = codec;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getOid()
+    {
+        return PagedResults.OID;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public SortResponseDecorator newCodecControl()
+    {
+        return new SortResponseDecorator( codec );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public SortResponseDecorator newCodecControl( SortResponseControl control )
+    {
+        return new SortResponseDecorator( codec, control );
+    }
+}

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseGrammar.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseGrammar.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseGrammar.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,103 @@
+/*
+ *   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.api.ldap.codec.controls.sort;
+
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
+import org.apache.directory.api.asn1.ber.grammar.Grammar;
+import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
+import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.api.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Grammar for decoding SortResponseControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SortResponseGrammar extends AbstractGrammar<SortResponseContainer>
+{
+    /** The logger */
+    static final Logger LOG = LoggerFactory.getLogger( SortRequestGrammar.class );
+
+    /** Speedup for logs */
+    static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /** The instance of grammar. SortResponseGrammar is a singleton */
+    private static Grammar<?> instance = new SortResponseGrammar();
+
+
+    private SortResponseGrammar()
+    {
+        setName( SortResponseGrammar.class.getName() );
+
+        // Create the transitions table
+        super.transitions = new GrammarTransition[SortResponseStates.END_STATE.ordinal()][256];
+
+        super.transitions[SortResponseStates.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
+            new GrammarTransition<SortResponseContainer>( SortResponseStates.START_STATE,
+                SortResponseStates.SEQUENCE_STATE,
+                UniversalTag.SEQUENCE.getValue(), null );
+        
+        super.transitions[SortResponseStates.SEQUENCE_STATE.ordinal()][UniversalTag.ENUMERATED.getValue()] =
+            new GrammarTransition<SortResponseContainer>( SortResponseStates.SEQUENCE_STATE,
+                SortResponseStates.RESULT_CODE_STATE,
+                UniversalTag.ENUMERATED.getValue(), new StoreSortResponseResultCode<SortResponseContainer>() );
+
+        super.transitions[SortResponseStates.RESULT_CODE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
+            new GrammarTransition<SortResponseContainer>( SortResponseStates.RESULT_CODE_STATE,
+                SortResponseStates.AT_DESC_STATE,
+                UniversalTag.OCTET_STRING.getValue(), new GrammarAction<SortResponseContainer>()
+                {
+
+                    @Override
+                    public void action( SortResponseContainer container ) throws DecoderException
+                    {
+                        BerValue value = container.getCurrentTLV().getValue();
+
+                        String atType = Strings.utf8ToString( value.getData() );
+                        if ( IS_DEBUG )
+                        {
+                            LOG.debug( "AttributeType = " + atType );
+                        }
+                        
+                        container.getControl().setAttibuteName( atType );
+                        container.setGrammarEndAllowed( true );
+                    }
+                } );
+
+    }
+
+
+    /**
+     * This class is a singleton.
+     * 
+     * @return An instance on this grammar
+     */
+    public static Grammar<?> getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseStates.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseStates.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseStates.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseStates.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,98 @@
+/*
+ *   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.api.ldap.codec.controls.sort;
+
+
+import org.apache.directory.api.asn1.ber.grammar.Grammar;
+import org.apache.directory.api.asn1.ber.grammar.States;
+
+
+/**
+ * Enumeration of states encountered while decoding a SortResponseControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum SortResponseStates implements States
+{
+    START_STATE,
+
+    SEQUENCE_STATE,
+
+    RESULT_CODE_STATE,
+    
+    AT_DESC_STATE,
+
+    END_STATE;
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar code
+     * @return The grammar name
+     */
+    public String getGrammarName( int grammar )
+    {
+        return "SORT_RESPONSE_GRAMMAR";
+    }
+
+
+    /**
+     * Get the grammar name
+     * 
+     * @param grammar The grammar class
+     * @return The grammar name
+     */
+    public String getGrammarName( Grammar<?> grammar )
+    {
+        if ( grammar instanceof SortResponseGrammar )
+        {
+            return "SORT_RESPONSE_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 == END_STATE.ordinal() ) ? "SORT_REQUEST_END_STATE" : name() );
+    }
+
+
+    @Override
+    public boolean isEndState()
+    {
+        return ( this == END_STATE );
+    }
+
+
+    @Override
+    public Enum<?> getStartState()
+    {
+        return START_STATE;
+    }
+
+}

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/StoreSortResponseResultCode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/StoreSortResponseResultCode.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/StoreSortResponseResultCode.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/StoreSortResponseResultCode.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,58 @@
+/*
+ *  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.api.ldap.codec.controls.sort;
+
+
+import org.apache.directory.api.asn1.actions.AbstractReadInteger;
+import org.apache.directory.api.asn1.ber.Asn1Container;
+import org.apache.directory.api.ldap.model.message.controls.SortResultCode;
+
+
+/**
+ * The action used to store the result code of a SortResponseControl
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StoreSortResponseResultCode<C extends Asn1Container> extends AbstractReadInteger<C>
+{
+
+    /**
+     * Instantiates a new StoreSortResponseResultCode action.
+     */
+    public StoreSortResponseResultCode()
+    {
+        super( "SortResponse result code error" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void setIntegerValue( int value, Asn1Container container )
+    {
+        SortResponseContainer sortRespContainer = ( SortResponseContainer ) container;
+
+        SortResultCode code = SortResultCode.get( value );
+        sortRespContainer.getControl().setSortResult( code );
+
+        sortRespContainer.setGrammarEndAllowed( true );
+    }
+}

Added: directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/SortRequestControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/SortRequestControlTest.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/SortRequestControlTest.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/SortRequestControlTest.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,163 @@
+/*
+ *   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.api.ldap.codec.sort;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.ldap.codec.controls.sort.SortRequestDecorator;
+import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
+import org.apache.directory.api.ldap.model.message.controls.SortKey;
+import org.apache.directory.api.ldap.model.message.controls.SortRequestControl;
+import org.junit.Test;
+
+/**
+ * Tests for SortRequestControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SortRequestControlTest extends AbstractCodecServiceTest
+{
+    @Test
+    public void testDecodeControl() throws Exception
+    {
+        ByteBuffer buffer = ByteBuffer.allocate( 16 );
+        buffer.put( new byte[]
+            {
+               0x30, 0x0E,
+                0x30, 0x0C,
+                   0x04, 0x02, 'c', 'n',
+                   0x04, 0x03, 'o', 'i', 'd',
+                   0x01, 0x01, 0x00
+            } );
+        buffer.flip();
+        
+        SortRequestDecorator decorator = new SortRequestDecorator( codec );
+        SortRequestControl control = ( SortRequestControl ) decorator.decode( buffer.array() );
+        
+        assertEquals( 1, control.getSortKeys().size() );
+        
+        SortKey sk = control.getSortKeys().get( 0 );
+        assertEquals( "cn", sk.getAttributeTypeDesc() );
+        assertEquals( "oid", sk.getMatchingRuleId() );
+        assertFalse( sk.isReverseOrder() );
+        
+        ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
+        decorator.computeLength();
+        decorator.encode( encoded );
+        assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
+    }
+    
+    
+    @Test
+    public void testDecodeControlWithMultipleSortKeys() throws Exception
+    {
+        ByteBuffer buffer = ByteBuffer.allocate( 0x1E );
+        buffer.put( new byte[]
+            {
+               0x30, 0x1C,
+
+                0x30, 0x0C,
+                   0x04, 0x02, 'c', 'n',
+                   0x04, 0x03, 'o', 'i', 'd',
+                   0x01, 0x01, 0x00,
+
+                0x30, 0x0C,
+                   0x04, 0x02, 's', 'n',
+                   0x04, 0x03, 'i', 'o', 'd',
+                   0x01, 0x01, (byte)0xFF
+            } );
+        buffer.flip();
+        
+        SortRequestDecorator decorator = new SortRequestDecorator( codec );
+        SortRequestControl control = ( SortRequestControl ) decorator.decode( buffer.array() );
+        
+        assertEquals( 2, control.getSortKeys().size() );
+        
+        SortKey sk = control.getSortKeys().get( 0 );
+        assertEquals( "cn", sk.getAttributeTypeDesc() );
+        assertEquals( "oid", sk.getMatchingRuleId() );
+        assertFalse( sk.isReverseOrder() );
+        
+        sk = control.getSortKeys().get( 1 );
+        assertEquals( "sn", sk.getAttributeTypeDesc() );
+        assertEquals( "iod", sk.getMatchingRuleId() );
+        assertTrue( sk.isReverseOrder() );
+        
+        ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
+        decorator.computeLength();
+        decorator.encode( encoded );
+        assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
+    }
+
+    
+    @Test(expected = DecoderException.class)
+    public void testDecodeWithoutAtDesc() throws Exception
+    {
+        ByteBuffer buffer = ByteBuffer.allocate( 7 );
+        buffer.put( new byte[]
+            {
+               0x30, 0x05,
+                0x30, 0x03,
+                   0x01, 0x01, 0x00
+            } );
+        buffer.flip();
+        
+        SortRequestDecorator decorator = new SortRequestDecorator( codec );
+        decorator.decode( buffer.array() );
+    }
+    
+    
+    @Test
+    public void testDecodeControlWithoutMrOid() throws Exception
+    {
+        ByteBuffer buffer = ByteBuffer.allocate( 11 );
+        buffer.put( new byte[]
+            {
+               0x30, 0x09,
+                0x30, 0x07,
+                   0x04, 0x02, 'c', 'n',
+                   0x01, 0x01, 0x00
+            } );
+        buffer.flip();
+        
+        SortRequestDecorator decorator = new SortRequestDecorator( codec );
+        SortRequestControl control = ( SortRequestControl ) decorator.decode( buffer.array() );
+        
+        assertEquals( 1, control.getSortKeys().size() );
+        
+        SortKey sk = control.getSortKeys().get( 0 );
+        assertEquals( "cn", sk.getAttributeTypeDesc() );
+        assertNull( sk.getMatchingRuleId() );
+        assertFalse( sk.isReverseOrder() );
+        
+        ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
+        decorator.computeLength();
+        decorator.encode( encoded );
+        assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
+    }
+}

Added: directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/SortResponseControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/SortResponseControlTest.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/SortResponseControlTest.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/sort/SortResponseControlTest.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,107 @@
+/*
+ *   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.api.ldap.codec.sort;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import org.apache.directory.api.ldap.codec.controls.sort.SortResponseDecorator;
+import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
+import org.apache.directory.api.ldap.model.message.controls.SortResponseControl;
+import org.apache.directory.api.ldap.model.message.controls.SortResultCode;
+import org.junit.Test;
+
+/**
+ * Tests for SortResponseControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SortResponseControlTest extends AbstractCodecServiceTest
+{
+    @Test
+    public void testDecodeControl() throws Exception
+    {
+        ByteBuffer buffer = ByteBuffer.allocate( 0x09 );
+        buffer.put( new byte[]
+            {
+               0x30, 0x07,
+                0x0A, 0x01, 0x00,
+                0x04, 0x02, 'c', 'n'
+            } );
+        buffer.flip();
+        
+        SortResponseDecorator decorator = new SortResponseDecorator( codec );
+        SortResponseControl control = ( SortResponseControl ) decorator.decode( buffer.array() );
+        
+        assertEquals( SortResultCode.SUCCESS, control.getSortResult() );
+        assertEquals( "cn", control.getAttibuteName() );
+        
+        ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
+        decorator.computeLength();
+        decorator.encode( encoded );
+        assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
+    }
+
+    
+    @Test
+    public void testDecodeControlWithoutAtType() throws Exception
+    {
+        ByteBuffer buffer = ByteBuffer.allocate( 0x05 );
+        buffer.put( new byte[]
+            {
+               0x30, 0x03,
+                0x0A, 0x01, 0x10
+            } );
+        buffer.flip();
+        
+        SortResponseDecorator decorator = new SortResponseDecorator( codec );
+        SortResponseControl control = ( SortResponseControl ) decorator.decode( buffer.array() );
+        
+        assertEquals( SortResultCode.NOSUCHATTRIBUTE, control.getSortResult() );
+        assertNull( control.getAttibuteName() );
+        
+        ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
+        decorator.computeLength();
+        decorator.encode( encoded );
+        assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
+    }
+
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testDecodeControlWithWrongResultCode() throws Exception
+    {
+        ByteBuffer buffer = ByteBuffer.allocate( 0x05 );
+        buffer.put( new byte[]
+            {
+               0x30, 0x03,
+                0x0A, 0x01, 0x0A
+            } );
+        buffer.flip();
+        
+        SortResponseDecorator decorator = new SortResponseDecorator( codec );
+        decorator.decode( buffer.array() );
+    }
+
+}

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortKey.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortKey.java?rev=1553092&r1=1553091&r2=1553092&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortKey.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortKey.java Mon Dec 23 10:43:10 2013
@@ -20,24 +20,20 @@
 package org.apache.directory.api.ldap.model.message.controls;
 
 
-import org.apache.directory.api.ldap.model.schema.AttributeType;
 
 
 /**
- * Store the Attribute 
+ * Datastructure to store the Attribute name, matching rule ID of the attribute<br>
+ * and the sort order.
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class SortKey
 {
     /**
-     * The name of AttributeType we want to use as a key for the sort
+     * The name/OID of AttributeType we want to use as a key for the sort
      */
-    private String attributeTypeOid;
-
-    /**
-     * The AttributeType we want to use as a key for the sort
-     */
-    private AttributeType attributeType;
+    private String attributeTypeDesc;
 
     /**
      * The matching rule to use to order the result
@@ -53,148 +49,56 @@ public class SortKey
     /**
      * Create a new instance of a SortKey for a give AttributeType
      * 
-     * @param attributeType The AttributeType to use
-     */
-    public SortKey( AttributeType attributeType )
-    {
-        this.attributeType = attributeType;
-        matchingRuleId = attributeType.getOrderingOid();
-        reverseOrder = false;
-    }
-
-
-    /**
-     * Create a new instance of a SortKey for a give AttributeType
-     * 
-     * @param attributeTypeOid The AttributeType OID to use
-     */
-    public SortKey( String attributeTypeOid )
-    {
-        this.attributeTypeOid = attributeTypeOid;
-        matchingRuleId = null;
-        reverseOrder = false;
-    }
-
-
-    /**
-     * Create a new instance of a SortKey for a give AttributeType
-     * 
-     * @param attributeType The AttributeType to use
-     * @param matchingRuleId The MatchingRule to use
+     * @param attributeTypeDesc The AttributeType's name or OID to use
      */
-    public SortKey( AttributeType attributeType, String matchingRuleId )
+    public SortKey( String attributeTypeDesc )
     {
-        this.attributeType = attributeType;
-        this.matchingRuleId = matchingRuleId;
-        reverseOrder = false;
+        this( attributeTypeDesc, null );
     }
 
 
     /**
      * Create a new instance of a SortKey for a give AttributeType
      * 
-     * @param attributeTypeOid The AttributeType OID to use
+     * @param attributeTypeDesc The AttributeType's name or OID to use
      * @param matchingRuleId The MatchingRule to use
      */
-    public SortKey( String attributeTypeOid, String matchingRuleId )
+    public SortKey( String attributeTypeDesc, String matchingRuleId )
     {
-        this.attributeTypeOid = attributeTypeOid;
-        this.matchingRuleId = matchingRuleId;
-        reverseOrder = false;
+        this( attributeTypeDesc, matchingRuleId, false );
     }
 
-
+    
     /**
      * Create a new instance of a SortKey for a give AttributeType
      * 
-     * @param attributeType The AttributeType to use
+     * @param attributeTypeDesc The AttributeType OID to use
      * @param matchingRuleId The MatchingRule to use
      * @param reverseOrder The reverseOrder flag
      */
-    public SortKey( AttributeType attributeType, String matchingRuleId, boolean reverseOrder )
+    public SortKey( String attributeTypeDesc, String matchingRuleId, boolean reverseOrder )
     {
-        this.attributeType = attributeType;
+        this.attributeTypeDesc = attributeTypeDesc;
         this.matchingRuleId = matchingRuleId;
         this.reverseOrder = reverseOrder;
     }
 
 
     /**
-     * Create a new instance of a SortKey for a give AttributeType
-     * 
-     * @param attributeTypeOid The AttributeType OID to use
-     * @param matchingRuleId The MatchingRule to use
-     * @param reverseOrder The reverseOrder flag
+     * @return the attributeType name or OID
      */
-    public SortKey( String attributeTypeOid, String matchingRuleId, boolean reverseOrder )
+    public String getAttributeTypeDesc()
     {
-        this.attributeTypeOid = attributeTypeOid;
-        this.matchingRuleId = matchingRuleId;
-        this.reverseOrder = reverseOrder;
-    }
-
-
-    /**
-     * Create a new instance of a SortKey for a give AttributeType
-     * 
-     * @param attributeType The AttributeType to use
-     * @param reverseOrder The reverseOrder flag
-     */
-    public SortKey( AttributeType attributeType, boolean reverseOrder )
-    {
-        this.attributeType = attributeType;
-        this.matchingRuleId = attributeType.getOrderingOid();
-        this.reverseOrder = reverseOrder;
-    }
-
-
-    /**
-     * Create a new instance of a SortKey for a give AttributeType
-     * 
-     * @param attributeTypeOid The AttributeType OID to use
-     * @param reverseOrder The reverseOrder flag
-     */
-    public SortKey( String attributeTypeOid, boolean reverseOrder )
-    {
-        this.attributeTypeOid = attributeTypeOid;
-        this.reverseOrder = reverseOrder;
-    }
-
-
-    /**
-     * @return the attributeType
-     */
-    public AttributeType getAttributeType()
-    {
-        return attributeType;
+        return attributeTypeDesc;
     }
 
 
     /**
      * @param attributeType the attributeType to set
      */
-    public void setAttributeType( AttributeType attributeType )
+    public void setAttributeTypeDesc( String attributeTypeDesc )
     {
-        this.attributeType = attributeType;
-        this.attributeTypeOid = attributeType.getOid();
-    }
-
-
-    /**
-     * @return the attributeType OID
-     */
-    public String getAttributeTypeOid()
-    {
-        return attributeTypeOid;
-    }
-
-
-    /**
-     * @param attributeType the attributeType to set
-     */
-    public void setAttributeType( String attributeTypeOid )
-    {
-        this.attributeTypeOid = attributeTypeOid;
+        this.attributeTypeDesc = attributeTypeDesc;
     }
 
 
@@ -243,19 +147,11 @@ public class SortKey
 
         sb.append( "SortKey : [" );
 
-        if ( attributeType != null )
-        {
-            sb.append( attributeType.getName() ).append( ',' );
-            sb.append( matchingRuleId );
-        }
-        else
+        sb.append( attributeTypeDesc );
+        
+        if ( matchingRuleId != null )
         {
-            sb.append( attributeTypeOid );
-
-            if ( matchingRuleId != null )
-            {
-                sb.append( ", " ).append( matchingRuleId );
-            }
+            sb.append( ", " ).append( matchingRuleId );
         }
 
         if ( reverseOrder )

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequestControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequestControl.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequestControl.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequestControl.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,65 @@
+/*
+ *   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.api.ldap.model.message.controls;
+
+
+import java.util.List;
+
+import org.apache.directory.api.ldap.model.message.Control;
+
+
+/**
+ * Implementation of Server Side Sort request control based on
+ * the <a href="http://tools.ietf.org/html/rfc2891">RFC 2891</a><br><br>
+ * 
+ *       SortKeyList ::= SEQUENCE OF SEQUENCE {<br>
+ *               attributeType   AttributeDescription,<br>
+ *               orderingRule    [0] MatchingRuleId OPTIONAL,<br>
+ *               reverseOrder    [1] BOOLEAN DEFAULT FALSE }<br>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface SortRequestControl extends Control
+{
+    /** the sort request control's OID */
+    String OID = "1.2.840.113556.1.4.473";
+
+
+    /**
+     * sets the sort keys
+     *  
+     * @param sortKeys
+     */
+    void setSortKeys( List<SortKey> sortKeys );
+
+
+    /**
+     * @return the list of sort keys
+     */
+    List<SortKey> getSortKeys();
+
+
+    /**
+     * adds a sort key
+     * 
+     * @param sortKey
+     */
+    void addSortKey( SortKey sortKey );
+}

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequestControlImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequestControlImpl.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequestControlImpl.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequestControlImpl.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,80 @@
+/*
+ *   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.api.ldap.model.message.controls;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * Implementation of SortRequestControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SortRequestControlImpl extends AbstractControl implements SortRequestControl
+{
+    /**
+     * the list of sort keys
+     */
+    private List<SortKey> sortKeys;
+
+
+    public SortRequestControlImpl()
+    {
+        super( OID );
+    }
+
+
+    /**
+     * @return the sortKeys
+     */
+    public List<SortKey> getSortKeys()
+    {
+        return sortKeys;
+    }
+
+
+    /**
+     * @param sortKeys the sortKeys to set
+     */
+    public void setSortKeys( List<SortKey> sortKeys )
+    {
+        this.sortKeys = sortKeys;
+    }
+
+
+    public void addSortKey( SortKey skey )
+    {
+        if ( sortKeys == null )
+        {
+            sortKeys = new ArrayList<SortKey>();
+        }
+
+        sortKeys.add( skey );
+    }
+
+
+    @Override
+    public String toString()
+    {
+        return "SortRequestControlImpl [sortKeys=" + sortKeys + "]";
+    }
+}

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResponseControl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResponseControl.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResponseControl.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResponseControl.java Mon Dec 23 10:43:10 2013
@@ -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.api.ldap.model.message.controls;
+
+import org.apache.directory.api.ldap.model.message.Control;
+
+/**
+ * 
+ * <pre>SortResult ::= SEQUENCE {<br>
+ *           sortResult  ENUMERATED {<br>
+ *           success                   (0), -- results are sorted<br>
+ *           operationsError           (1), -- server internal failure<br>
+ *           timeLimitExceeded         (3), -- timelimit reached before sorting was completed<br>
+ *           strongAuthRequired        (8), -- refused to return sorted results via insecure protocol<br>
+ *           adminLimitExceeded       (11), -- too many matching entries for the server to sort<br>
+ *           noSuchAttribute          (16), -- unrecognized attribute type in sort key<br>
+ *           inappropriateMatching    (18), -- unrecognized or inappropriate matching rule in sort key<br>
+ *           insufficientAccessRights (50), -- refused to return sorted results to this client<br>
+ *           busy                     (51), -- too busy to process<br>
+ *           unwillingToPerform       (53), -- unable to sort<br>
+ *           other                    (80)<br>
+ *           },<br>
+ *       attributeType [0] AttributeDescription OPTIONAL }<br><pre>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface SortResponseControl extends Control
+{
+    /** the OID of the response control */
+    String OID = "1.2.840.113556.1.4.474";
+    
+    /**
+     * sets the sort result
+     * 
+     * @param result
+     */
+    void setSortResult( SortResultCode result );
+    
+    
+    /**
+     * @return the sort result
+     */
+    SortResultCode getSortResult();
+
+    
+    /**
+     * sets the name of the first offending attribute
+     *  
+     * @param attributeName
+     */
+    // didn't name the method setAttribute*Type*
+    // cause in our internal terminology AttributeType is a java type
+    void setAttibuteName( String attributeName );
+    
+    
+    /**
+     * @return the name of the first offending attribute
+     */
+    String getAttibuteName();
+}

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResponseControlImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResponseControlImpl.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResponseControlImpl.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResponseControlImpl.java Mon Dec 23 10:43:10 2013
@@ -0,0 +1,107 @@
+/*
+ *   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.api.ldap.model.message.controls;
+
+/**
+ * Implementation of SortResponseControl.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SortResponseControlImpl extends AbstractControl  implements SortResponseControl
+{
+    /** the sort operations result code */
+    private SortResultCode result;
+    
+    /** name of the first offending attribute */
+    private String attributeName;
+    
+    public SortResponseControlImpl()
+    {
+        super( OID );
+    }
+
+    @Override
+    public void setSortResult( SortResultCode result )
+    {
+        this.result = result;
+    }
+
+    @Override
+    public SortResultCode getSortResult()
+    {
+        return result;
+    }
+
+    @Override
+    public void setAttibuteName( String attributeName )
+    {
+        this.attributeName = attributeName;
+    }
+
+    @Override
+    public String getAttibuteName()
+    {
+        return attributeName;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ( ( attributeName == null ) ? 0 : attributeName.hashCode() );
+        result = prime * result + ( ( this.result == null ) ? 0 : this.result.hashCode() );
+        return result;
+    }
+
+    @Override
+    public boolean equals( Object o )
+    {
+        if( !super.equals( o ) )
+        {
+            return false;
+        }
+        
+        SortResponseControl that = ( SortResponseControl ) o;
+        
+        if( result != that.getSortResult() )
+        {
+            return false;
+        }
+        
+        if( attributeName != null )
+        {
+            return ( attributeName.equalsIgnoreCase( that.getAttibuteName() ) );
+        }
+        else if( that.getAttibuteName() == null )
+        {
+            return true;
+        }
+        
+        return false;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "SortResponseControlImpl [result=" + result + ", attributeName=" + attributeName + "]";
+    }
+    
+}

Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResultCode.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResultCode.java?rev=1553092&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResultCode.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortResultCode.java Mon Dec 23 10:43:10 2013
@@ -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.api.ldap.model.message.controls;
+
+/**
+ * Enumeration of the result codes of a SortResult defined in <a href="http://tools.ietf.org/html/rfc2891">RFC 2891</a>
+ * for server side sort control.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public enum SortResultCode
+{
+    SUCCESS( 0, "Results are sorted"),
+    
+    OPERATIONSERROR( 1, "Server internal failure"),
+    
+    TIMELIMITEXCEEDED( 3, "Timelimit reached before sorting was completed"),
+    
+    STRONGAUTHREQUIRED( 8, "Refused to return sorted results via insecure protocol"),
+    
+    ADMINLIMITEXCEEDED( 11, "Too many matching entries for the server to sort"),
+    
+    NOSUCHATTRIBUTE( 16, "Unrecognized attribute type in sort key"),
+    
+    INAPPROPRIATEMATCHING( 18, "Unrecognized or inappropriate matching rule in sort key"),
+    
+    INSUFFICIENTACCESSRIGHTS( 50, "Refused to return sorted results to this client"),
+    
+    BUSY( 51, "Too busy to process"),
+    
+    UNWILLINGTOPERFORM( 53, "Unable to sort"),
+    
+    OTHER( 80, "Other");
+    
+    int val;
+    String desc;
+    
+    private SortResultCode( int val, String desc )
+    {
+        this.val = val;
+        this.desc = desc;
+    }
+
+    public int getVal()
+    {
+        return val;
+    }
+    
+    /**
+     * returns the enum value representing the given code.
+     * 
+     * @param code the result code
+     * @return returns the corresponding ResultCode, throws IllegalArgumentException when there
+     *         is no matching ResultCode exists for the given value.
+     */
+    public static SortResultCode get( int code )
+    {
+        switch ( code )
+        {
+            case 0:
+                return SUCCESS;
+
+            case 1:
+                return OPERATIONSERROR;
+
+            case 3:
+                return TIMELIMITEXCEEDED;
+                
+            case 8:
+                return STRONGAUTHREQUIRED;
+
+            case 11:
+                return ADMINLIMITEXCEEDED;
+                
+            case 16:
+                return NOSUCHATTRIBUTE;
+                
+            case 18:
+                return INAPPROPRIATEMATCHING;
+                
+            case 50:
+                return INSUFFICIENTACCESSRIGHTS;
+                
+            case 51:
+                return BUSY;
+                
+            case 53:
+                return UNWILLINGTOPERFORM;
+                
+            case 80:
+                return OTHER;
+
+            default:
+                throw new IllegalArgumentException( "Unknown sort response result code " + code );
+        }
+    }
+}



Mime
View raw message