001/*
002 * Copyright 2014-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2014-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.extensions;
037
038
039
040import java.io.Serializable;
041import java.util.ArrayList;
042import java.util.Collection;
043import java.util.Collections;
044import java.util.Iterator;
045import java.util.List;
046
047import com.unboundid.asn1.ASN1OctetString;
048import com.unboundid.util.NotMutable;
049import com.unboundid.util.ThreadSafety;
050import com.unboundid.util.ThreadSafetyLevel;
051import com.unboundid.util.Validator;
052
053
054
055/**
056 * This class represents a data structure with information about a notification
057 * destination defined in a Ping Identity, UnboundID, or Nokia/Alcatel-Lucent
058 * 8661 server instance.
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 NotificationDestinationDetails
073       implements Serializable
074{
075  /**
076   * The serial version UID for this serializable class.
077   */
078  private static final long serialVersionUID = -6596207374277234834L;
079
080
081
082  // The encoded details for this notification destination.
083  private final List<ASN1OctetString> details;
084
085  // The subscriptions defined for this notification destination.
086  private final List<NotificationSubscriptionDetails> subscriptions;
087
088  // The unique ID for this notification destination.
089  private final String id;
090
091
092
093  /**
094   * Creates a new notification destination details object with the provided
095   * information.
096   *
097   * @param  id             The unique ID for this notification destination.  It
098   *                        must not be {@code null}.
099   * @param  details        The encoded details for this notification
100   *                        destination.  It must not be {@code null} or empty.
101   * @param  subscriptions  The subscriptions defined for this notification
102   *                        destination.  It may be {@code null} or empty if
103   *                        there are no subscriptions for this destination.
104   */
105  public NotificationDestinationDetails(final String id,
106              final Collection<ASN1OctetString> details,
107              final Collection<NotificationSubscriptionDetails> subscriptions)
108  {
109    Validator.ensureNotNull(id);
110    Validator.ensureNotNull(details);
111    Validator.ensureFalse(details.isEmpty());
112
113    this.id = id;
114    this.details =
115         Collections.unmodifiableList(new ArrayList<>(details));
116
117    if (subscriptions == null)
118    {
119      this.subscriptions = Collections.emptyList();
120    }
121    else
122    {
123      this.subscriptions =
124           Collections.unmodifiableList(new ArrayList<>(subscriptions));
125    }
126  }
127
128
129
130  /**
131   * Retrieves the unique ID for this destination details object.
132   *
133   * @return The unique ID for this destination details object.
134   */
135  public String getID()
136  {
137    return id;
138  }
139
140
141
142  /**
143   * Retrieves the encoded details for this destination details object.
144   *
145   * @return  The encoded details for this destination details object.
146   */
147  public List<ASN1OctetString> getDetails()
148  {
149    return details;
150  }
151
152
153
154  /**
155   * Retrieves the subscriptions defined for this notification destination, if
156   * any.
157   *
158   * @return  The subscriptions defined for this notification destination, or
159   *          an empty list if there are no subscriptions for this destination.
160   */
161  public List<NotificationSubscriptionDetails> getSubscriptions()
162  {
163    return subscriptions;
164  }
165
166
167
168  /**
169   * Retrieves a string representation of this notification subscription details
170   * object.
171   *
172   * @return  A string representation of this notification subscription details
173   *          object.
174   */
175  @Override()
176  public String toString()
177  {
178    final StringBuilder buffer = new StringBuilder();
179    toString(buffer);
180    return buffer.toString();
181  }
182
183
184
185  /**
186   * Appends a string representation of this notification subscription details
187   * object to the provided buffer.
188   *
189   * @param  buffer  The buffer to which the information should be appended.
190   */
191  public void toString(final StringBuilder buffer)
192  {
193    buffer.append("NotificationDestination(id='");
194    buffer.append(id);
195    buffer.append("', subscriptionIDs={");
196
197    final Iterator<NotificationSubscriptionDetails> subscriptionIterator =
198         subscriptions.iterator();
199    while (subscriptionIterator.hasNext())
200    {
201      buffer.append('\'');
202      buffer.append(subscriptionIterator.next().getID());
203      buffer.append('\'');
204
205      if (subscriptionIterator.hasNext())
206      {
207        buffer.append(", ");
208      }
209    }
210
211    buffer.append("})");
212  }
213}