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 java.io.Serializable;
026 import java.util.ArrayList;
027 import java.util.Collection;
028 import java.util.Collections;
029 import java.util.Iterator;
030 import java.util.List;
031
032 import com.unboundid.asn1.ASN1OctetString;
033 import com.unboundid.util.NotMutable;
034 import com.unboundid.util.ThreadSafety;
035 import com.unboundid.util.ThreadSafetyLevel;
036 import com.unboundid.util.Validator;
037
038
039
040 /**
041 * <BLOCKQUOTE>
042 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID
043 * LDAP SDK for Java. It is not available for use in applications that
044 * include only the Standard Edition of the LDAP SDK, and is not supported for
045 * use in conjunction with non-UnboundID products.
046 * </BLOCKQUOTE>
047 * This class represents a data structure with information about a notification
048 * destination defined in an UnboundID server instance.
049 */
050 @NotMutable()
051 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
052 public final class NotificationDestinationDetails
053 implements Serializable
054 {
055 /**
056 * The serial version UID for this serializable class.
057 */
058 private static final long serialVersionUID = -6596207374277234834L;
059
060
061
062 // The encoded details for this notification destination.
063 private final List<ASN1OctetString> details;
064
065 // The subscriptions defined for this notification destination.
066 private final List<NotificationSubscriptionDetails> subscriptions;
067
068 // The unique ID for this notification destination.
069 private final String id;
070
071
072
073 /**
074 * Creates a new notification destination details object with the provided
075 * information.
076 *
077 * @param id The unique ID for this notification destination. It
078 * must not be {@code null}.
079 * @param details The encoded details for this notification
080 * destination. It must not be {@code null} or empty.
081 * @param subscriptions The subscriptions defined for this notification
082 * destination. It may be {@code null} or empty if
083 * there are no subscriptions for this destination.
084 */
085 public NotificationDestinationDetails(final String id,
086 final Collection<ASN1OctetString> details,
087 final Collection<NotificationSubscriptionDetails> subscriptions)
088 {
089 Validator.ensureNotNull(id);
090 Validator.ensureNotNull(details);
091 Validator.ensureFalse(details.isEmpty());
092
093 this.id = id;
094 this.details =
095 Collections.unmodifiableList(new ArrayList<ASN1OctetString>(details));
096
097 if (subscriptions == null)
098 {
099 this.subscriptions = Collections.emptyList();
100 }
101 else
102 {
103 this.subscriptions = Collections.unmodifiableList(
104 new ArrayList<NotificationSubscriptionDetails>(subscriptions));
105 }
106 }
107
108
109
110 /**
111 * Retrieves the unique ID for this destination details object.
112 *
113 * @return The unique ID for this destination details object.
114 */
115 public String getID()
116 {
117 return id;
118 }
119
120
121
122 /**
123 * Retrieves the encoded details for this destination details object.
124 *
125 * @return The encoded details for this destination details object.
126 */
127 public List<ASN1OctetString> getDetails()
128 {
129 return details;
130 }
131
132
133
134 /**
135 * Retrieves the subscriptions defined for this notification destination, if
136 * any.
137 *
138 * @return The subscriptions defined for this notification destination, or
139 * an empty list if there are no subscriptions for this destination.
140 */
141 public List<NotificationSubscriptionDetails> getSubscriptions()
142 {
143 return subscriptions;
144 }
145
146
147
148 /**
149 * Retrieves a string representation of this notification subscription details
150 * object.
151 *
152 * @return A string representation of this notification subscription details
153 * object.
154 */
155 @Override()
156 public String toString()
157 {
158 final StringBuilder buffer = new StringBuilder();
159 toString(buffer);
160 return buffer.toString();
161 }
162
163
164
165 /**
166 * Appends a string representation of this notification subscription details
167 * object to the provided buffer.
168 *
169 * @param buffer The buffer to which the information should be appended.
170 */
171 public void toString(final StringBuilder buffer)
172 {
173 buffer.append("NotificationDestination(id='");
174 buffer.append(id);
175 buffer.append("', subscriptionIDs={");
176
177 final Iterator<NotificationSubscriptionDetails> subscriptionIterator =
178 subscriptions.iterator();
179 while (subscriptionIterator.hasNext())
180 {
181 buffer.append('\'');
182 buffer.append(subscriptionIterator.next().getID());
183 buffer.append('\'');
184
185 if (subscriptionIterator.hasNext())
186 {
187 buffer.append(", ");
188 }
189 }
190
191 buffer.append("})");
192 }
193 }