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