View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  package org.apache.directory.api.ldap.codec.controls.sort;
21  
22  
23  import org.apache.directory.api.asn1.ber.AbstractContainer;
24  import org.apache.directory.api.ldap.codec.api.LdapApiService;
25  import org.apache.directory.api.ldap.model.message.controls.SortResponse;
26  
27  
28  /**
29   * Container for SortResponseControl.
30   *
31   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32   */
33  public class SortResponseContainer extends AbstractContainer
34  {
35      /** the decorator instance of sort response control */
36      private SortResponseDecorator control;
37  
38      /** LDAP codec */
39      private LdapApiService codec;
40  
41  
42      /**
43       * Creates a new instance of SortResponseContainer.
44       *
45       * @param codec the LDAP codec
46       */
47      public SortResponseContainer( LdapApiService codec )
48      {
49          super();
50          this.codec = codec;
51          setGrammar( SortResponseGrammar.getInstance() );
52          setTransition( SortResponseStates.START_STATE );
53      }
54  
55  
56      /**
57       * Creates a new instance of SortResponseContainer.
58       *
59       * @param codec the LDAP codec
60       * @param control the sort response control
61       */
62      public SortResponseContainer( LdapApiService codec, SortResponse control )
63      {
64          this( codec );
65          decorate( control );
66      }
67  
68  
69      /**
70       * Decorate the SortResponse control
71       * 
72       * @param control The Sort Response control to decorate
73       */
74      public void decorate( SortResponse control )
75      {
76          if ( control instanceof SortResponseDecorator )
77          {
78              this.control = ( SortResponseDecorator ) control;
79          }
80          else
81          {
82              this.control = new SortResponseDecorator( codec, control );
83          }
84      }
85  
86  
87      /**
88       * @return the control
89       */
90      public SortResponseDecorator getControl()
91      {
92          return control;
93      }
94  
95  
96      /**
97       * @param control the control to set
98       */
99      public void setControl( SortResponseDecorator control )
100     {
101         this.control = control;
102     }
103 
104 
105     /**
106      * Clean the container
107      */
108     @Override
109     public void clean()
110     {
111         super.clean();
112         control = null;
113     }
114 }