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