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