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