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.types; 029 import org.opends.messages.Message; 030 031 032 /** 033 * This class defines a base exception for OpenDS exceptions. 034 */ 035 @org.opends.server.types.PublicAPI( 036 stability=org.opends.server.types.StabilityLevel.VOLATILE, 037 mayInstantiate=false, 038 mayExtend=false, 039 mayInvoke=true) 040 public abstract class OpenDsException 041 extends Exception 042 { 043 044 /** Message that explains the problem. */ 045 Message message; 046 047 /** 048 * Creates a new identified exception. 049 */ 050 protected OpenDsException() 051 { 052 super(); 053 } 054 055 /** 056 * Constructs a new instance from another 057 * <code>OpenDsException</code>. 058 * This constructor sets the message to be that of 059 * <code>cause</code>. 060 * 061 * @param cause exception whose message will be used for 062 * this exception's message. 063 */ 064 protected OpenDsException(OpenDsException cause) { 065 this(null, cause); 066 } 067 068 /** 069 * Creates a new identified exception with the provided information. 070 * 071 * @param message The message that explains the problem that 072 * occurred. 073 */ 074 protected OpenDsException(Message message) 075 { 076 this(message, null); 077 } 078 079 080 081 /** 082 * Creates a new identified exception with the provided information. 083 * 084 * @param cause The underlying cause that triggered this 085 * exception. 086 */ 087 protected OpenDsException(Throwable cause) 088 { 089 this(null, cause); 090 } 091 092 093 094 /** 095 * Creates a new identified exception with the provided information. 096 * 097 * @param message The message that explains the problem that 098 * occurred. 099 * @param cause The underlying cause that triggered this 100 * exception. 101 */ 102 protected OpenDsException(Message message, Throwable cause) 103 { 104 super(message != null ? message.toString() : 105 cause != null ? cause.getMessage() : null, cause); 106 if (message != null) { 107 this.message = message; 108 } else if (cause instanceof OpenDsException) { 109 this.message = ((OpenDsException)cause).getMessageObject(); 110 } 111 } 112 113 114 115 /** 116 * Returns the message that explains the problem that occurred. 117 * 118 * @return Message of the problem 119 */ 120 public Message getMessageObject() { 121 return this.message; 122 } 123 }