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.entryChange; 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.EntryChange; 26 27 28 /** 29 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 30 */ 31 public class EntryChangeContainer extends AbstractContainer 32 { 33 /** EntryChangeControl */ 34 private EntryChangeDecorator control; 35 36 /** The codec that encodes and decodes */ 37 private LdapApiService codec; 38 39 40 /** 41 * Creates a new EntryChangeContainer object. We will store one 42 * grammar, it's enough ... 43 */ 44 public EntryChangeContainer( LdapApiService codec ) 45 { 46 super(); 47 this.codec = codec; 48 grammar = EntryChangeGrammar.getInstance(); 49 setTransition( EntryChangeStates.START_STATE ); 50 } 51 52 53 /** 54 * Creates a container with decorator, optionally decorating the supplied 55 * Control if it is not a decorator implementation. 56 * 57 * @param control The EntryChange ControlDecorator, or a Control to be 58 * wrapped by a new decorator. 59 */ 60 public EntryChangeContainer( LdapApiService codec, EntryChange control ) 61 { 62 this( codec ); 63 decorate( control ); 64 } 65 66 67 /** 68 * @return Returns the EntryChangeControl. 69 */ 70 public EntryChangeDecorator getEntryChangeDecorator() 71 { 72 return control; 73 } 74 75 76 /** 77 * Checks to see if the supplied EntryChange implementation is a decorator 78 * and if so just sets the EntryChangeDecorator to it. Otherwise the supplied 79 * control is decorated by creating a new EntryChangeDecorator to wrap the 80 * object. 81 * 82 * @param control The EntryChange Control to wrap, if it is not a decorator. 83 */ 84 public void decorate( EntryChange control ) 85 { 86 if ( control instanceof EntryChangeDecorator ) 87 { 88 this.control = ( EntryChangeDecorator ) control; 89 } 90 else 91 { 92 this.control = new EntryChangeDecorator( codec, control ); 93 } 94 } 95 96 97 /** 98 * Set a EntryChangeControl Object into the container. It will be completed 99 * 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 }