001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027package org.opends.server.types; 028 029import org.forgerock.opendj.ldap.ModificationType; 030 031/** 032 * This class defines a data structure for storing and interacting 033 * with a modification that may be requested of an entry in the Directory Server. 034 */ 035@org.opends.server.types.PublicAPI( 036 stability=org.opends.server.types.StabilityLevel.UNCOMMITTED, 037 mayInstantiate=true, 038 mayExtend=false, 039 mayInvoke=true) 040public final class Modification 041{ 042 /** The attribute for this modification. */ 043 private Attribute attribute; 044 045 /** 046 * Indicates whether this modification was generated by internal processing 047 * and therefore should not be subject to no-user-modification and related checks. 048 */ 049 private boolean isInternal; 050 051 /** The modification type for this modification. */ 052 private ModificationType modificationType; 053 054 /** 055 * Creates a new modification with the provided information. 056 * 057 * @param modificationType The modification type for this modification. 058 * @param attribute The attribute for this modification. 059 */ 060 public Modification(ModificationType modificationType, 061 Attribute attribute) 062 { 063 this.modificationType = modificationType; 064 this.attribute = attribute; 065 066 isInternal = false; 067 } 068 069 /** 070 * Creates a new modification with the provided information. 071 * 072 * @param modificationType The modification type for this modification. 073 * @param attribute The attribute for this modification. 074 * @param isInternal Indicates whether this is an internal modification 075 * and therefore should not be subject to 076 * no-user-modification and related checks. 077 */ 078 public Modification(ModificationType modificationType, 079 Attribute attribute, boolean isInternal) 080 { 081 this.modificationType = modificationType; 082 this.attribute = attribute; 083 this.isInternal = isInternal; 084 } 085 086 /** 087 * Retrieves the modification type for this modification. 088 * 089 * @return The modification type for this modification. 090 */ 091 public ModificationType getModificationType() 092 { 093 return modificationType; 094 } 095 096 /** 097 * Specifies the modification type for this modification. 098 * 099 * @param modificationType The modification type for this modification. 100 */ 101 @org.opends.server.types.PublicAPI( 102 stability=org.opends.server.types.StabilityLevel.PRIVATE, 103 mayInstantiate=false, 104 mayExtend=false, 105 mayInvoke=false) 106 public void setModificationType(ModificationType modificationType) 107 { 108 this.modificationType = modificationType; 109 } 110 111 /** 112 * Retrieves the attribute for this modification. 113 * 114 * @return The attribute for this modification. 115 */ 116 public Attribute getAttribute() 117 { 118 return attribute; 119 } 120 121 /** 122 * Specifies the attribute for this modification. 123 * 124 * @param attribute The attribute for this modification. 125 */ 126 @org.opends.server.types.PublicAPI( 127 stability=org.opends.server.types.StabilityLevel.PRIVATE, 128 mayInstantiate=false, 129 mayExtend=false, 130 mayInvoke=false) 131 public void setAttribute(Attribute attribute) 132 { 133 this.attribute = attribute; 134 } 135 136 /** 137 * Indicates whether this is modification was created by internal processing 138 * and should not be subject to no-user-modification and related checks. 139 * 140 * @return {@code true} if this is an internal modification, or {@code false} if not. 141 */ 142 public boolean isInternal() 143 { 144 return isInternal; 145 } 146 147 /** 148 * Specifies whether this modification was created by internal processing 149 * and should not be subject to no-user-modification and related checks. 150 * 151 * @param isInternal Specifies whether this modification was created 152 * by internal processing and should not be subject to 153 * no-user-modification and related checks. 154 */ 155 public void setInternal(boolean isInternal) 156 { 157 this.isInternal = isInternal; 158 } 159 160 /** 161 * Indicates whether the provided object is equal to this modification. 162 * It will only be considered equal if the object is a modification 163 * with the same modification type and an attribute that is equal to this modification. 164 * 165 * @param o The object for which to make the determination. 166 * @return {@code true} if the provided object is a 167 * modification that is equal to this modification, 168 * or {@code false} if not. 169 */ 170 @Override 171 public boolean equals(Object o) 172 { 173 if (this == o) 174 { 175 return true; 176 } 177 if (!(o instanceof Modification)) 178 { 179 return false; 180 } 181 182 Modification m = (Modification) o; 183 return modificationType == m.modificationType 184 && attribute.equals(m.attribute); 185 } 186 187 /** 188 * Retrieves the hash code for this modification. The hash code 189 * returned will be the hash code for the attribute included in this modification. 190 * 191 * @return The hash code for this modification. 192 */ 193 @Override 194 public int hashCode() 195 { 196 return attribute.hashCode(); 197 } 198 199 /** 200 * Retrieves a one-line string representation of this modification. 201 * 202 * @return A one-line string representation of this modification. 203 */ 204 @Override 205 public String toString() 206 { 207 StringBuilder buffer = new StringBuilder(); 208 toString(buffer); 209 return buffer.toString(); 210 } 211 212 /** 213 * Appends a one-line representation of this modification to the provided buffer. 214 * 215 * @param buffer The buffer to which the information should be appended. 216 */ 217 public void toString(StringBuilder buffer) 218 { 219 buffer.append("Modification("); 220 buffer.append(modificationType); 221 buffer.append(", "); 222 buffer.append(attribute); 223 } 224}