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.entryChange; 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.EntryChange; 026 027 028/** 029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 030 */ 031public class EntryChangeContainer extends AbstractContainer 032{ 033 /** EntryChangeControl */ 034 private EntryChangeDecorator control; 035 036 /** The codec that encodes and decodes */ 037 private LdapApiService codec; 038 039 040 /** 041 * Creates a new EntryChangeContainer object. We will store one 042 * grammar, it's enough ... 043 */ 044 public EntryChangeContainer( LdapApiService codec ) 045 { 046 super(); 047 this.codec = codec; 048 grammar = EntryChangeGrammar.getInstance(); 049 setTransition( EntryChangeStates.START_STATE ); 050 } 051 052 053 /** 054 * Creates a container with decorator, optionally decorating the supplied 055 * Control if it is not a decorator implementation. 056 * 057 * @param control The EntryChange ControlDecorator, or a Control to be 058 * wrapped by a new decorator. 059 */ 060 public EntryChangeContainer( LdapApiService codec, EntryChange control ) 061 { 062 this( codec ); 063 decorate( control ); 064 } 065 066 067 /** 068 * @return Returns the EntryChangeControl. 069 */ 070 public EntryChangeDecorator getEntryChangeDecorator() 071 { 072 return control; 073 } 074 075 076 /** 077 * Checks to see if the supplied EntryChange implementation is a decorator 078 * and if so just sets the EntryChangeDecorator to it. Otherwise the supplied 079 * control is decorated by creating a new EntryChangeDecorator to wrap the 080 * object. 081 * 082 * @param control The EntryChange Control to wrap, if it is not a decorator. 083 */ 084 public void decorate( EntryChange control ) 085 { 086 if ( control instanceof EntryChangeDecorator ) 087 { 088 this.control = ( EntryChangeDecorator ) control; 089 } 090 else 091 { 092 this.control = new EntryChangeDecorator( codec, control ); 093 } 094 } 095 096 097 /** 098 * Set a EntryChangeControl Object into the container. It will be completed 099 * by the ldapDecoder. 100 * 101 * @param control the EntryChangeControl to set. 102 */ 103 public void setEntryChangeDecorator( EntryChangeDecorator control ) 104 { 105 this.control = control; 106 } 107 108 109 /** 110 * Clean the container 111 */ 112 public void clean() 113 { 114 super.clean(); 115 control = null; 116 } 117}