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