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      /**
47       * Creates a new instance of SortRequestContainer.
48       *
49       * @param codec the LDAP codec
50       */
51      public SortRequestContainer( LdapApiService codec )
52      {
53          super();
54          this.codec = codec;
55          setGrammar( SortRequestGrammar.getInstance() );
56          setTransition( SortRequestStates.START_STATE );
57      }
58  
59  
60      /**
61       * Creates a new instance of SortRequestContainer.
62       *
63       * @param codec the LDAP codec
64       * @param control the sort request control
65       */
66      public SortRequestContainer( LdapApiService codec, SortRequest control )
67      {
68          this( codec );
69          decorate( control );
70      }
71  
72  
73      /**
74       * Decorate a SortRequest control
75       * 
76       * @param control The control to decorate
77       */
78      public void decorate( SortRequest control )
79      {
80          if ( control instanceof SortRequestDecorator )
81          {
82              this.control = ( SortRequestDecorator ) control;
83          }
84          else
85          {
86              this.control = new SortRequestDecorator( codec, control );
87          }
88      }
89  
90  
91      /**
92       * @return the control
93       */
94      public SortRequestDecorator getControl()
95      {
96          return control;
97      }
98  
99  
100     /**
101      * @param control the control to set
102      */
103     public void setControl( SortRequestDecorator control )
104     {
105         this.control = control;
106     }
107 
108 
109     /**
110      * Clean the container
111      */
112     @Override
113     public void clean()
114     {
115         super.clean();
116         control = null;
117     }
118 
119 
120     /**
121      * @return the currentKey
122      */
123     public SortKey getCurrentKey()
124     {
125         return currentKey;
126     }
127 
128 
129     /**
130      * @param currentKey the currentKey to set
131      */
132     public void setCurrentKey( SortKey currentKey )
133     {
134         this.currentKey = currentKey;
135     }
136 
137 }