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 */
020
021package org.apache.directory.api.ldap.extras.controls.vlv_impl;
022
023
024import org.apache.directory.api.asn1.ber.AbstractContainer;
025import org.apache.directory.api.ldap.codec.api.LdapApiService;
026import org.apache.directory.api.ldap.extras.controls.vlv.VirtualListViewResponse;
027
028
029/**
030 * A container for the VLV response control.
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 */
034public class VirtualListViewResponseContainer extends AbstractContainer
035{
036    private VirtualListViewResponseDecorator control;
037
038    private LdapApiService codec;
039
040
041    /**
042     * Creates a new VirtualListViewResponseContainer object.
043     *
044     * @param codec The LDAP Service to use
045     */
046    public VirtualListViewResponseContainer( LdapApiService codec )
047    {
048        super();
049        this.codec = codec;
050        setGrammar( VirtualListViewResponseGrammar.getInstance() );
051        setTransition( VirtualListViewResponseStates.START_STATE );
052    }
053
054
055    /**
056     * Creates a new VirtualListViewResponseContainer object.
057     *
058     * @param control The VLV control to decorate
059     * @param codec The LDAP Service to use
060     */
061    public VirtualListViewResponseContainer( VirtualListViewResponseDecorator control, LdapApiService codec )
062    {
063        this( codec );
064        decorate( control );
065    }
066
067
068    /**
069     * @return The decorated VLV control
070     */
071    public VirtualListViewResponseDecorator getDecorator()
072    {
073        return control;
074    }
075
076
077    /**
078     * Decorate a VLV control
079     *  
080     * @param control The VLV control to decorate
081     */
082    public void decorate( VirtualListViewResponse control )
083    {
084        if ( control instanceof VirtualListViewResponseDecorator )
085        {
086            this.control = ( VirtualListViewResponseDecorator ) control;
087        }
088        else
089        {
090            this.control = new VirtualListViewResponseDecorator( codec, control );
091        }
092    }
093
094
095    /**
096     * Set the VLV control
097     * 
098     * @param control The VLV control
099     */
100    public void setVirtualListViewResponseControl( VirtualListViewResponseDecorator control )
101    {
102        this.control = control;
103    }
104
105
106    /**
107     * {@inheritDoc}
108     */
109    @Override
110    public void clean()
111    {
112        super.clean();
113        control = null;
114    }
115}