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.model.message; 021 022 023import org.apache.directory.api.i18n.I18n; 024 025 026/** 027 * Implementation of an AbandonRequest message. 028 * 029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 030 */ 031public class AbandonRequestImpl extends AbstractRequest implements AbandonRequest 032{ 033 /** Sequence identifier of the outstanding request message to abandon */ 034 private int abandonId; 035 036 037 /** 038 * Creates an AbandonRequest implementation for an outstanding request. 039 */ 040 public AbandonRequestImpl() 041 { 042 super( -1, TYPE, false ); 043 } 044 045 046 /** 047 * Creates an AbandonRequest implementation for an outstanding request. 048 * 049 * @param abdandonnedId the sequence identifier of the AbandonRequest message. 050 */ 051 public AbandonRequestImpl( final int abdandonnedId ) 052 { 053 super( -1, TYPE, false ); 054 abandonId = abdandonnedId; 055 } 056 057 058 /** 059 * Gets the id of the request operation to terminate. 060 * 061 * @return the id of the request message to abandon 062 */ 063 @Override 064 public int getAbandoned() 065 { 066 return abandonId; 067 } 068 069 070 /** 071 * {@inheritDoc} 072 */ 073 @Override 074 public AbandonRequest setAbandoned( int abandonId ) 075 { 076 this.abandonId = abandonId; 077 078 return this; 079 } 080 081 082 /** 083 * RFC 2251 [Section 4.11]: Abandon, Bind, Unbind, and StartTLS operations 084 * cannot be abandoned. 085 */ 086 public void abandon() 087 { 088 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04185 ) ); 089 } 090 091 092 /** 093 * {@inheritDoc} 094 */ 095 @Override 096 public AbandonRequest setMessageId( int messageId ) 097 { 098 super.setMessageId( messageId ); 099 100 return this; 101 } 102 103 104 /** 105 * {@inheritDoc} 106 */ 107 @Override 108 public AbandonRequest addControl( Control control ) 109 { 110 return ( AbandonRequest ) super.addControl( control ); 111 } 112 113 114 /** 115 * {@inheritDoc} 116 */ 117 @Override 118 public AbandonRequest addAllControls( Control[] controls ) 119 { 120 return ( AbandonRequest ) super.addAllControls( controls ); 121 } 122 123 124 /** 125 * {@inheritDoc} 126 */ 127 @Override 128 public AbandonRequest removeControl( Control control ) 129 { 130 return ( AbandonRequest ) super.removeControl( control ); 131 } 132 133 134 /** 135 * Checks for equality first by asking the super method which should compare 136 * all but the Abandoned request's Id. It then compares this to determine 137 * equality. 138 * 139 * @param obj the object to test for equality to this AbandonRequest 140 * @return true if the obj equals this request, false otherwise 141 */ 142 @Override 143 public boolean equals( Object obj ) 144 { 145 if ( this == obj ) 146 { 147 return true; 148 } 149 150 if ( ( obj == null ) || !( obj instanceof AbandonRequest ) ) 151 { 152 return false; 153 } 154 155 if ( !super.equals( obj ) ) 156 { 157 return false; 158 } 159 160 AbandonRequest req = ( AbandonRequest ) obj; 161 162 return req.getAbandoned() == abandonId; 163 } 164 165 166 /** 167 * @see Object#hashCode() 168 * @return the instance's hash code 169 */ 170 @Override 171 public int hashCode() 172 { 173 int hash = 37; 174 hash = hash * 17 + abandonId; 175 hash = hash * 17 + super.hashCode(); 176 177 return hash; 178 } 179 180 181 /** 182 * Return a String representing an AbandonRequest 183 * 184 * @return A String representing the AbandonRequest 185 */ 186 @Override 187 public String toString() 188 { 189 StringBuilder sb = new StringBuilder(); 190 191 sb.append( " Abandon Request :\n" ); 192 sb.append( " Message Id : " ).append( abandonId ); 193 194 // The controls 195 sb.append( super.toString() ); 196 197 return sb.toString(); 198 } 199}