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