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 2008 Sun Microsystems, Inc.
026 */
027
028 package org.opends.server.admin;
029
030
031
032 import static org.opends.messages.AdminMessages.*;
033
034 import org.opends.messages.Message;
035
036
037
038 /**
039 * The requested managed object was found but its type could not be
040 * determined.
041 */
042 public 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 Message createMessage(AbstractManagedObjectDefinition<?, ?> d,
079 Reason reason) {
080 Message 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 }