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 * @param codec The LDAP service instance 045 */ 046 public EntryChangeContainer( LdapApiService codec ) 047 { 048 super(); 049 this.codec = codec; 050 setGrammar( EntryChangeGrammar.getInstance() ); 051 setTransition( EntryChangeStates.START_STATE ); 052 } 053 054 055 /** 056 * Creates a container with decorator, optionally decorating the supplied 057 * Control if it is not a decorator implementation. 058 * 059 * @param codec The LDAP service instance 060 * @param control The EntryChange ControlDecorator, or a Control to be 061 * wrapped by a new decorator. 062 */ 063 public EntryChangeContainer( LdapApiService codec, EntryChange control ) 064 { 065 this( codec ); 066 decorate( control ); 067 } 068 069 070 /** 071 * @return Returns the EntryChangeControl. 072 */ 073 public EntryChangeDecorator getEntryChangeDecorator() 074 { 075 return control; 076 } 077 078 079 /** 080 * Checks to see if the supplied EntryChange implementation is a decorator 081 * and if so just sets the EntryChangeDecorator to it. Otherwise the supplied 082 * control is decorated by creating a new EntryChangeDecorator to wrap the 083 * object. 084 * 085 * @param control The EntryChange Control to wrap, if it is not a decorator. 086 */ 087 public void decorate( EntryChange control ) 088 { 089 if ( control instanceof EntryChangeDecorator ) 090 { 091 this.control = ( EntryChangeDecorator ) control; 092 } 093 else 094 { 095 this.control = new EntryChangeDecorator( codec, control ); 096 } 097 } 098 099 100 /** 101 * Set a EntryChangeControl Object into the container. It will be completed 102 * by the ldapDecoder. 103 * 104 * @param control the EntryChangeControl to set. 105 */ 106 public void setEntryChangeDecorator( EntryChangeDecorator control ) 107 { 108 this.control = control; 109 } 110 111 112 /** 113 * Clean the container 114 */ 115 @Override 116 public void clean() 117 { 118 super.clean(); 119 control = null; 120 } 121}