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.search.persistentSearch;
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.PersistentSearch;
26  
27  
28  /**
29   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
30   */
31  public class PersistentSearchContainer extends AbstractContainer
32  {
33      /** PSearchControl */
34      private PersistentSearchDecorator decorator;
35  
36      private LdapApiService codec;
37  
38  
39      /**
40       * Creates a new PSearchControlContainer object. We will store one grammar,
41       * it's enough ...
42       * 
43       * @param codec The LDAP service instance
44       */
45      public PersistentSearchContainer( LdapApiService codec )
46      {
47          super();
48          this.codec = codec;
49          setGrammar( PersistentSearchGrammar.getInstance() );
50          setTransition( PersistentSearchStates.START_STATE );
51      }
52  
53  
54      /**
55       * Creates a new PSearchControlContainer object pre-populated with a
56       * decorator wrapping the supplied control, or using the supplied control if
57       * it already is a decorator.
58       *
59       * @param codec The LDAP service instance
60       * @param control The PersistentSearch Control or a decorating wrapper.
61       */
62      public PersistentSearchContainer( LdapApiService codec, PersistentSearch control )
63      {
64          this( codec );
65          decorate( control );
66      }
67  
68  
69      /**
70       * Conditionally decorates a control if is not a decorator already.
71       *
72       * @param control The PersistentSearch Control to decorate if it already is not
73       * a decorator, if it is then the object is set as this container's decorator.
74       */
75      public void decorate( PersistentSearch control )
76      {
77          if ( control instanceof PersistentSearchDecorator )
78          {
79              this.decorator = ( PersistentSearchDecorator ) control;
80          }
81          else
82          {
83              this.decorator = new PersistentSearchDecorator( codec, control );
84          }
85      }
86  
87  
88      /**
89       * @return Returns the persistent search decorator.
90       */
91      public PersistentSearchDecorator getPersistentSearchDecorator()
92      {
93  
94          return decorator;
95      }
96  
97  
98      /**
99       * Set a PSearchControl Object into the container. It will be completed by
100      * the ldapDecoder.
101      * 
102      * @param decorator the PSearchControl to set.
103      */
104     public void setPersistentSearchDecorator( PersistentSearchDecorator decorator )
105     {
106         this.decorator = decorator;
107     }
108 
109 
110     /**
111      * Clean the container
112      */
113     @Override
114     public void clean()
115     {
116         super.clean();
117         decorator = null;
118     }
119 }