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.VirtualListViewRequest;
027
028
029/**
030 * A container for the VLV request control.
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 */
034public class VirtualListViewRequestContainer extends AbstractContainer
035{
036    private VirtualListViewRequestDecorator control;
037
038    private LdapApiService codec;
039
040
041    /**
042     * Creates a new VirtualListViewRequestContainer instance
043     * 
044     * @param codec The LDAP Service to use
045     */
046    public VirtualListViewRequestContainer( LdapApiService codec )
047    {
048        super();
049        this.codec = codec;
050        setGrammar( VirtualListViewRequestGrammar.getInstance() );
051        setTransition( VirtualListViewRequestStates.START_STATE );
052    }
053
054
055    /**
056     * Creates a new VirtualListViewRequestContainer instance
057     * 
058     * @param control The VLV control
059     * @param codec The LDAP Service to use
060     */
061    public VirtualListViewRequestContainer( VirtualListViewRequestDecorator control, LdapApiService codec )
062    {
063        this( codec );
064        decorate( control );
065    }
066
067
068    /**
069     * @return The VLV control
070     */
071    public VirtualListViewRequestDecorator getDecorator()
072    {
073        return control;
074    }
075
076
077    /**
078     * Decorate he VLV control
079     * 
080     * @param control The control to decorate
081     */
082    public void decorate( VirtualListViewRequest control )
083    {
084        if ( control instanceof VirtualListViewRequestDecorator )
085        {
086            this.control = ( VirtualListViewRequestDecorator ) control;
087        }
088        else
089        {
090            this.control = new VirtualListViewRequestDecorator( codec, control );
091        }
092    }
093
094
095    /**
096     * Sets the VLV control
097     * 
098     * @param control The VLV control
099     */
100    public void setVirtualListViewRequestControl( VirtualListViewRequestDecorator 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}