001/*
002 * Copyright 2009-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2009-2020 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) 2015-2020 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.ThreadSafety;
048import com.unboundid.util.ThreadSafetyLevel;
049
050import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*;
051
052
053
054/**
055 * This class provides an implementation of the unsolicited cancel response
056 * control, which may be returned by the Directory Server if an operation is
057 * canceled by the server without a cancel or abandon request from the client.
058 * This control does not have a value.
059 * <BR>
060 * <BLOCKQUOTE>
061 *   <B>NOTE:</B>  This class, and other classes within the
062 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
063 *   supported for use against Ping Identity, UnboundID, and
064 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
065 *   for proprietary functionality or for external specifications that are not
066 *   considered stable or mature enough to be guaranteed to work in an
067 *   interoperable way with other types of LDAP servers.
068 * </BLOCKQUOTE>
069 */
070@NotMutable()
071@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
072public final class UnsolicitedCancelResponseControl
073       extends Control
074       implements DecodeableControl
075{
076  /**
077   * The OID (1.3.6.1.4.1.30221.2.5.7) for the unsolicited cancel response
078   * control.
079   */
080  public static final String UNSOLICITED_CANCEL_RESPONSE_OID =
081       "1.3.6.1.4.1.30221.2.5.7";
082
083
084
085  /**
086   * The serial version UID for this serializable class.
087   */
088  private static final long serialVersionUID = 36962888392922937L;
089
090
091
092  /**
093   * Creates a new unsolicited cancel response control.
094   */
095  public UnsolicitedCancelResponseControl()
096  {
097    super(UNSOLICITED_CANCEL_RESPONSE_OID, false, null);
098  }
099
100
101
102  /**
103   * Creates a new account usable response control with the provided
104   * information.
105   *
106   * @param  oid         The OID for the control.
107   * @param  isCritical  Indicates whether the control should be marked
108   *                     critical.
109   * @param  value       The encoded value for the control.  This may be
110   *                     {@code null} if no value was provided.
111   *
112   * @throws  LDAPException  If the provided control cannot be decoded as an
113   *                         account usable response control.
114   */
115  public UnsolicitedCancelResponseControl(final String oid,
116                                          final boolean isCritical,
117                                          final ASN1OctetString value)
118         throws LDAPException
119  {
120    super(oid, isCritical, value);
121
122    if (value != null)
123    {
124      throw new LDAPException(ResultCode.DECODING_ERROR,
125                              ERR_UNSOLICITED_CANCEL_RESPONSE_HAS_VALUE.get());
126    }
127  }
128
129
130
131  /**
132   * {@inheritDoc}
133   */
134  @Override()
135  public UnsolicitedCancelResponseControl decodeControl(final String oid,
136                                               final boolean isCritical,
137                                               final ASN1OctetString value)
138         throws LDAPException
139  {
140    return new UnsolicitedCancelResponseControl(oid, isCritical, value);
141  }
142
143
144
145  /**
146   * Extracts an unsolicited cancel response control from the provided result.
147   *
148   * @param  result  The result from which to retrieve the unsolicited cancel
149   *                 response control.
150   *
151   * @return  The unsolicited cancel response control contained in the provided
152   *          result, or {@code null} if the result did not contain an
153   *          unsolicited cancel response control.
154   *
155   * @throws  LDAPException  If a problem is encountered while attempting to
156   *                         decode the unsolicited cancel response control
157   *                         contained in the provided result.
158   */
159  public static UnsolicitedCancelResponseControl get(final LDAPResult result)
160         throws LDAPException
161  {
162    final Control c =
163         result.getResponseControl(UNSOLICITED_CANCEL_RESPONSE_OID);
164    if (c == null)
165    {
166      return null;
167    }
168
169    if (c instanceof UnsolicitedCancelResponseControl)
170    {
171      return (UnsolicitedCancelResponseControl) c;
172    }
173    else
174    {
175      return new UnsolicitedCancelResponseControl(c.getOID(), c.isCritical(),
176           c.getValue());
177    }
178  }
179
180
181
182  /**
183   * {@inheritDoc}
184   */
185  @Override()
186  public String getControlName()
187  {
188    return INFO_CONTROL_NAME_UNSOLICITED_CANCEL_RESPONSE.get();
189  }
190
191
192
193  /**
194   * {@inheritDoc}
195   */
196  @Override()
197  public void toString(final StringBuilder buffer)
198  {
199    buffer.append("UnsolicitedCancelResponseControl()");
200  }
201}