001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 * Portions Copyright 2014-2015 ForgeRock AS. 016 */ 017 018package org.opends.server.admin; 019 020 021 022import static org.opends.messages.AdminMessages.*; 023 024import org.forgerock.i18n.LocalizableMessage; 025 026 027 028/** 029 * The requested managed object was found but its type could not be 030 * determined. 031 */ 032public class DefinitionDecodingException extends DecodingException { 033 034 /** 035 * An enumeration defining the reasons why the definition could not 036 * be resolved. 037 */ 038 public static enum Reason { 039 /** 040 * The managed object could be found but its type resolved to an 041 * abstract managed object definition. 042 */ 043 ABSTRACT_TYPE_INFORMATION(), 044 045 /** 046 * The managed object could be found but did not contain any type 047 * information (eg missing object classes in LDAP). 048 */ 049 NO_TYPE_INFORMATION(), 050 051 /** 052 * The managed object could be found but did not contain the 053 * expected type information (eg incorrect object classes in 054 * LDAP). 055 */ 056 WRONG_TYPE_INFORMATION(); 057 058 } 059 060 /** 061 * Version ID required by serializable classes. 062 */ 063 private static final long serialVersionUID = 3459033551415663416L; 064 065 066 067 /** Create the message. */ 068 private static LocalizableMessage createMessage(AbstractManagedObjectDefinition<?, ?> d, 069 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 089 /** 090 * Create a new definition decoding exception. 091 * 092 * @param d 093 * The expected type of managed object. 094 * @param reason 095 * The reason why the definition could not be determined. 096 */ 097 public DefinitionDecodingException(AbstractManagedObjectDefinition<?, ?> d, 098 Reason reason) { 099 super(createMessage(d, reason)); 100 this.d = d; 101 this.reason = reason; 102 } 103 104 105 106 /** 107 * Gets the expected managed object definition. 108 * 109 * @return Returns the expected managed object definition. 110 */ 111 public AbstractManagedObjectDefinition<?, ?> getManagedObjectDefinition() { 112 return d; 113 } 114 115 116 117 /** 118 * Gets the reason why the definition could not be determined. 119 * 120 * @return Returns the reason why the definition could not be 121 * determined. 122 */ 123 public Reason getReason() { 124 return reason; 125 } 126}