blob: 500d14749fd046d7b97ef774aeb59eb365817c73 [file] [log] [blame]
Richard S. Hallc88fca32006-10-18 22:01:22 +00001/*
Richard S. Hallf28d6762009-06-08 19:31:06 +00002 * Copyright (c) OSGi Alliance (2000, 2008). All Rights Reserved.
Richard S. Hallc88fca32006-10-18 22:01:22 +00003 *
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
17package org.osgi.framework;
18
19/**
20 * A Framework exception used to indicate that a bundle lifecycle problem
21 * occurred.
22 *
23 * <p>
Richard S. Hallf28d6762009-06-08 19:31:06 +000024 * A <code>BundleException</code> object is created by the Framework to denote
Richard S. Hallc88fca32006-10-18 22:01:22 +000025 * an exception condition in the lifecycle of a bundle.
26 * <code>BundleException</code>s should not be created by bundle developers.
Richard S. Hallf28d6762009-06-08 19:31:06 +000027 * A type code is used to identify the exception type for future extendability.
Richard S. Hallc88fca32006-10-18 22:01:22 +000028 *
29 * <p>
Richard S. Hallf28d6762009-06-08 19:31:06 +000030 * OSGi Alliance reserves the right to extend the set of types.
Richard S. Hallc88fca32006-10-18 22:01:22 +000031 *
Richard S. Hallf28d6762009-06-08 19:31:06 +000032 * <p>
33 * This exception conforms to the general purpose exception chaining mechanism.
34 *
35 * @version $Revision: 6083 $
Richard S. Hallc88fca32006-10-18 22:01:22 +000036 */
37
38public class BundleException extends Exception {
Richard S. Hallf28d6762009-06-08 19:31:06 +000039 static final long serialVersionUID = 3571095144220455665L;
Richard S. Hallc88fca32006-10-18 22:01:22 +000040 /**
Richard S. Hallf28d6762009-06-08 19:31:06 +000041 * Type of bundle exception.
42 *
43 * @since 1.5
Richard S. Hallc88fca32006-10-18 22:01:22 +000044 */
Richard S. Hallf28d6762009-06-08 19:31:06 +000045 private final int type;
Richard S. Hallc88fca32006-10-18 22:01:22 +000046
47 /**
Richard S. Hallf28d6762009-06-08 19:31:06 +000048 * 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. Hallc88fca32006-10-18 22:01:22 +0000122 *
123 * @param msg The associated message.
124 * @param cause The cause of this exception.
125 */
126 public BundleException(String msg, Throwable cause) {
Richard S. Hallf28d6762009-06-08 19:31:06 +0000127 this(msg, UNSPECIFIED, cause);
Richard S. Hallc88fca32006-10-18 22:01:22 +0000128 }
129
130 /**
Richard S. Hallf28d6762009-06-08 19:31:06 +0000131 * Creates a <code>BundleException</code> with the specified message.
Richard S. Hallc88fca32006-10-18 22:01:22 +0000132 *
133 * @param msg The message.
134 */
135 public BundleException(String msg) {
Richard S. Hallf28d6762009-06-08 19:31:06 +0000136 this(msg, UNSPECIFIED);
Richard S. Hallc88fca32006-10-18 22:01:22 +0000137 }
138
139 /**
Richard S. Hallf28d6762009-06-08 19:31:06 +0000140 * 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. Hallc88fca32006-10-18 22:01:22 +0000169 *
170 * <p>
171 * This method predates the general purpose exception chaining mechanism.
Richard S. Hallf28d6762009-06-08 19:31:06 +0000172 * The <code>getCause()</code> method is now the preferred means of
173 * obtaining this information.
Richard S. Hallc88fca32006-10-18 22:01:22 +0000174 *
Richard S. Hallf28d6762009-06-08 19:31:06 +0000175 * @return The result of calling <code>getCause()</code>.
Richard S. Hallc88fca32006-10-18 22:01:22 +0000176 */
177 public Throwable getNestedException() {
Richard S. Hallf28d6762009-06-08 19:31:06 +0000178 return getCause();
Richard S. Hallc88fca32006-10-18 22:01:22 +0000179 }
180
181 /**
Richard S. Hallf28d6762009-06-08 19:31:06 +0000182 * Returns the cause of this exception or <code>null</code> if no cause was
183 * set.
Richard S. Hallc88fca32006-10-18 22:01:22 +0000184 *
Richard S. Hallf28d6762009-06-08 19:31:06 +0000185 * @return The cause of this exception or <code>null</code> if no cause was
186 * set.
Richard S. Hallc88fca32006-10-18 22:01:22 +0000187 * @since 1.3
188 */
Richard S. Hallf28d6762009-06-08 19:31:06 +0000189 public Throwable getCause() {
190 return super.getCause();
Richard S. Hallc88fca32006-10-18 22:01:22 +0000191 }
192
193 /**
Richard S. Hallf28d6762009-06-08 19:31:06 +0000194 * Initializes the cause of this exception to the specified value.
Richard S. Hallc88fca32006-10-18 22:01:22 +0000195 *
Richard S. Hallf28d6762009-06-08 19:31:06 +0000196 * @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. Hallc88fca32006-10-18 22:01:22 +0000202 * @since 1.3
203 */
204 public Throwable initCause(Throwable cause) {
Richard S. Hallf28d6762009-06-08 19:31:06 +0000205 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. Hallc88fca32006-10-18 22:01:22 +0000217 }
218}