001 /* 002 * Copyright 2009-2015 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005 /* 006 * Copyright (C) 2015 UnboundID Corp. 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 */ 021 package com.unboundid.ldap.sdk.unboundidds.controls; 022 023 024 025 import com.unboundid.asn1.ASN1OctetString; 026 import com.unboundid.ldap.sdk.Control; 027 import com.unboundid.ldap.sdk.DecodeableControl; 028 import com.unboundid.ldap.sdk.LDAPException; 029 import com.unboundid.ldap.sdk.LDAPResult; 030 import com.unboundid.ldap.sdk.ResultCode; 031 import com.unboundid.util.NotMutable; 032 import com.unboundid.util.ThreadSafety; 033 import com.unboundid.util.ThreadSafetyLevel; 034 035 import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 036 037 038 039 /** 040 * <BLOCKQUOTE> 041 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID 042 * LDAP SDK for Java. It is not available for use in applications that 043 * include only the Standard Edition of the LDAP SDK, and is not supported for 044 * use in conjunction with non-UnboundID products. 045 * </BLOCKQUOTE> 046 * This class provides an implementation of the unsolicited cancel response 047 * control, which may be returned by the Directory Server if an operation is 048 * canceled by the server without a cancel or abandon request from the client. 049 * This control does not have a value. 050 */ 051 @NotMutable() 052 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 053 public final class UnsolicitedCancelResponseControl 054 extends Control 055 implements DecodeableControl 056 { 057 /** 058 * The OID (1.3.6.1.4.1.30221.2.5.7) for the unsolicited cancel response 059 * control. 060 */ 061 public static final String UNSOLICITED_CANCEL_RESPONSE_OID = 062 "1.3.6.1.4.1.30221.2.5.7"; 063 064 065 066 /** 067 * The serial version UID for this serializable class. 068 */ 069 private static final long serialVersionUID = 36962888392922937L; 070 071 072 073 /** 074 * Creates a new unsolicited cancel response control. 075 */ 076 public UnsolicitedCancelResponseControl() 077 { 078 super(UNSOLICITED_CANCEL_RESPONSE_OID, false, null); 079 } 080 081 082 083 /** 084 * Creates a new account usable response control with the provided 085 * information. 086 * 087 * @param oid The OID for the control. 088 * @param isCritical Indicates whether the control should be marked 089 * critical. 090 * @param value The encoded value for the control. This may be 091 * {@code null} if no value was provided. 092 * 093 * @throws LDAPException If the provided control cannot be decoded as an 094 * account usable response control. 095 */ 096 public UnsolicitedCancelResponseControl(final String oid, 097 final boolean isCritical, 098 final ASN1OctetString value) 099 throws LDAPException 100 { 101 super(oid, isCritical, value); 102 103 if (value != null) 104 { 105 throw new LDAPException(ResultCode.DECODING_ERROR, 106 ERR_UNSOLICITED_CANCEL_RESPONSE_HAS_VALUE.get()); 107 } 108 } 109 110 111 112 /** 113 * {@inheritDoc} 114 */ 115 public UnsolicitedCancelResponseControl decodeControl(final String oid, 116 final boolean isCritical, 117 final ASN1OctetString value) 118 throws LDAPException 119 { 120 return new UnsolicitedCancelResponseControl(oid, isCritical, value); 121 } 122 123 124 125 /** 126 * Extracts an unsolicited cancel response control from the provided result. 127 * 128 * @param result The result from which to retrieve the unsolicited cancel 129 * response control. 130 * 131 * @return The unsolicited cancel response control contained in the provided 132 * result, or {@code null} if the result did not contain an 133 * unsolicited cancel response control. 134 * 135 * @throws LDAPException If a problem is encountered while attempting to 136 * decode the unsolicited cancel response control 137 * contained in the provided result. 138 */ 139 public static UnsolicitedCancelResponseControl get(final LDAPResult result) 140 throws LDAPException 141 { 142 final Control c = 143 result.getResponseControl(UNSOLICITED_CANCEL_RESPONSE_OID); 144 if (c == null) 145 { 146 return null; 147 } 148 149 if (c instanceof UnsolicitedCancelResponseControl) 150 { 151 return (UnsolicitedCancelResponseControl) c; 152 } 153 else 154 { 155 return new UnsolicitedCancelResponseControl(c.getOID(), c.isCritical(), 156 c.getValue()); 157 } 158 } 159 160 161 162 /** 163 * {@inheritDoc} 164 */ 165 @Override() 166 public String getControlName() 167 { 168 return INFO_CONTROL_NAME_UNSOLICITED_CANCEL_RESPONSE.get(); 169 } 170 171 172 173 /** 174 * {@inheritDoc} 175 */ 176 @Override() 177 public void toString(final StringBuilder buffer) 178 { 179 buffer.append("UnsolicitedCancelResponseControl()"); 180 } 181 }