001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.codec.controls.search.persistentSearch; 021 022 023import org.apache.directory.api.asn1.ber.AbstractContainer; 024import org.apache.directory.api.ldap.codec.api.LdapApiService; 025import org.apache.directory.api.ldap.model.message.controls.PersistentSearch; 026 027 028/** 029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 030 */ 031public class PersistentSearchContainer extends AbstractContainer 032{ 033 /** PSearchControl */ 034 private PersistentSearchDecorator decorator; 035 036 private LdapApiService codec; 037 038 039 /** 040 * Creates a new PSearchControlContainer object. We will store one grammar, 041 * it's enough ... 042 * 043 * @param codec The LDAP service instance 044 */ 045 public PersistentSearchContainer( LdapApiService codec ) 046 { 047 super(); 048 this.codec = codec; 049 setGrammar( PersistentSearchGrammar.getInstance() ); 050 setTransition( PersistentSearchStates.START_STATE ); 051 } 052 053 054 /** 055 * Creates a new PSearchControlContainer object pre-populated with a 056 * decorator wrapping the supplied control, or using the supplied control if 057 * it already is a decorator. 058 * 059 * @param codec The LDAP service instance 060 * @param control The PersistentSearch Control or a decorating wrapper. 061 */ 062 public PersistentSearchContainer( LdapApiService codec, PersistentSearch control ) 063 { 064 this( codec ); 065 decorate( control ); 066 } 067 068 069 /** 070 * Conditionally decorates a control if is not a decorator already. 071 * 072 * @param control The PersistentSearch Control to decorate if it already is not 073 * a decorator, if it is then the object is set as this container's decorator. 074 */ 075 public void decorate( PersistentSearch control ) 076 { 077 if ( control instanceof PersistentSearchDecorator ) 078 { 079 this.decorator = ( PersistentSearchDecorator ) control; 080 } 081 else 082 { 083 this.decorator = new PersistentSearchDecorator( codec, control ); 084 } 085 } 086 087 088 /** 089 * @return Returns the persistent search decorator. 090 */ 091 public PersistentSearchDecorator getPersistentSearchDecorator() 092 { 093 094 return decorator; 095 } 096 097 098 /** 099 * 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}