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.SortKey; 026import org.apache.directory.api.ldap.model.message.controls.SortRequest; 027 028 029/** 030 * Container for SortRequestControl. 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 */ 034public class SortRequestContainer extends AbstractContainer 035{ 036 /** the sort request control decorator */ 037 private SortRequestDecorator control; 038 039 /** the LDAP codec */ 040 private LdapApiService codec; 041 042 /** current key that is being decoded */ 043 private SortKey currentKey; 044 045 046 /** 047 * Creates a new instance of SortRequestContainer. 048 * 049 * @param codec the LDAP codec 050 */ 051 public SortRequestContainer( LdapApiService codec ) 052 { 053 super(); 054 this.codec = codec; 055 setGrammar( SortRequestGrammar.getInstance() ); 056 setTransition( SortRequestStates.START_STATE ); 057 } 058 059 060 /** 061 * Creates a new instance of SortRequestContainer. 062 * 063 * @param codec the LDAP codec 064 * @param control the sort request control 065 */ 066 public SortRequestContainer( LdapApiService codec, SortRequest control ) 067 { 068 this( codec ); 069 decorate( control ); 070 } 071 072 073 /** 074 * Decorate a SortRequest control 075 * 076 * @param control The control to decorate 077 */ 078 public void decorate( SortRequest control ) 079 { 080 if ( control instanceof SortRequestDecorator ) 081 { 082 this.control = ( SortRequestDecorator ) control; 083 } 084 else 085 { 086 this.control = new SortRequestDecorator( codec, control ); 087 } 088 } 089 090 091 /** 092 * @return the control 093 */ 094 public SortRequestDecorator getControl() 095 { 096 return control; 097 } 098 099 100 /** 101 * @param control the control to set 102 */ 103 public void setControl( SortRequestDecorator control ) 104 { 105 this.control = control; 106 } 107 108 109 /** 110 * Clean the container 111 */ 112 @Override 113 public void clean() 114 { 115 super.clean(); 116 control = null; 117 } 118 119 120 /** 121 * @return the currentKey 122 */ 123 public SortKey getCurrentKey() 124 { 125 return currentKey; 126 } 127 128 129 /** 130 * @param currentKey the currentKey to set 131 */ 132 public void setCurrentKey( SortKey currentKey ) 133 { 134 this.currentKey = currentKey; 135 } 136 137}