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 java.util.ArrayList; 041import java.util.Collection; 042import java.util.Collections; 043import java.util.Iterator; 044import java.util.List; 045 046import com.unboundid.asn1.ASN1Element; 047import com.unboundid.asn1.ASN1OctetString; 048import com.unboundid.asn1.ASN1Sequence; 049import com.unboundid.ldap.sdk.LDAPException; 050import com.unboundid.ldap.sdk.ResultCode; 051import com.unboundid.util.Debug; 052import com.unboundid.util.NotMutable; 053import com.unboundid.util.NotNull; 054import com.unboundid.util.StaticUtils; 055import com.unboundid.util.ThreadSafety; 056import com.unboundid.util.ThreadSafetyLevel; 057import com.unboundid.util.Validator; 058 059import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 060 061 062 063/** 064 * This class provides an implementation of a get changelog batch change 065 * selection criteria value that indicates that the server should only return 066 * changes which target one or more of the specified attributes. The changes 067 * may target other attributes as well, but at least one of the associated 068 * attributes must be included in the change. 069 * <BR> 070 * <BLOCKQUOTE> 071 * <B>NOTE:</B> This class, and other classes within the 072 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 073 * supported for use against Ping Identity, UnboundID, and 074 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 075 * for proprietary functionality or for external specifications that are not 076 * considered stable or mature enough to be guaranteed to work in an 077 * interoperable way with other types of LDAP servers. 078 * </BLOCKQUOTE> 079 */ 080@NotMutable() 081@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 082public final class AnyAttributesChangeSelectionCriteria 083 extends ChangelogBatchChangeSelectionCriteria 084{ 085 /** 086 * The inner BER type that should be used for encoded elements that represent 087 * an any attributes get changelog batch selection criteria value. 088 */ 089 static final byte TYPE_SELECTION_CRITERIA_ANY_ATTRIBUTES = (byte) 0xA1; 090 091 092 093 // The names of the target attributes. 094 @NotNull private final List<String> attributeNames; 095 096 097 098 /** 099 * Creates a new any attributes change selection criteria value with the 100 * provided set of attribute names. 101 * 102 * @param attributeNames The names of the target attributes for changes that 103 * should be retrieved. It must not be {@code null} 104 * or empty. 105 */ 106 public AnyAttributesChangeSelectionCriteria( 107 @NotNull final String... attributeNames) 108 { 109 this(StaticUtils.toList(attributeNames)); 110 } 111 112 113 114 /** 115 * Creates a new any attributes change selection criteria value with the 116 * provided set of attribute names. 117 * 118 * @param attributeNames The names of the target attributes for changes that 119 * should be retrieved. It must not be {@code null} 120 * or empty. 121 */ 122 public AnyAttributesChangeSelectionCriteria( 123 @NotNull final Collection<String> attributeNames) 124 { 125 Validator.ensureNotNull(attributeNames); 126 Validator.ensureFalse(attributeNames.isEmpty()); 127 128 this.attributeNames = 129 Collections.unmodifiableList(new ArrayList<>(attributeNames)); 130 } 131 132 133 134 /** 135 * Decodes the provided ASN.1 element, which is the inner element of a 136 * changelog batch change selection criteria element, as an any attributes 137 * change selection criteria value. 138 * 139 * @param innerElement The inner element of a changelog batch change 140 * selection criteria element to be decoded. 141 * 142 * @return The decoded any attributes change selection criteria value. 143 * 144 * @throws LDAPException If a problem is encountered while trying to decode 145 * the provided element as the inner element of an any 146 * attributes change selection criteria value. 147 */ 148 @NotNull() 149 static AnyAttributesChangeSelectionCriteria decodeInnerElement( 150 @NotNull final ASN1Element innerElement) 151 throws LDAPException 152 { 153 try 154 { 155 final ASN1Element[] attrElements = 156 ASN1Sequence.decodeAsSequence(innerElement).elements(); 157 final ArrayList<String> attrNames = new ArrayList<>(attrElements.length); 158 for (final ASN1Element e : attrElements) 159 { 160 attrNames.add(ASN1OctetString.decodeAsOctetString(e).stringValue()); 161 } 162 163 return new AnyAttributesChangeSelectionCriteria(attrNames); 164 } 165 catch (final Exception e) 166 { 167 Debug.debugException(e); 168 throw new LDAPException(ResultCode.DECODING_ERROR, 169 ERR_ANY_ATTRS_CHANGE_SELECTION_CRITERIA_DECODE_ERROR.get( 170 StaticUtils.getExceptionMessage(e)), 171 e); 172 } 173 } 174 175 176 177 /** 178 * Retrieves the names of the target attributes for changes that should be 179 * retrieved. 180 * 181 * @return The names of the target attributes for changes that should be 182 * retrieved. 183 */ 184 @NotNull() 185 public List<String> getAttributeNames() 186 { 187 return attributeNames; 188 } 189 190 191 192 /** 193 * {@inheritDoc} 194 */ 195 @Override() 196 @NotNull() 197 public ASN1Element encodeInnerElement() 198 { 199 final ArrayList<ASN1Element> elements = 200 new ArrayList<>(attributeNames.size()); 201 for (final String s : attributeNames) 202 { 203 elements.add(new ASN1OctetString(s)); 204 } 205 206 return new ASN1Sequence(TYPE_SELECTION_CRITERIA_ANY_ATTRIBUTES, elements); 207 } 208 209 210 211 /** 212 * {@inheritDoc} 213 */ 214 @Override() 215 public void toString(@NotNull final StringBuilder buffer) 216 { 217 buffer.append("AnyAttributesChangeSelectionCriteria(attributeNames={"); 218 219 final Iterator<String> iterator = attributeNames.iterator(); 220 while (iterator.hasNext()) 221 { 222 buffer.append(iterator.next()); 223 if (iterator.hasNext()) 224 { 225 buffer.append(','); 226 } 227 } 228 229 buffer.append("})"); 230 } 231}