blob: b226dab24628b3d963fa5ff5b66cceb1f2a0b43f [file] [log] [blame]
Richard S. Hall930fecc2005-08-16 18:33:34 +00001/*
2 * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/FrameworkEvent.java,v 1.9 2005/05/13 20:32:56 hargrave Exp $
3 *
4 * Copyright (c) OSGi Alliance (2004, 2005). All Rights Reserved.
5 *
6 * This program and the accompanying materials are made available under the
7 * terms of the Eclipse Public License v1.0 which accompanies this
8 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
9 */
10
11package org.osgi.framework;
12
13import java.util.EventObject;
14
15/**
16 * A general Framework event.
17 *
18 * <p>
19 * <code>FrameworkEvent</code> is the event class used when notifying listeners of
20 * general events occuring within the OSGI environment. A type code is used to
21 * identify the event type for future extendability.
22 *
23 * <p>
24 * OSGi Alliance reserves the right to extend the set of event types.
25 *
26 * @version $Revision: 1.9 $
27 */
28
29public class FrameworkEvent extends EventObject {
30 static final long serialVersionUID = 207051004521261705L;
31 /**
32 * Bundle related to the event.
33 */
34 private Bundle bundle;
35
36 /**
37 * Exception related to the event.
38 */
39 private Throwable throwable;
40
41 /**
42 * Type of event.
43 */
44 private int type;
45
46 /**
47 * The Framework has started.
48 *
49 * <p>
50 * This event is broadcast when the Framework has started after all
51 * installed bundles that are marked to be started have been started and the
52 * Framework has reached the intitial start level.
53 *
54 * <p>
55 * The value of <code>STARTED</code> is 0x00000001.
56 *
57 * @see "<code>StartLevel</code>"
58 */
59 public final static int STARTED = 0x00000001;
60
61 /**
62 * An error has occurred.
63 *
64 * <p>
65 * There was an error associated with a bundle.
66 *
67 * <p>
68 * The value of <code>ERROR</code> is 0x00000002.
69 */
70 public final static int ERROR = 0x00000002;
71
72 /**
73 * A PackageAdmin.refreshPackage operation has completed.
74 *
75 * <p>
76 * This event is broadcast when the Framework has completed the refresh
77 * packages operation initiated by a call to the
78 * PackageAdmin.refreshPackages method.
79 *
80 * <p>
81 * The value of <code>PACKAGES_REFRESHED</code> is 0x00000004.
82 *
83 * @since 1.2
84 * @see "<code>PackageAdmin.refreshPackages</code>"
85 */
86 public final static int PACKAGES_REFRESHED = 0x00000004;
87
88 /**
89 * A StartLevel.setStartLevel operation has completed.
90 *
91 * <p>
92 * This event is broadcast when the Framework has completed changing the
93 * active start level initiated by a call to the StartLevel.setStartLevel
94 * method.
95 *
96 * <p>
97 * The value of <code>STARTLEVEL_CHANGED</code> is 0x00000008.
98 *
99 * @since 1.2
100 * @see "<code>StartLevel</code>"
101 */
102 public final static int STARTLEVEL_CHANGED = 0x00000008;
103
104 /**
105 * A warning has occurred.
106 *
107 * <p>
108 * There was a warning associated with a bundle.
109 *
110 * <p>
111 * The value of <code>WARNING</code> is 0x00000010.
112 *
113 * @since 1.3
114 */
115 public final static int WARNING = 0x00000010;
116
117 /**
118 * An informational event has occurred.
119 *
120 * <p>
121 * There was an informational event associated with a bundle.
122 *
123 * <p>
124 * The value of <code>INFO</code> is 0x00000020.
125 *
126 * @since 1.3
127 */
128 public final static int INFO = 0x00000020;
129
130 /**
131 * Creates a Framework event.
132 *
133 * @param type The event type.
134 * @param source The event source object. This may not be <code>null</code>.
135 * @deprecated Since 1.2. This constructor is deprecated in favor of using
136 * the other constructor with the System Bundle as the event
137 * source.
138 */
139 public FrameworkEvent(int type, Object source) {
140 super(source);
141 this.type = type;
142 this.bundle = null;
143 this.throwable = null;
144 }
145
146 /**
147 * Creates a Framework event regarding the specified bundle.
148 *
149 * @param type The event type.
150 * @param bundle The event source.
151 * @param throwable The related exception. This argument may be
152 * <code>null</code> if there is no related exception.
153 */
154 public FrameworkEvent(int type, Bundle bundle, Throwable throwable) {
155 super(bundle);
156 this.type = type;
157 this.bundle = bundle;
158 this.throwable = throwable;
159 }
160
161 /**
162 * Returns the exception related to this event.
163 *
164 * @return The related exception or <code>null</code> if none.
165 */
166 public Throwable getThrowable() {
167 return throwable;
168 }
169
170 /**
171 * Returns the bundle associated with the event. This bundle is also the
172 * source of the event.
173 *
174 * @return The bundle associated with the event.
175 */
176 public Bundle getBundle() {
177 return bundle;
178 }
179
180 /**
181 * Returns the type of framework event.
182 * <p>
183 * The type values are:
184 * <ul>
185 * <li>{@link #STARTED}
186 * <li>{@link #ERROR}
187 * <li>{@link #WARNING}
188 * <li>{@link #INFO}
189 * <li>{@link #PACKAGES_REFRESHED}
190 * <li>{@link #STARTLEVEL_CHANGED}
191 * </ul>
192 *
193 * @return The type of state change.
194 */
195
196 public int getType() {
197 return type;
198 }
199}