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 public PersistentSearchContainer( LdapApiService codec ) 044 { 045 super(); 046 this.codec = codec; 047 grammar = PersistentSearchGrammar.getInstance(); 048 setTransition( PersistentSearchStates.START_STATE ); 049 } 050 051 052 /** 053 * Creates a new PSearchControlContainer object pre-populated with a 054 * decorator wrapping the supplied control, or using the supplied control if 055 * it already is a decorator. 056 * 057 * @param control The PersistentSearch Control or a decorating wrapper. 058 */ 059 public PersistentSearchContainer( LdapApiService codec, PersistentSearch control ) 060 { 061 this( codec ); 062 decorate( control ); 063 } 064 065 066 /** 067 * Conditionally decorates a control if is not a decorator already. 068 * 069 * @param control The PersistentSearch Control to decorate if it already is not 070 * a decorator, if it is then the object is set as this container's decorator. 071 */ 072 public void decorate( PersistentSearch control ) 073 { 074 if ( control instanceof PersistentSearchDecorator ) 075 { 076 this.decorator = ( PersistentSearchDecorator ) control; 077 } 078 else 079 { 080 this.decorator = new PersistentSearchDecorator( codec, control ); 081 } 082 } 083 084 085 /** 086 * @return Returns the persistent search decorator. 087 */ 088 public PersistentSearchDecorator getPersistentSearchDecorator() 089 { 090 091 return decorator; 092 } 093 094 095 /** 096 * Set a PSearchControl Object into the container. It will be completed by 097 * the ldapDecoder. 098 * 099 * @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}