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 * https://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.extras.extended.cancel; 021 022 023import org.apache.directory.api.i18n.I18n; 024import org.apache.directory.api.ldap.model.message.AbstractExtendedResponse; 025import org.apache.directory.api.ldap.model.message.ResultCodeEnum; 026 027 028/** 029 * 030 * The response sent back from the server after the Cancel extended operation is performed. 031 * 032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 033 */ 034public class CancelResponseImpl extends AbstractExtendedResponse implements CancelResponse 035{ 036 /** 037 * Create a new CancelResponse object 038 * @param messageId The messageId 039 * @param rcode the result code 040 */ 041 public CancelResponseImpl( int messageId, ResultCodeEnum rcode ) 042 { 043 super( messageId ); 044 045 switch ( rcode ) 046 { 047 case SUCCESS: 048 case CANCELED: 049 case CANNOT_CANCEL: 050 case NO_SUCH_OPERATION: 051 case TOO_LATE: 052 break; 053 054 default: 055 throw new IllegalArgumentException( I18n.err( I18n.ERR_13503_RESULT_CODE_SHOULD_BE_IN, ResultCodeEnum.SUCCESS, 056 ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) ); 057 } 058 059 super.getLdapResult().setMatchedDn( null ); 060 super.getLdapResult().setResultCode( rcode ); 061 } 062 063 064 /** 065 * Create a new CancelResponse instance 066 * 067 * @param messageId The request's messageId 068 */ 069 public CancelResponseImpl( int messageId ) 070 { 071 super( messageId ); 072 super.getLdapResult().setMatchedDn( null ); 073 super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS ); 074 } 075 076 077 /** 078 * Create a new CancelResponse instance 079 */ 080 public CancelResponseImpl() 081 { 082 super( CancelRequest.EXTENSION_OID ); 083 super.getLdapResult().setMatchedDn( null ); 084 super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS ); 085 } 086 087 088 /** 089 * Gets the OID uniquely identifying this extended response (a.k.a. its 090 * name). It's a null value for the Cancel response 091 * 092 * @return the OID of the extended response type. 093 */ 094 @Override 095 public String getResponseName() 096 { 097 return ""; 098 } 099 100 101 /** 102 * {@inheritDoc} 103 */ 104 @Override 105 public int hashCode() 106 { 107 int hash = 37; 108 // Seems simple but look at the equals() method ... 109 hash = hash * 17 + getClass().getName().hashCode(); 110 111 return hash; 112 } 113 114 115 /** 116 * @see Object#equals(Object) 117 */ 118 @Override 119 public boolean equals( Object obj ) 120 { 121 if ( obj == this ) 122 { 123 return true; 124 } 125 126 return obj instanceof CancelResponseImpl; 127 } 128}