001/* 002 * Copyright 2009-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2009-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) 2009-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.migrate.ldapjdk; 037 038 039 040import java.io.Serializable; 041 042import com.unboundid.ldap.sdk.Modification; 043import com.unboundid.ldap.sdk.ModificationType; 044import com.unboundid.util.NotExtensible; 045import com.unboundid.util.NotMutable; 046import com.unboundid.util.NotNull; 047import com.unboundid.util.ThreadSafety; 048import com.unboundid.util.ThreadSafetyLevel; 049 050 051 052/** 053 * This class provides a data structure that represents an LDAP modification. 054 * <BR><BR> 055 * This class is primarily intended to be used in the process of updating 056 * applications which use the Netscape Directory SDK for Java to switch to or 057 * coexist with the UnboundID LDAP SDK for Java. For applications not written 058 * using the Netscape Directory SDK for Java, the {@link Modification} class 059 * should be used instead. 060 */ 061@NotExtensible() 062@NotMutable() 063@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 064public class LDAPModification 065 implements Serializable 066{ 067 /** 068 * The modification type that indicates that one or more values should be 069 * added to the target attribute. 070 */ 071 public static final int ADD = ModificationType.ADD_INT_VALUE; 072 073 074 075 /** 076 * The modification type that indicates that one or more values should be 077 * removed from the target attribute. 078 */ 079 public static final int DELETE = ModificationType.DELETE_INT_VALUE; 080 081 082 083 /** 084 * The modification type that indicates that one or more values should be 085 * replaced in target attribute. 086 */ 087 public static final int REPLACE = ModificationType.REPLACE_INT_VALUE; 088 089 090 091 /** 092 * The serial version UID for this serializable class. 093 */ 094 private static final long serialVersionUID = 4385895404606128438L; 095 096 097 098 // The modification object for this LDAP modification. 099 @NotNull private final Modification modification; 100 101 102 103 /** 104 * Creates a new LDAP modification with the provided information. 105 * 106 * @param op The type of modification to perform. 107 * @param attr The attribute to use for the modification. 108 */ 109 public LDAPModification(final int op, @NotNull final LDAPAttribute attr) 110 { 111 modification = new Modification(ModificationType.valueOf(op), 112 attr.getName(), attr.getByteValueArray()); 113 } 114 115 116 117 /** 118 * Creates a new LDAP modification from the provided {@link Modification} 119 * object. 120 * 121 * @param modification The {@code Modification} object to use to create this 122 * LDAP modification. 123 */ 124 public LDAPModification(@NotNull final Modification modification) 125 { 126 this.modification = modification; 127 } 128 129 130 131 /** 132 * Retrieves the modification type for this LDAP modification. 133 * 134 * @return The modification type for this LDAP modification. 135 */ 136 public int getOp() 137 { 138 return modification.getModificationType().intValue(); 139 } 140 141 142 143 /** 144 * Retrieves the attribute to include in this modification. 145 * 146 * @return The attribute to include in this modification. 147 */ 148 @NotNull() 149 public LDAPAttribute getAttribute() 150 { 151 return new LDAPAttribute(modification.getAttribute()); 152 } 153 154 155 156 /** 157 * Retrieves a {@link Modification} object that is the equivalent of this LDAP 158 * modification. 159 * 160 * @return A {@code Modification} object that is the equivalent of this LDAP 161 * modification. 162 */ 163 @NotNull() 164 public Modification toModification() 165 { 166 return modification; 167 } 168 169 170 171 /** 172 * Retrieves a string representation of this LDAP modification. 173 * 174 * @return A string representation of this LDAP modification. 175 */ 176 @Override() 177 @NotNull() 178 public String toString() 179 { 180 return modification.toString(); 181 } 182}