001 /* 002 * Copyright 2014-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.extensions; 022 023 024 025 import com.unboundid.asn1.ASN1Element; 026 import com.unboundid.asn1.ASN1OctetString; 027 import com.unboundid.asn1.ASN1Sequence; 028 import com.unboundid.ldap.sdk.Control; 029 import com.unboundid.ldap.sdk.ExtendedRequest; 030 import com.unboundid.ldap.sdk.LDAPException; 031 import com.unboundid.ldap.sdk.ResultCode; 032 import com.unboundid.util.Debug; 033 import com.unboundid.util.NotMutable; 034 import com.unboundid.util.StaticUtils; 035 import com.unboundid.util.ThreadSafety; 036 import com.unboundid.util.ThreadSafetyLevel; 037 import com.unboundid.util.Validator; 038 039 import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 040 041 042 043 /** 044 * <BLOCKQUOTE> 045 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID 046 * LDAP SDK for Java. It is not available for use in applications that 047 * include only the Standard Edition of the LDAP SDK, and is not supported for 048 * use in conjunction with non-UnboundID products. 049 * </BLOCKQUOTE> 050 * This class provides an extended request that may be used to delete a 051 * notification subscription. The request has an OID of 052 * 1.3.6.1.4.1.30221.2.6.39 and a value with the following encoding: 053 * <BR><BR> 054 * <PRE> 055 * DeleteNotificationSubscriptionRequest ::= SEQUENCE { 056 * notificationManagerID OCTET STRING, 057 * notificationDestinationID OCTET STRING, 058 * notificationSubscriptionID OCTET STRING } 059 * </PRE> 060 */ 061 @NotMutable() 062 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 063 public final class DeleteNotificationSubscriptionExtendedRequest 064 extends ExtendedRequest 065 { 066 /** 067 * The OID (1.3.6.1.4.1.30221.2.6.39) for the delete notification subscription 068 * extended request. 069 */ 070 public static final String DELETE_NOTIFICATION_SUBSCRIPTION_REQUEST_OID = 071 "1.3.6.1.4.1.30221.2.6.39"; 072 073 074 075 /** 076 * The serial version UID for this serializable class. 077 */ 078 private static final long serialVersionUID = 914822438877247L; 079 080 081 082 // The notification destination ID. 083 private final String destinationID; 084 085 // The notification manager ID. 086 private final String managerID; 087 088 // The notification subscription ID. 089 private final String subscriptionID; 090 091 092 093 /** 094 * Creates a new delete notification subscription extended request with the 095 * provided information. 096 * 097 * @param managerID The notification manager ID. It must not be 098 * {@code null}. 099 * @param destinationID The notification destination ID. It must not be 100 * {@code null}. 101 * @param subscriptionID The notification destination ID. It must not be 102 * {@code null}. 103 * @param controls The set of controls to include in the request. 104 * It may be {@code null} or empty if no controls 105 * are needed. 106 */ 107 public DeleteNotificationSubscriptionExtendedRequest(final String managerID, 108 final String destinationID, final String subscriptionID, 109 final Control... controls) 110 { 111 super(DELETE_NOTIFICATION_SUBSCRIPTION_REQUEST_OID, 112 encodeValue(managerID, destinationID, subscriptionID), controls); 113 114 this.managerID = managerID; 115 this.destinationID = destinationID; 116 this.subscriptionID = subscriptionID; 117 } 118 119 120 121 /** 122 * Creates a new delete notification subscription extended request from the 123 * provided generic extended request. 124 * 125 * @param extendedRequest The generic extended request to use to create this 126 * delete notification destination extended request. 127 * 128 * @throws LDAPException If a problem occurs while decoding the request. 129 */ 130 public DeleteNotificationSubscriptionExtendedRequest( 131 final ExtendedRequest extendedRequest) 132 throws LDAPException 133 { 134 super(extendedRequest); 135 136 final ASN1OctetString value = extendedRequest.getValue(); 137 if (value == null) 138 { 139 throw new LDAPException(ResultCode.DECODING_ERROR, 140 ERR_DEL_NOTIFICATION_SUB_REQ_DECODE_NO_VALUE.get()); 141 } 142 143 try 144 { 145 final ASN1Element[] elements = 146 ASN1Sequence.decodeAsSequence(value.getValue()).elements(); 147 managerID = 148 ASN1OctetString.decodeAsOctetString(elements[0]).stringValue(); 149 destinationID = 150 ASN1OctetString.decodeAsOctetString(elements[1]).stringValue(); 151 subscriptionID = 152 ASN1OctetString.decodeAsOctetString(elements[2]).stringValue(); 153 } 154 catch (final Exception e) 155 { 156 Debug.debugException(e); 157 throw new LDAPException(ResultCode.DECODING_ERROR, 158 ERR_DEL_NOTIFICATION_SUB_REQ_ERROR_DECODING_VALUE.get( 159 StaticUtils.getExceptionMessage(e)), 160 e); 161 } 162 } 163 164 165 166 /** 167 * Encodes the provided information into an ASN.1 octet string suitable for 168 * use as the value of this extended request. 169 * 170 * @param managerID The notification manager ID. It must not be 171 * {@code null}. 172 * @param destinationID The notification destination ID. It must not be 173 * {@code null}. 174 * @param subscriptionID The notification destination ID. It must not be 175 * {@code null}. 176 * 177 * @return The ASN.1 octet string containing the encoded value. 178 */ 179 private static ASN1OctetString encodeValue(final String managerID, 180 final String destinationID, final String subscriptionID) 181 { 182 Validator.ensureNotNull(managerID); 183 Validator.ensureNotNull(destinationID); 184 Validator.ensureNotNull(subscriptionID); 185 186 final ASN1Sequence valueSequence = new ASN1Sequence( 187 new ASN1OctetString(managerID), 188 new ASN1OctetString(destinationID), 189 new ASN1OctetString(subscriptionID)); 190 return new ASN1OctetString(valueSequence.encode()); 191 } 192 193 194 195 /** 196 * Retrieves the notification manager ID. 197 * 198 * @return The notification manager ID. 199 */ 200 public String getManagerID() 201 { 202 return managerID; 203 } 204 205 206 207 /** 208 * Retrieves the notification destination ID. 209 * 210 * @return The notification destination ID. 211 */ 212 public String getDestinationID() 213 { 214 return destinationID; 215 } 216 217 218 219 /** 220 * Retrieves the notification subscription ID. 221 * 222 * @return The notification subscription ID. 223 */ 224 public String getSubscriptionID() 225 { 226 return subscriptionID; 227 } 228 229 230 231 /** 232 * {@inheritDoc} 233 */ 234 @Override() 235 public DeleteNotificationSubscriptionExtendedRequest duplicate() 236 { 237 return duplicate(getControls()); 238 } 239 240 241 242 /** 243 * {@inheritDoc} 244 */ 245 @Override() 246 public DeleteNotificationSubscriptionExtendedRequest 247 duplicate(final Control[] controls) 248 { 249 final DeleteNotificationSubscriptionExtendedRequest r = 250 new DeleteNotificationSubscriptionExtendedRequest(managerID, 251 destinationID, subscriptionID, controls); 252 r.setResponseTimeoutMillis(getResponseTimeoutMillis(null)); 253 return r; 254 } 255 256 257 258 /** 259 * {@inheritDoc} 260 */ 261 @Override() 262 public String getExtendedRequestName() 263 { 264 return INFO_EXTENDED_REQUEST_NAME_DEL_NOTIFICATION_SUB.get(); 265 } 266 267 268 269 /** 270 * {@inheritDoc} 271 */ 272 @Override() 273 public void toString(final StringBuilder buffer) 274 { 275 buffer.append("DeleteNotificationSubscriptionExtendedRequest(managerID='"); 276 buffer.append(managerID); 277 buffer.append("', destinationID='"); 278 buffer.append(destinationID); 279 buffer.append("', subscriptionID='"); 280 buffer.append(subscriptionID); 281 buffer.append('\''); 282 283 final Control[] controls = getControls(); 284 if (controls.length > 0) 285 { 286 buffer.append(", controls={"); 287 for (int i=0; i < controls.length; i++) 288 { 289 if (i > 0) 290 { 291 buffer.append(", "); 292 } 293 294 buffer.append(controls[i]); 295 } 296 buffer.append('}'); 297 } 298 299 buffer.append(')'); 300 } 301 }