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   *     https://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.DecoderException;
24  import org.apache.directory.api.asn1.ber.tlv.BerValue;
25  import org.apache.directory.api.asn1.util.Asn1Buffer;
26  import org.apache.directory.api.ldap.codec.api.AbstractControlFactory;
27  import org.apache.directory.api.ldap.codec.api.LdapApiService;
28  import org.apache.directory.api.ldap.model.message.Control;
29  import org.apache.directory.api.ldap.model.message.controls.PersistentSearch;
30  import org.apache.directory.api.ldap.model.message.controls.PersistentSearchImpl;
31  
32  
33  /**
34   * A factory to create a PersistentSearch control
35   *
36   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
37   * @version $Rev$, $Date$
38   */
39  public class PersistentSearchFactory extends AbstractControlFactory<PersistentSearch>
40  {
41      /**
42       * Create a new PersistentSearchFactory instance
43       *
44       * @param codec The LdapApiService instance
45       */
46      public PersistentSearchFactory( LdapApiService codec )
47      {
48          super( codec, PersistentSearch.OID );
49      }
50  
51  
52      /**
53       * {@inheritDoc}
54       */
55      @Override
56      public PersistentSearch newControl()
57      {
58          return new PersistentSearchImpl();
59      }
60  
61  
62      /**
63       * {@inheritDoc}
64       */
65      @Override
66      public void encodeValue( Asn1Buffer buffer, Control control )
67      {
68          PersistentSearch persistentSearch = ( PersistentSearch ) control;
69          int start = buffer.getPos();
70  
71          // The returnECs flag
72          BerValue.encodeBoolean( buffer, persistentSearch.isReturnECs() );
73  
74          // The changeOnly flag
75          BerValue.encodeBoolean( buffer, persistentSearch.isChangesOnly() );
76  
77          // The changeTypes
78          BerValue.encodeInteger( buffer, persistentSearch.getChangeTypes() );
79  
80          // The PersistentSearch sequence
81          BerValue.encodeSequence( buffer, start );
82      }
83  
84  
85      /**
86       * {@inheritDoc}
87       */
88      @Override
89      public void decodeValue( Control control, byte[] controlBytes ) throws DecoderException
90      {
91          decodeValue( new PersistentSearchContainer( control ), control, controlBytes );
92      }
93  }