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 public int getAbandoned() 064 { 065 return abandonId; 066 } 067 068 069 /** 070 * {@inheritDoc} 071 */ 072 public AbandonRequest setAbandoned( int abandonId ) 073 { 074 this.abandonId = abandonId; 075 076 return this; 077 } 078 079 080 /** 081 * RFC 2251 [Section 4.11]: Abandon, Bind, Unbind, and StartTLS operations 082 * cannot be abandoned. 083 */ 084 public void abandon() 085 { 086 throw new UnsupportedOperationException( I18n.err( I18n.ERR_04185 ) ); 087 } 088 089 090 /** 091 * {@inheritDoc} 092 */ 093 public AbandonRequest setMessageId( int messageId ) 094 { 095 super.setMessageId( messageId ); 096 097 return this; 098 } 099 100 101 /** 102 * {@inheritDoc} 103 */ 104 public AbandonRequest addControl( Control control ) 105 { 106 return ( AbandonRequest ) super.addControl( control ); 107 } 108 109 110 /** 111 * {@inheritDoc} 112 */ 113 public AbandonRequest addAllControls( Control[] controls ) 114 { 115 return ( AbandonRequest ) super.addAllControls( controls ); 116 } 117 118 119 /** 120 * {@inheritDoc} 121 */ 122 public AbandonRequest removeControl( Control control ) 123 { 124 return ( AbandonRequest ) super.removeControl( control ); 125 } 126 127 128 /** 129 * Checks for equality first by asking the super method which should compare 130 * all but the Abandoned request's Id. It then compares this to determine 131 * equality. 132 * 133 * @param obj the object to test for equality to this AbandonRequest 134 * @return true if the obj equals this request, false otherwise 135 */ 136 public boolean equals( Object obj ) 137 { 138 if ( this == obj ) 139 { 140 return true; 141 } 142 143 if ( ( obj == null ) || !( obj instanceof AbandonRequest ) ) 144 { 145 return false; 146 } 147 148 if ( !super.equals( obj ) ) 149 { 150 return false; 151 } 152 153 AbandonRequest req = ( AbandonRequest ) obj; 154 155 return req.getAbandoned() == abandonId; 156 } 157 158 159 /** 160 * @see Object#hashCode() 161 * @return the instance's hash code 162 */ 163 public int hashCode() 164 { 165 int hash = 37; 166 hash = hash * 17 + abandonId; 167 hash = hash * 17 + super.hashCode(); 168 169 return hash; 170 } 171 172 173 /** 174 * Return a String representing an AbandonRequest 175 * 176 * @return A String representing the AbandonRequest 177 */ 178 public String toString() 179 { 180 StringBuilder sb = new StringBuilder(); 181 182 sb.append( " Abandon Request :\n" ); 183 sb.append( " Message Id : " ).append( abandonId ); 184 185 // The controls 186 sb.append( super.toString() ); 187 188 return sb.toString(); 189 } 190}