001/* 002 * Copyright 2009-2022 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2009-2022 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2009-2022 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.sdk.unboundidds.controls; 037 038 039 040import com.unboundid.asn1.ASN1OctetString; 041import com.unboundid.ldap.sdk.Control; 042import com.unboundid.ldap.sdk.DecodeableControl; 043import com.unboundid.ldap.sdk.LDAPException; 044import com.unboundid.ldap.sdk.LDAPResult; 045import com.unboundid.ldap.sdk.ResultCode; 046import com.unboundid.util.NotMutable; 047import com.unboundid.util.NotNull; 048import com.unboundid.util.Nullable; 049import com.unboundid.util.ThreadSafety; 050import com.unboundid.util.ThreadSafetyLevel; 051 052import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 053 054 055 056/** 057 * This class provides an implementation of the unsolicited cancel response 058 * control, which may be returned by the Directory Server if an operation is 059 * canceled by the server without a cancel or abandon request from the client. 060 * This control does not have a value. 061 * <BR> 062 * <BLOCKQUOTE> 063 * <B>NOTE:</B> This class, and other classes within the 064 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 065 * supported for use against Ping Identity, UnboundID, and 066 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 067 * for proprietary functionality or for external specifications that are not 068 * considered stable or mature enough to be guaranteed to work in an 069 * interoperable way with other types of LDAP servers. 070 * </BLOCKQUOTE> 071 */ 072@NotMutable() 073@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 074public final class UnsolicitedCancelResponseControl 075 extends Control 076 implements DecodeableControl 077{ 078 /** 079 * The OID (1.3.6.1.4.1.30221.2.5.7) for the unsolicited cancel response 080 * control. 081 */ 082 @NotNull public static final String UNSOLICITED_CANCEL_RESPONSE_OID = 083 "1.3.6.1.4.1.30221.2.5.7"; 084 085 086 087 /** 088 * The serial version UID for this serializable class. 089 */ 090 private static final long serialVersionUID = 36962888392922937L; 091 092 093 094 /** 095 * Creates a new unsolicited cancel response control. 096 */ 097 public UnsolicitedCancelResponseControl() 098 { 099 super(UNSOLICITED_CANCEL_RESPONSE_OID, false, null); 100 } 101 102 103 104 /** 105 * Creates a new account usable response control with the provided 106 * information. 107 * 108 * @param oid The OID for the control. 109 * @param isCritical Indicates whether the control should be marked 110 * critical. 111 * @param value The encoded value for the control. This may be 112 * {@code null} if no value was provided. 113 * 114 * @throws LDAPException If the provided control cannot be decoded as an 115 * account usable response control. 116 */ 117 public UnsolicitedCancelResponseControl(@NotNull final String oid, 118 final boolean isCritical, 119 @Nullable final ASN1OctetString value) 120 throws LDAPException 121 { 122 super(oid, isCritical, value); 123 124 if (value != null) 125 { 126 throw new LDAPException(ResultCode.DECODING_ERROR, 127 ERR_UNSOLICITED_CANCEL_RESPONSE_HAS_VALUE.get()); 128 } 129 } 130 131 132 133 /** 134 * {@inheritDoc} 135 */ 136 @Override() 137 @NotNull() 138 public UnsolicitedCancelResponseControl decodeControl( 139 @NotNull final String oid, 140 final boolean isCritical, 141 @Nullable final ASN1OctetString value) 142 throws LDAPException 143 { 144 return new UnsolicitedCancelResponseControl(oid, isCritical, value); 145 } 146 147 148 149 /** 150 * Extracts an unsolicited cancel response control from the provided result. 151 * 152 * @param result The result from which to retrieve the unsolicited cancel 153 * response control. 154 * 155 * @return The unsolicited cancel response control contained in the provided 156 * result, or {@code null} if the result did not contain an 157 * unsolicited cancel response control. 158 * 159 * @throws LDAPException If a problem is encountered while attempting to 160 * decode the unsolicited cancel response control 161 * contained in the provided result. 162 */ 163 @Nullable() 164 public static UnsolicitedCancelResponseControl get( 165 @NotNull final LDAPResult result) 166 throws LDAPException 167 { 168 final Control c = 169 result.getResponseControl(UNSOLICITED_CANCEL_RESPONSE_OID); 170 if (c == null) 171 { 172 return null; 173 } 174 175 if (c instanceof UnsolicitedCancelResponseControl) 176 { 177 return (UnsolicitedCancelResponseControl) c; 178 } 179 else 180 { 181 return new UnsolicitedCancelResponseControl(c.getOID(), c.isCritical(), 182 c.getValue()); 183 } 184 } 185 186 187 188 /** 189 * {@inheritDoc} 190 */ 191 @Override() 192 @NotNull() 193 public String getControlName() 194 { 195 return INFO_CONTROL_NAME_UNSOLICITED_CANCEL_RESPONSE.get(); 196 } 197 198 199 200 /** 201 * {@inheritDoc} 202 */ 203 @Override() 204 public void toString(@NotNull final StringBuilder buffer) 205 { 206 buffer.append("UnsolicitedCancelResponseControl()"); 207 } 208}