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