blob: 4cf04a0f5b9499b0cb4cc329e5e05ab283670874 [file] [log] [blame]
Richard S. Hallf28d6762009-06-08 19:31:06 +00001/*
2 * Copyright (c) OSGi Alliance (2007, 2009). All Rights Reserved.
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
17package org.osgi.framework;
18
19/**
20 * A service exception used to indicate that a service problem occurred.
21 *
22 * <p>
23 * A <code>ServiceException</code> object is created by the Framework or
24 * service implementation to denote an exception condition in the service. A
25 * type code is used to identify the exception type for future extendability.
26 * Service implementations may also create subclasses of
27 * <code>ServiceException</code>. When subclassing, the subclass should set
28 * the type to {@link #SUBCLASSED} to indicate that
29 * <code>ServiceException</code> has been subclassed.
30 *
31 * <p>
32 * This exception conforms to the general purpose exception chaining mechanism.
33 *
34 * @version $Revision: 6518 $
35 * @since 1.5
36 */
37
38public class ServiceException extends RuntimeException {
39 static final long serialVersionUID = 3038963223712959631L;
40
41 /**
42 * Type of service exception.
43 */
44 private final int type;
45
46 /**
47 * No exception type is unspecified.
48 */
49 public static final int UNSPECIFIED = 0;
50 /**
51 * The service has been unregistered.
52 */
53 public static final int UNREGISTERED = 1;
54 /**
55 * The service factory produced an invalid service object.
56 */
57 public static final int FACTORY_ERROR = 2;
58 /**
59 * The service factory threw an exception.
60 */
61 public static final int FACTORY_EXCEPTION = 3;
62 /**
63 * The exception is a subclass of ServiceException. The subclass should be
64 * examined for the type of the exception.
65 */
66 public static final int SUBCLASSED = 4;
67 /**
68 * An error occurred invoking a remote service.
69 */
70 public static final int REMOTE = 5;
71
72 /**
73 * Creates a <code>ServiceException</code> with the specified message and
74 * exception cause.
75 *
76 * @param msg The associated message.
77 * @param cause The cause of this exception.
78 */
79 public ServiceException(String msg, Throwable cause) {
80 this(msg, UNSPECIFIED, cause);
81 }
82
83 /**
84 * Creates a <code>ServiceException</code> with the specified message.
85 *
86 * @param msg The message.
87 */
88 public ServiceException(String msg) {
89 this(msg, UNSPECIFIED);
90 }
91
92 /**
93 * Creates a <code>ServiceException</code> with the specified message,
94 * type and exception cause.
95 *
96 * @param msg The associated message.
97 * @param type The type for this exception.
98 * @param cause The cause of this exception.
99 */
100 public ServiceException(String msg, int type, Throwable cause) {
101 super(msg, cause);
102 this.type = type;
103 }
104
105 /**
106 * Creates a <code>ServiceException</code> with the specified message and
107 * type.
108 *
109 * @param msg The message.
110 * @param type The type for this exception.
111 */
112 public ServiceException(String msg, int type) {
113 super(msg);
114 this.type = type;
115 }
116
117 /**
118 * Returns the type for this exception or <code>UNSPECIFIED</code> if the
119 * type was unspecified or unknown.
120 *
121 * @return The type of this exception.
122 */
123 public int getType() {
124 return type;
125 }
126}