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.SortResponse;
026
027
028/**
029 * Container for SortResponseControl.
030 *
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 */
033public class SortResponseContainer extends AbstractContainer
034{
035    /** the decorator instance of sort response control */
036    private SortResponseDecorator control;
037
038    /** LDAP codec */
039    private LdapApiService codec;
040
041    /**
042     * Creates a new instance of SortResponseContainer.
043     *
044     * @param codec the LDAP codec
045     */
046    public SortResponseContainer( LdapApiService codec )
047    {
048        super();
049        this.codec = codec;
050        grammar = SortResponseGrammar.getInstance();
051        setTransition( SortResponseStates.START_STATE );
052    }
053
054
055    /**
056     * Creates a new instance of SortResponseContainer.
057     *
058     * @param codec the LDAP codec
059     * @param control the sort response control
060     */
061    public SortResponseContainer( LdapApiService codec, SortResponse control )
062    {
063        this( codec );
064        decorate( control );
065    }
066
067
068    /**
069     * {@inheritDoc} 
070     */
071    public void decorate( SortResponse control )
072    {
073        if ( control instanceof SortResponseDecorator )
074        {
075            this.control = ( SortResponseDecorator ) control;
076        }
077        else
078        {
079            this.control = new SortResponseDecorator( codec, control );
080        }
081    }
082
083
084    /**
085     * @return the control
086     */
087    public SortResponseDecorator getControl()
088    {
089        return control;
090    }
091
092
093    /**
094     * @param control the control to set
095     */
096    public void setControl( SortResponseDecorator control )
097    {
098        this.control = control;
099    }
100
101
102    /**
103     * Clean the container
104     */
105    public void clean()
106    {
107        super.clean();
108        control = null;
109    }
110
111}