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.sort; 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.SortResponse; 026 027 028/** 029 * Container for SortResponseControl. 030 * 031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 032 */ 033public class SortResponseContainer extends AbstractContainer 034{ 035 /** the decorator instance of sort response control */ 036 private SortResponseDecorator control; 037 038 /** LDAP codec */ 039 private LdapApiService codec; 040 041 042 /** 043 * Creates a new instance of SortResponseContainer. 044 * 045 * @param codec the LDAP codec 046 */ 047 public SortResponseContainer( LdapApiService codec ) 048 { 049 super(); 050 this.codec = codec; 051 setGrammar( SortResponseGrammar.getInstance() ); 052 setTransition( SortResponseStates.START_STATE ); 053 } 054 055 056 /** 057 * Creates a new instance of SortResponseContainer. 058 * 059 * @param codec the LDAP codec 060 * @param control the sort response control 061 */ 062 public SortResponseContainer( LdapApiService codec, SortResponse control ) 063 { 064 this( codec ); 065 decorate( control ); 066 } 067 068 069 /** 070 * Decorate the SortResponse control 071 * 072 * @param control The Sort Response control to decorate 073 */ 074 public void decorate( SortResponse control ) 075 { 076 if ( control instanceof SortResponseDecorator ) 077 { 078 this.control = ( SortResponseDecorator ) control; 079 } 080 else 081 { 082 this.control = new SortResponseDecorator( codec, control ); 083 } 084 } 085 086 087 /** 088 * @return the control 089 */ 090 public SortResponseDecorator getControl() 091 { 092 return control; 093 } 094 095 096 /** 097 * @param control the control to set 098 */ 099 public void setControl( SortResponseDecorator control ) 100 { 101 this.control = control; 102 } 103 104 105 /** 106 * Clean the container 107 */ 108 @Override 109 public void clean() 110 { 111 super.clean(); 112 control = null; 113 } 114}