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