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.SortKey;
26  import org.apache.directory.api.ldap.model.message.controls.SortRequest;
27  
28  
29  /**
30   * Container for SortRequestControl.
31   *
32   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33   */
34  public class SortRequestContainer extends AbstractContainer
35  {
36      /** the sort request control decorator */
37      private SortRequestDecorator control;
38  
39      /** the LDAP codec */
40      private LdapApiService codec;
41  
42      /** current key that is being decoded */
43      private SortKey currentKey;
44  
45      /**
46       * Creates a new instance of SortRequestContainer.
47       *
48       * @param codec the LDAP codec
49       */
50      public SortRequestContainer( LdapApiService codec )
51      {
52          super();
53          this.codec = codec;
54          grammar = SortRequestGrammar.getInstance();
55          setTransition( SortRequestStates.START_STATE );
56      }
57  
58  
59      /**
60       * Creates a new instance of SortRequestContainer.
61       *
62       * @param codec the LDAP codec
63       * @param control the sort request control
64       */
65      public SortRequestContainer( LdapApiService codec, SortRequest control )
66      {
67          this( codec );
68          decorate( control );
69      }
70  
71  
72      /**
73       * {@inheritDoc}
74       */
75      public void decorate( SortRequest control )
76      {
77          if ( control instanceof SortRequestDecorator )
78          {
79              this.control = ( SortRequestDecorator ) control;
80          }
81          else
82          {
83              this.control = new SortRequestDecorator( codec, control );
84          }
85      }
86  
87  
88      /**
89       * @return the control
90       */
91      public SortRequestDecorator getControl()
92      {
93          return control;
94      }
95  
96  
97      /**
98       * @param control the control to set
99       */
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 }