mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
13.53.2013 2d2991e5746eacef47f32cfec5092597da247007
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 */
 
package org.opends.server.admin.client;
 
 
 
import static com.forgerock.opendj.ldap.AdminMessages.*;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
 
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.opends.server.admin.OperationsException;
import org.opends.server.admin.PropertyIsMandatoryException;
 
import com.forgerock.opendj.util.Validator;
 
 
 
/**
 * This exception is thrown when an attempt is made to add or modify a
 * managed object when one or more of its mandatory properties are
 * undefined.
 */
public class MissingMandatoryPropertiesException extends OperationsException {
 
  /**
   * Serialization ID.
   */
  private static final long serialVersionUID = 6342522125252055588L;
 
 
 
  // Create the message.
  private static LocalizableMessage createMessage(
      Collection<PropertyIsMandatoryException> causes) {
    Validator.ensureNotNull(causes);
    Validator.ensureTrue(!causes.isEmpty(), "causes should not be empty");
 
    if (causes.size() == 1) {
      return ERR_MISSING_MANDATORY_PROPERTIES_EXCEPTION_SINGLE.get(causes
          .iterator().next().getPropertyDefinition().getName());
    } else {
      LocalizableMessageBuilder builder = new LocalizableMessageBuilder();
 
      boolean isFirst = true;
      for (PropertyIsMandatoryException cause : causes) {
        if (!isFirst) {
          builder.append(", ");
        }
        builder.append(cause.getPropertyDefinition().getName());
        isFirst = false;
      }
 
      return ERR_MISSING_MANDATORY_PROPERTIES_EXCEPTION_PLURAL.get(builder
          .toMessage());
    }
  }
 
  // The causes of this exception.
  private final Collection<PropertyIsMandatoryException> causes;
 
  // Indicates whether the exception occurred during managed object
  // creation.
  private final boolean isCreate;
 
  // The user friendly name of the component that caused this
  // exception.
  private final LocalizableMessage ufn;
 
 
 
  /**
   * Creates a new missing mandatory properties exception with the
   * provided causes.
   *
   * @param ufn
   *          The user friendly name of the component that caused this
   *          exception.
   * @param causes
   *          The causes of this exception (must be non-<code>null</code>
   *          and non-empty).
   * @param isCreate
   *          Indicates whether the exception occurred during managed
   *          object creation.
   */
  public MissingMandatoryPropertiesException(LocalizableMessage ufn,
      Collection<PropertyIsMandatoryException> causes, boolean isCreate) {
    super(createMessage(causes));
 
    this.causes = new ArrayList<PropertyIsMandatoryException>(causes);
    this.ufn = ufn;
    this.isCreate = isCreate;
  }
 
 
 
  /**
   * Gets the first exception that caused this exception.
   *
   * @return Returns the first exception that caused this exception.
   */
  @Override
  public PropertyIsMandatoryException getCause() {
    return causes.iterator().next();
  }
 
 
 
  /**
   * Gets an unmodifiable collection view of the causes of this
   * exception.
   *
   * @return Returns an unmodifiable collection view of the causes of
   *         this exception.
   */
  public Collection<PropertyIsMandatoryException> getCauses() {
    return Collections.unmodifiableCollection(causes);
  }
 
 
 
  /**
   * Gets the user friendly name of the component that caused this
   * exception.
   *
   * @return Returns the user friendly name of the component that
   *         caused this exception.
   */
  public LocalizableMessage getUserFriendlyName() {
    return ufn;
  }
 
 
 
  /**
   * Indicates whether or not this exception was thrown during managed
   * object creation or during modification.
   *
   * @return Returns <code>true</code> if this exception was thrown
   *         during managed object creation.
   */
  public boolean isCreate() {
    return isCreate;
  }
 
}