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