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 destination. The request has an OID of 1.3.6.1.4.1.30221.2.6.37
052 * and a value with the following encoding:
053 * <BR><BR>
054 * <PRE>
055 * DeleteNotificationDestinationRequest ::= SEQUENCE {
056 * notificationManagerID OCTET STRING,
057 * notificationDestinationID OCTET STRING }
058 * </PRE>
059 */
060 @NotMutable()
061 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
062 public final class DeleteNotificationDestinationExtendedRequest
063 extends ExtendedRequest
064 {
065 /**
066 * The OID (1.3.6.1.4.1.30221.2.6.37) for the delete notification destination
067 * extended request.
068 */
069 public static final String DELETE_NOTIFICATION_DESTINATION_REQUEST_OID =
070 "1.3.6.1.4.1.30221.2.6.37";
071
072
073
074 /**
075 * The serial version UID for this serializable class.
076 */
077 private static final long serialVersionUID = -2644432176543980784L;
078
079
080
081 // The notification destination ID.
082 private final String destinationID;
083
084 // The notification manager ID.
085 private final String managerID;
086
087
088
089 /**
090 * Creates a new delete notification destination extended request with the
091 * provided information.
092 *
093 * @param managerID The notification manager ID. It must not be
094 * {@code null}.
095 * @param destinationID The notification destination ID. It must not be
096 * {@code null}.
097 * @param controls The set of controls to include in the request.
098 * It may be {@code null} or empty if no controls
099 * are needed.
100 */
101 public DeleteNotificationDestinationExtendedRequest(final String managerID,
102 final String destinationID, final Control... controls)
103 {
104 super(DELETE_NOTIFICATION_DESTINATION_REQUEST_OID,
105 encodeValue(managerID, destinationID), controls);
106
107 this.managerID = managerID;
108 this.destinationID = destinationID;
109 }
110
111
112
113 /**
114 * Creates a new delete notification destination extended request from the
115 * provided generic extended request.
116 *
117 * @param extendedRequest The generic extended request to use to create this
118 * delete notification destination extended request.
119 *
120 * @throws LDAPException If a problem occurs while decoding the request.
121 */
122 public DeleteNotificationDestinationExtendedRequest(
123 final ExtendedRequest extendedRequest)
124 throws LDAPException
125 {
126 super(extendedRequest);
127
128 final ASN1OctetString value = extendedRequest.getValue();
129 if (value == null)
130 {
131 throw new LDAPException(ResultCode.DECODING_ERROR,
132 ERR_DEL_NOTIFICATION_DEST_REQ_DECODE_NO_VALUE.get());
133 }
134
135 try
136 {
137 final ASN1Element[] elements =
138 ASN1Sequence.decodeAsSequence(value.getValue()).elements();
139 managerID =
140 ASN1OctetString.decodeAsOctetString(elements[0]).stringValue();
141 destinationID =
142 ASN1OctetString.decodeAsOctetString(elements[1]).stringValue();
143 }
144 catch (final Exception e)
145 {
146 Debug.debugException(e);
147 throw new LDAPException(ResultCode.DECODING_ERROR,
148 ERR_DEL_NOTIFICATION_DEST_REQ_ERROR_DECODING_VALUE.get(
149 StaticUtils.getExceptionMessage(e)),
150 e);
151 }
152 }
153
154
155
156 /**
157 * Encodes the provided information into an ASN.1 octet string suitable for
158 * use as the value of this extended request.
159 *
160 * @param managerID The notification manager ID. It must not be
161 * {@code null}.
162 * @param destinationID The notification destination ID. It must not be
163 * {@code null}.
164 *
165 * @return The ASN.1 octet string containing the encoded value.
166 */
167 private static ASN1OctetString encodeValue(final String managerID,
168 final String destinationID)
169 {
170 Validator.ensureNotNull(managerID);
171 Validator.ensureNotNull(destinationID);
172
173 final ASN1Sequence valueSequence = new ASN1Sequence(
174 new ASN1OctetString(managerID),
175 new ASN1OctetString(destinationID));
176 return new ASN1OctetString(valueSequence.encode());
177 }
178
179
180
181 /**
182 * Retrieves the notification manager ID.
183 *
184 * @return The notification manager ID.
185 */
186 public String getManagerID()
187 {
188 return managerID;
189 }
190
191
192
193 /**
194 * Retrieves the notification destination ID.
195 *
196 * @return The notification destination ID.
197 */
198 public String getDestinationID()
199 {
200 return destinationID;
201 }
202
203
204
205 /**
206 * {@inheritDoc}
207 */
208 @Override()
209 public DeleteNotificationDestinationExtendedRequest duplicate()
210 {
211 return duplicate(getControls());
212 }
213
214
215
216 /**
217 * {@inheritDoc}
218 */
219 @Override()
220 public DeleteNotificationDestinationExtendedRequest
221 duplicate(final Control[] controls)
222 {
223 final DeleteNotificationDestinationExtendedRequest r =
224 new DeleteNotificationDestinationExtendedRequest(managerID,
225 destinationID, controls);
226 r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
227 return r;
228 }
229
230
231
232 /**
233 * {@inheritDoc}
234 */
235 @Override()
236 public String getExtendedRequestName()
237 {
238 return INFO_EXTENDED_REQUEST_NAME_DEL_NOTIFICATION_DEST.get();
239 }
240
241
242
243 /**
244 * {@inheritDoc}
245 */
246 @Override()
247 public void toString(final StringBuilder buffer)
248 {
249 buffer.append("DeleteNotificationDestinationExtendedRequest(managerID='");
250 buffer.append(managerID);
251 buffer.append("', destinationID='");
252 buffer.append(destinationID);
253 buffer.append('\'');
254
255 final Control[] controls = getControls();
256 if (controls.length > 0)
257 {
258 buffer.append(", controls={");
259 for (int i=0; i < controls.length; i++)
260 {
261 if (i > 0)
262 {
263 buffer.append(", ");
264 }
265
266 buffer.append(controls[i]);
267 }
268 buffer.append('}');
269 }
270
271 buffer.append(')');
272 }
273 }