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.Collections;
033 import java.util.Iterator;
034 import java.util.List;
035 import java.util.Map;
036
037 import org.opends.server.types.Attribute;
038 import org.opends.server.types.AttributeType;
039 import org.opends.server.types.DN;
040
041
042
043 /**
044 * This class defines a data structure for a change record entry for
045 * an add operation. It includes a DN and a set of attributes, as well as
046 * methods to decode the entry.
047 */
048 @org.opends.server.types.PublicAPI(
049 stability=org.opends.server.types.StabilityLevel.VOLATILE,
050 mayInstantiate=true,
051 mayExtend=false,
052 mayInvoke=true)
053 public final class AddChangeRecordEntry extends ChangeRecordEntry
054 {
055
056 /**
057 * The entry attributes for this operation.
058 */
059 private final List<Attribute> attributes;
060
061
062
063 /**
064 * Creates a new entry with the provided information.
065 *
066 * @param dn
067 * The distinguished name for this entry. It must not be
068 * <CODE>null</CODE>.
069 * @param attributes
070 * The entry attributes for this operation. It must not be
071 * <CODE>null</CODE>.
072 */
073 public AddChangeRecordEntry(DN dn,
074 Map<AttributeType,List<Attribute>> attributes)
075 {
076 super(dn);
077
078
079 ensureNotNull(attributes);
080
081
082 this.attributes = new ArrayList<Attribute>(attributes.size());
083 for (List<Attribute> list : attributes.values())
084 {
085 for (Attribute a : list)
086 {
087 this.attributes.add(a);
088 }
089 }
090 }
091
092
093
094 /**
095 * Retrieves the name of the change operation type.
096 *
097 * @return The name of the change operation type.
098 */
099 public ChangeOperationType getChangeOperationType()
100 {
101 return ChangeOperationType.ADD;
102 }
103
104
105
106 /**
107 * Retrieves the entire set of attributes for this entry.
108 * <p>
109 * The returned list is read-only.
110 *
111 * @return The entire unmodifiable list of attributes for this entry.
112 */
113 public List<Attribute> getAttributes()
114 {
115 return Collections.unmodifiableList(attributes);
116 }
117
118
119
120 /**
121 * {@inheritDoc}
122 */
123 @Override()
124 public String toString()
125 {
126 StringBuilder buffer = new StringBuilder();
127 buffer.append("AddChangeRecordEntry(dn=\"");
128 buffer.append(String.valueOf(getDN()));
129 buffer.append("\", attrs={");
130
131 Iterator<Attribute> iterator = attributes.iterator();
132 while (iterator.hasNext())
133 {
134 buffer.append(iterator.next().getName());
135 if (iterator.hasNext())
136 {
137 buffer.append(", ");
138 }
139 }
140 buffer.append("})");
141
142 return buffer.toString();
143 }
144 }
145