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
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.util;
028    
029    import static org.opends.server.util.Validator.*;
030    
031    import java.util.ArrayList;
032    import java.util.Collection;
033    import java.util.Collections;
034    import java.util.Iterator;
035    import java.util.List;
036    
037    import org.opends.server.types.DN;
038    import org.opends.server.types.RawModification;
039    
040    
041    
042    /**
043     * This class defines a data structure for a change record entry for
044     * an modify operation.  It includes a DN and a set of attributes, as well as
045     * methods to decode the entry.
046     */
047    @org.opends.server.types.PublicAPI(
048         stability=org.opends.server.types.StabilityLevel.VOLATILE,
049         mayInstantiate=true,
050         mayExtend=false,
051         mayInvoke=true)
052    public final class ModifyChangeRecordEntry extends ChangeRecordEntry
053    {
054      /**
055       * The modifications for this change record.
056       */
057      private final List<RawModification> modifications;
058    
059    
060    
061      /**
062       * Creates a new entry with the provided information.
063       *
064       * @param  dn             The distinguished name for this entry.  It must not
065       *                        be  <CODE>null</CODE>.
066       * @param  modifications  The modifications for this change record.  It must
067       *                        not be <CODE>null</CODE>.
068       */
069      public ModifyChangeRecordEntry(DN dn,
070          Collection<RawModification> modifications)
071      {
072        super(dn);
073    
074    
075        ensureNotNull(modifications);
076    
077        this.modifications = new ArrayList<RawModification>(modifications);
078      }
079    
080    
081      /**
082       * Get the list of modifications.
083       * <p>
084       * The returned list is read-only.
085       *
086       * @return Returns the unmodifiable list of modifications.
087       */
088      public List<RawModification> getModifications()
089      {
090        return Collections.unmodifiableList(modifications);
091      }
092    
093    
094    
095      /**
096       * Retrieves the name of the change operation type.
097       *
098       * @return  The name of the change operation type.
099       */
100      public ChangeOperationType getChangeOperationType()
101      {
102        return ChangeOperationType.MODIFY;
103      }
104    
105    
106    
107      /**
108       * {@inheritDoc}
109       */
110      @Override()
111      public String toString()
112      {
113        StringBuilder buffer = new StringBuilder();
114        buffer.append("ModifyChangeRecordEntry(dn=\"");
115        buffer.append(String.valueOf(getDN()));
116        buffer.append("\", mods={");
117    
118        Iterator<RawModification> iterator = modifications.iterator();
119        while (iterator.hasNext())
120        {
121          RawModification mod = iterator.next();
122          buffer.append(mod.getModificationType().getLDIFName());
123          buffer.append(" ");
124          buffer.append(mod.getAttribute().getAttributeType());
125    
126          if (iterator.hasNext())
127          {
128            buffer.append(", ");
129          }
130        }
131        buffer.append("})");
132    
133        return buffer.toString();
134      }
135    }
136