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 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027
028package org.opends.server.admin;
029
030
031
032import static org.opends.messages.AdminMessages.*;
033
034import org.forgerock.i18n.LocalizableMessage;
035
036
037
038/**
039 * The requested managed object was found but its type could not be
040 * determined.
041 */
042public class DefinitionDecodingException extends DecodingException {
043
044  /**
045   * An enumeration defining the reasons why the definition could not
046   * be resolved.
047   */
048  public static enum Reason {
049    /**
050     * The managed object could be found but its type resolved to an
051     * abstract managed object definition.
052     */
053    ABSTRACT_TYPE_INFORMATION(),
054
055    /**
056     * The managed object could be found but did not contain any type
057     * information (eg missing object classes in LDAP).
058     */
059    NO_TYPE_INFORMATION(),
060
061    /**
062     * The managed object could be found but did not contain the
063     * expected type information (eg incorrect object classes in
064     * LDAP).
065     */
066    WRONG_TYPE_INFORMATION();
067
068  }
069
070  /**
071   * Version ID required by serializable classes.
072   */
073  private static final long serialVersionUID = 3459033551415663416L;
074
075
076
077  /** Create the message. */
078  private static LocalizableMessage createMessage(AbstractManagedObjectDefinition<?, ?> d,
079      Reason reason) {
080    LocalizableMessage ufn = d.getUserFriendlyName();
081    switch (reason) {
082    case NO_TYPE_INFORMATION:
083      return ERR_DECODING_EXCEPTION_NO_TYPE_INFO.get(ufn);
084    case WRONG_TYPE_INFORMATION:
085      return ERR_DECODING_EXCEPTION_WRONG_TYPE_INFO.get(ufn);
086    default:
087      return ERR_DECODING_EXCEPTION_ABSTRACT_TYPE_INFO.get(ufn);
088    }
089  }
090
091  /** The expected type of managed object. */
092  private final AbstractManagedObjectDefinition<?, ?> d;
093
094  /** The reason why the definition could not be determined. */
095  private final Reason reason;
096
097
098
099  /**
100   * Create a new definition decoding exception.
101   *
102   * @param d
103   *          The expected type of managed object.
104   * @param reason
105   *          The reason why the definition could not be determined.
106   */
107  public DefinitionDecodingException(AbstractManagedObjectDefinition<?, ?> d,
108      Reason reason) {
109    super(createMessage(d, reason));
110    this.d = d;
111    this.reason = reason;
112  }
113
114
115
116  /**
117   * Gets the expected managed object definition.
118   *
119   * @return Returns the expected managed object definition.
120   */
121  public AbstractManagedObjectDefinition<?, ?> getManagedObjectDefinition() {
122    return d;
123  }
124
125
126
127  /**
128   * Gets the reason why the definition could not be determined.
129   *
130   * @return Returns the reason why the definition could not be
131   *         determined.
132   */
133  public Reason getReason() {
134    return reason;
135  }
136}