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 * @param codec The LDAP service instance 45 */ 46 public EntryChangeContainer( LdapApiService codec ) 47 { 48 super(); 49 this.codec = codec; 50 setGrammar( EntryChangeGrammar.getInstance() ); 51 setTransition( EntryChangeStates.START_STATE ); 52 } 53 54 55 /** 56 * Creates a container with decorator, optionally decorating the supplied 57 * Control if it is not a decorator implementation. 58 * 59 * @param codec The LDAP service instance 60 * @param control The EntryChange ControlDecorator, or a Control to be 61 * wrapped by a new decorator. 62 */ 63 public EntryChangeContainer( LdapApiService codec, EntryChange control ) 64 { 65 this( codec ); 66 decorate( control ); 67 } 68 69 70 /** 71 * @return Returns the EntryChangeControl. 72 */ 73 public EntryChangeDecorator getEntryChangeDecorator() 74 { 75 return control; 76 } 77 78 79 /** 80 * Checks to see if the supplied EntryChange implementation is a decorator 81 * and if so just sets the EntryChangeDecorator to it. Otherwise the supplied 82 * control is decorated by creating a new EntryChangeDecorator to wrap the 83 * object. 84 * 85 * @param control The EntryChange Control to wrap, if it is not a decorator. 86 */ 87 public void decorate( EntryChange control ) 88 { 89 if ( control instanceof EntryChangeDecorator ) 90 { 91 this.control = ( EntryChangeDecorator ) control; 92 } 93 else 94 { 95 this.control = new EntryChangeDecorator( codec, control ); 96 } 97 } 98 99 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 }