001/*
002 * Copyright 2011-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2011-2024 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) 2011-2024 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 com.unboundid.asn1.ASN1Element;
041import com.unboundid.ldap.sdk.LDAPException;
042import com.unboundid.ldap.sdk.ResultCode;
043import com.unboundid.util.Debug;
044import com.unboundid.util.NotExtensible;
045import com.unboundid.util.NotNull;
046import com.unboundid.util.StaticUtils;
047import com.unboundid.util.ThreadSafety;
048import com.unboundid.util.ThreadSafetyLevel;
049import com.unboundid.util.Validator;
050
051import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
052
053
054
055/**
056 * This class defines an API that should be implemented by classes which may
057 * represent a way to pare down the changelog entries that should be returned
058 * (e.g., so that they only include changes to a particular attribute or set of
059 * attributes) when using the {@link GetChangelogBatchExtendedRequest}.
060 * <BR>
061 * <BLOCKQUOTE>
062 *   <B>NOTE:</B>  This class, and other classes within the
063 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
064 *   supported for use against Ping Identity, UnboundID, and
065 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
066 *   for proprietary functionality or for external specifications that are not
067 *   considered stable or mature enough to be guaranteed to work in an
068 *   interoperable way with other types of LDAP servers.
069 * </BLOCKQUOTE>
070 */
071@NotExtensible()
072@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE)
073public abstract class ChangelogBatchChangeSelectionCriteria
074{
075  /**
076   * The outer BER type that should be used for encoded elements that represent
077   * a get changelog batch selection criteria value.
078   */
079  static final byte TYPE_SELECTION_CRITERIA = (byte) 0xA7;
080
081
082
083  /**
084   * Encodes this changelog batch change selection criteria value to an ASN.1
085   * element suitable for inclusion in the get changelog batch extended request.
086   *
087   * @return  An ASN.1 element containing the encoded representation of this
088   *          changelog batch change selection criteria value.
089   */
090  @NotNull()
091  public final ASN1Element encode()
092  {
093    return new ASN1Element(TYPE_SELECTION_CRITERIA,
094         encodeInnerElement().encode());
095  }
096
097
098
099  /**
100   * Encodes the inner element for this changelog batch change selection
101   * criteria to an ASN.1 element.
102   *
103   * @return  The encoded representation of the inner element to include in the
104   *          encoded representation of the changelog batch change selection
105   *          criteria element.
106   */
107  @NotNull()
108  protected abstract ASN1Element encodeInnerElement();
109
110
111
112  /**
113   * Decodes the provided ASN.1 element as a changelog batch change selection
114   * criteria value.
115   *
116   * @param  element  The ASN.1 element to be decoded.  It must not be
117   *                  {@code null}.
118   *
119   * @return  The decoded changelog batch change selection criteria value.
120   *
121   * @throws  LDAPException  If the provided ASN.1 element cannot be decoded as
122   *                         a changelog batch starting point.
123   */
124  @NotNull()
125  public static ChangelogBatchChangeSelectionCriteria decode(
126                     @NotNull final ASN1Element element)
127         throws LDAPException
128  {
129    Validator.ensureNotNull(element);
130
131    // The value of the element is itself an ASN.1 element, and we need to use
132    // its BER type to figure out what type of element it is.
133    final ASN1Element innerElement;
134    try
135    {
136      innerElement = ASN1Element.decode(element.getValue());
137    }
138    catch (final Exception e)
139    {
140      Debug.debugException(e);
141      throw new LDAPException(ResultCode.DECODING_ERROR,
142           ERR_CLBATCH_CHANGE_SELECTION_CRITERIA_DECODE_INNER_FAILURE.get(
143                StaticUtils.getExceptionMessage(e)),
144           e);
145    }
146
147    switch (innerElement.getType())
148    {
149      case AnyAttributesChangeSelectionCriteria.
150           TYPE_SELECTION_CRITERIA_ANY_ATTRIBUTES:
151        return AnyAttributesChangeSelectionCriteria.decodeInnerElement(
152             innerElement);
153      case AllAttributesChangeSelectionCriteria.
154           TYPE_SELECTION_CRITERIA_ALL_ATTRIBUTES:
155        return AllAttributesChangeSelectionCriteria.decodeInnerElement(
156             innerElement);
157      case IgnoreAttributesChangeSelectionCriteria.
158           TYPE_SELECTION_CRITERIA_IGNORE_ATTRIBUTES:
159        return IgnoreAttributesChangeSelectionCriteria.decodeInnerElement(
160             innerElement);
161      case NotificationDestinationChangeSelectionCriteria.
162           TYPE_SELECTION_CRITERIA_NOTIFICATION_DESTINATION:
163        return NotificationDestinationChangeSelectionCriteria.
164             decodeInnerElement(innerElement);
165      default:
166        throw new LDAPException(ResultCode.DECODING_ERROR,
167             ERR_CLBATCH_CHANGE_SELECTION_CRITERIA_UNKNOWN_TYPE.get(
168                  StaticUtils.toHex(innerElement.getType())));
169    }
170  }
171
172
173
174  /**
175   * Retrieves a string representation of this changelog batch change selection
176   * criteria value.
177   *
178   * @return  A string representation of this changelog batch change selection
179   *          criteria value.
180   */
181  @Override()
182  @NotNull()
183  public final String toString()
184  {
185    final StringBuilder buffer = new StringBuilder();
186    toString(buffer);
187    return buffer.toString();
188  }
189
190
191
192  /**
193   * Appends a string representation of this changelog batch change selection
194   * criteria value to the provided buffer.
195   *
196   * @param  buffer  The buffer to which the information should be appended.
197   */
198  public abstract void toString(@NotNull StringBuilder buffer);
199}