Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 1 | /* |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 2 | * Copyright (c) OSGi Alliance (2000, 2008). All Rights Reserved. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.osgi.framework; |
| 18 | |
| 19 | /** |
| 20 | * A Framework exception used to indicate that a bundle lifecycle problem |
| 21 | * occurred. |
| 22 | * |
| 23 | * <p> |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 24 | * A <code>BundleException</code> object is created by the Framework to denote |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 25 | * an exception condition in the lifecycle of a bundle. |
| 26 | * <code>BundleException</code>s should not be created by bundle developers. |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 27 | * A type code is used to identify the exception type for future extendability. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 28 | * |
| 29 | * <p> |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 30 | * OSGi Alliance reserves the right to extend the set of types. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 31 | * |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 32 | * <p> |
| 33 | * This exception conforms to the general purpose exception chaining mechanism. |
| 34 | * |
| 35 | * @version $Revision: 6083 $ |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 36 | */ |
| 37 | |
| 38 | public class BundleException extends Exception { |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 39 | static final long serialVersionUID = 3571095144220455665L; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 40 | /** |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 41 | * Type of bundle exception. |
| 42 | * |
| 43 | * @since 1.5 |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 44 | */ |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 45 | private final int type; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 46 | |
| 47 | /** |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 48 | * No exception type is unspecified. |
| 49 | * |
| 50 | * @since 1.5 |
| 51 | */ |
| 52 | public static final int UNSPECIFIED = 0; |
| 53 | /** |
| 54 | * The operation was unsupported. |
| 55 | * |
| 56 | * @since 1.5 |
| 57 | */ |
| 58 | public static final int UNSUPPORTED_OPERATION = 1; |
| 59 | /** |
| 60 | * The operation was invalid. |
| 61 | * |
| 62 | * @since 1.5 |
| 63 | */ |
| 64 | public static final int INVALID_OPERATION = 2; |
| 65 | /** |
| 66 | * The bundle manifest was in error. |
| 67 | * |
| 68 | * @since 1.5 |
| 69 | */ |
| 70 | public static final int MANIFEST_ERROR = 3; |
| 71 | /** |
| 72 | * The bundle was not resolved. |
| 73 | * |
| 74 | * @since 1.5 |
| 75 | */ |
| 76 | public static final int RESOLVE_ERROR = 4; |
| 77 | /** |
| 78 | * The bundle activator was in error. |
| 79 | * |
| 80 | * @since 1.5 |
| 81 | */ |
| 82 | public static final int ACTIVATOR_ERROR = 5; |
| 83 | /** |
| 84 | * The operation failed due to insufficient permissions. |
| 85 | * |
| 86 | * @since 1.5 |
| 87 | */ |
| 88 | public static final int SECURITY_ERROR = 6; |
| 89 | /** |
| 90 | * The operation failed to complete the requested lifecycle state change. |
| 91 | * |
| 92 | * @since 1.5 |
| 93 | */ |
| 94 | public static final int STATECHANGE_ERROR = 7; |
| 95 | |
| 96 | /** |
| 97 | * The bundle could not be resolved due to an error with the |
| 98 | * Bundle-NativeCode header. |
| 99 | * |
| 100 | * @since 1.5 |
| 101 | */ |
| 102 | public static final int NATIVECODE_ERROR = 8; |
| 103 | |
| 104 | /** |
| 105 | * The install or update operation failed because another |
| 106 | * already installed bundle has the same symbolic name and version. |
| 107 | * @since 1.5 |
| 108 | */ |
| 109 | public static final int DUPLICATE_BUNDLE_ERROR = 9; |
| 110 | |
| 111 | /** |
| 112 | * The start transient operation failed because the start level of the |
| 113 | * bundle is greater than the current framework start level |
| 114 | * |
| 115 | * @since 1.5 |
| 116 | */ |
| 117 | public static final int START_TRANSIENT_ERROR = 10; |
| 118 | |
| 119 | /** |
| 120 | * Creates a <code>BundleException</code> with the specified message and |
| 121 | * exception cause. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 122 | * |
| 123 | * @param msg The associated message. |
| 124 | * @param cause The cause of this exception. |
| 125 | */ |
| 126 | public BundleException(String msg, Throwable cause) { |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 127 | this(msg, UNSPECIFIED, cause); |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 131 | * Creates a <code>BundleException</code> with the specified message. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 132 | * |
| 133 | * @param msg The message. |
| 134 | */ |
| 135 | public BundleException(String msg) { |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 136 | this(msg, UNSPECIFIED); |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /** |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 140 | * Creates a <code>BundleException</code> with the specified message, type |
| 141 | * and exception cause. |
| 142 | * |
| 143 | * @param msg The associated message. |
| 144 | * @param type The type for this exception. |
| 145 | * @param cause The cause of this exception. |
| 146 | * @since 1.5 |
| 147 | */ |
| 148 | public BundleException(String msg, int type, Throwable cause) { |
| 149 | super(msg, cause); |
| 150 | this.type = type; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Creates a <code>BundleException</code> with the specified message and |
| 155 | * type. |
| 156 | * |
| 157 | * @param msg The message. |
| 158 | * @param type The type for this exception. |
| 159 | * @since 1.5 |
| 160 | */ |
| 161 | public BundleException(String msg, int type) { |
| 162 | super(msg); |
| 163 | this.type = type; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Returns the cause of this exception or <code>null</code> if no cause was |
| 168 | * specified when this exception was created. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 169 | * |
| 170 | * <p> |
| 171 | * This method predates the general purpose exception chaining mechanism. |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 172 | * The <code>getCause()</code> method is now the preferred means of |
| 173 | * obtaining this information. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 174 | * |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 175 | * @return The result of calling <code>getCause()</code>. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 176 | */ |
| 177 | public Throwable getNestedException() { |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 178 | return getCause(); |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /** |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 182 | * Returns the cause of this exception or <code>null</code> if no cause was |
| 183 | * set. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 184 | * |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 185 | * @return The cause of this exception or <code>null</code> if no cause was |
| 186 | * set. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 187 | * @since 1.3 |
| 188 | */ |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 189 | public Throwable getCause() { |
| 190 | return super.getCause(); |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /** |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 194 | * Initializes the cause of this exception to the specified value. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 195 | * |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 196 | * @param cause The cause of this exception. |
| 197 | * @return This exception. |
| 198 | * @throws IllegalArgumentException If the specified cause is this |
| 199 | * exception. |
| 200 | * @throws IllegalStateException If the cause of this exception has already |
| 201 | * been set. |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 202 | * @since 1.3 |
| 203 | */ |
| 204 | public Throwable initCause(Throwable cause) { |
Richard S. Hall | f28d676 | 2009-06-08 19:31:06 +0000 | [diff] [blame] | 205 | return super.initCause(cause); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Returns the type for this exception or <code>UNSPECIFIED</code> if the |
| 210 | * type was unspecified or unknown. |
| 211 | * |
| 212 | * @return The type of this exception. |
| 213 | * @since 1.5 |
| 214 | */ |
| 215 | public int getType() { |
| 216 | return type; |
Richard S. Hall | c88fca3 | 2006-10-18 22:01:22 +0000 | [diff] [blame] | 217 | } |
| 218 | } |