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 public PersistentSearchContainer( LdapApiService codec ) 44 { 45 super(); 46 this.codec = codec; 47 grammar = PersistentSearchGrammar.getInstance(); 48 setTransition( PersistentSearchStates.START_STATE ); 49 } 50 51 52 /** 53 * Creates a new PSearchControlContainer object pre-populated with a 54 * decorator wrapping the supplied control, or using the supplied control if 55 * it already is a decorator. 56 * 57 * @param control The PersistentSearch Control or a decorating wrapper. 58 */ 59 public PersistentSearchContainer( LdapApiService codec, PersistentSearch control ) 60 { 61 this( codec ); 62 decorate( control ); 63 } 64 65 66 /** 67 * Conditionally decorates a control if is not a decorator already. 68 * 69 * @param control The PersistentSearch Control to decorate if it already is not 70 * a decorator, if it is then the object is set as this container's decorator. 71 */ 72 public void decorate( PersistentSearch control ) 73 { 74 if ( control instanceof PersistentSearchDecorator ) 75 { 76 this.decorator = ( PersistentSearchDecorator ) control; 77 } 78 else 79 { 80 this.decorator = new PersistentSearchDecorator( codec, control ); 81 } 82 } 83 84 85 /** 86 * @return Returns the persistent search decorator. 87 */ 88 public PersistentSearchDecorator getPersistentSearchDecorator() 89 { 90 91 return decorator; 92 } 93 94 95 /** 96 * Set a PSearchControl Object into the container. It will be completed by 97 * the ldapDecoder. 98 * 99 * @param decorator the PSearchControl to set. 100 */ 101 public void setPersistentSearchDecorator( PersistentSearchDecorator decorator ) 102 { 103 this.decorator = decorator; 104 } 105 106 107 /** 108 * Clean the container 109 */ 110 public void clean() 111 { 112 super.clean(); 113 decorator = null; 114 } 115 }