001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020package org.apache.directory.api.ldap.codec.controls.sort;
021
022
023import org.apache.directory.api.asn1.ber.AbstractContainer;
024import org.apache.directory.api.ldap.codec.api.LdapApiService;
025import org.apache.directory.api.ldap.model.message.controls.SortKey;
026import org.apache.directory.api.ldap.model.message.controls.SortRequest;
027
028
029/**
030 * Container for SortRequestControl.
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 */
034public class SortRequestContainer extends AbstractContainer
035{
036    /** the sort request control decorator */
037    private SortRequestDecorator control;
038
039    /** the LDAP codec */
040    private LdapApiService codec;
041
042    /** current key that is being decoded */
043    private SortKey currentKey;
044
045    /**
046     * Creates a new instance of SortRequestContainer.
047     *
048     * @param codec the LDAP codec
049     */
050    public SortRequestContainer( LdapApiService codec )
051    {
052        super();
053        this.codec = codec;
054        grammar = SortRequestGrammar.getInstance();
055        setTransition( SortRequestStates.START_STATE );
056    }
057
058
059    /**
060     * Creates a new instance of SortRequestContainer.
061     *
062     * @param codec the LDAP codec
063     * @param control the sort request control
064     */
065    public SortRequestContainer( LdapApiService codec, SortRequest control )
066    {
067        this( codec );
068        decorate( control );
069    }
070
071
072    /**
073     * {@inheritDoc}
074     */
075    public void decorate( SortRequest control )
076    {
077        if ( control instanceof SortRequestDecorator )
078        {
079            this.control = ( SortRequestDecorator ) control;
080        }
081        else
082        {
083            this.control = new SortRequestDecorator( codec, control );
084        }
085    }
086
087
088    /**
089     * @return the control
090     */
091    public SortRequestDecorator getControl()
092    {
093        return control;
094    }
095
096
097    /**
098     * @param control the control to set
099     */
100    public void setControl( SortRequestDecorator control )
101    {
102        this.control = control;
103    }
104
105
106    /**
107     * Clean the container
108     */
109    public void clean()
110    {
111        super.clean();
112        control = null;
113    }
114
115
116    /**
117     * @return the currentKey
118     */
119    public SortKey getCurrentKey()
120    {
121        return currentKey;
122    }
123
124
125    /**
126     * @param currentKey the currentKey to set
127     */
128    public void setCurrentKey( SortKey currentKey )
129    {
130        this.currentKey = currentKey;
131    }
132    
133}