blob: 29d365034e023c7109885747c7e513aa2364937d [file] [log] [blame]
Richard S. Hall930fecc2005-08-16 18:33:34 +00001/*
2 * $Header: /cvshome/build/org.osgi.framework/src/org/osgi/framework/ServiceEvent.java,v 1.9 2005/05/13 20:32:56 hargrave Exp $
3 *
4 * Copyright (c) OSGi Alliance (2000, 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.Dictionary;
14import java.util.EventObject;
15
16/**
17 * A service lifecycle change event.
18 * <p>
19 * <code>ServiceEvent</code> objects are delivered to a <code>ServiceListener</code>
20 * objects when a change occurs in this service's lifecycle. A type code is used
21 * to identify the event type for future extendability.
22 *
23 * <p>
24 * OSGi Alliance reserves the right to extend the set of types.
25 *
26 * @version $Revision: 1.9 $
27 * @see ServiceListener
28 */
29
30public class ServiceEvent extends EventObject {
31 static final long serialVersionUID = 8792901483909409299L;
32 /**
33 * Reference to the service that had a change occur in its lifecycle.
34 */
35 private ServiceReference reference;
36
37 /**
38 * Type of service lifecycle change.
39 */
40 private int type;
41
42 /**
43 * This service has been registered.
44 * <p>
45 * This event is synchronously delivered <strong>after </strong> the service
46 * has been registered with the Framework.
47 *
48 * <p>
49 * The value of <code>REGISTERED</code> is 0x00000001.
50 *
51 * @see BundleContext#registerService(String[],Object,Dictionary)
52 */
53 public final static int REGISTERED = 0x00000001;
54
55 /**
56 * The properties of a registered service have been modified.
57 * <p>
58 * This event is synchronously delivered <strong>after </strong> the service
59 * properties have been modified.
60 *
61 * <p>
62 * The value of <code>MODIFIED</code> is 0x00000002.
63 *
64 * @see ServiceRegistration#setProperties
65 */
66 public final static int MODIFIED = 0x00000002;
67
68 /**
69 * This service is in the process of being unregistered.
70 * <p>
71 * This event is synchronously delivered <strong>before </strong> the
72 * service has completed unregistering.
73 *
74 * <p>
75 * If a bundle is using a service that is <code>UNREGISTERING</code>, the
76 * bundle should release its use of the service when it receives this event.
77 * If the bundle does not release its use of the service when it receives
78 * this event, the Framework will automatically release the bundle's use of
79 * the service while completing the service unregistration operation.
80 *
81 * <p>
82 * The value of UNREGISTERING is 0x00000004.
83 *
84 * @see ServiceRegistration#unregister
85 * @see BundleContext#ungetService
86 */
87 public final static int UNREGISTERING = 0x00000004;
88
89 /**
90 * Creates a new service event object.
91 *
92 * @param type The event type.
93 * @param reference A <code>ServiceReference</code> object to the service that
94 * had a lifecycle change.
95 */
96 public ServiceEvent(int type, ServiceReference reference) {
97 super(reference);
98 this.reference = reference;
99 this.type = type;
100 }
101
102 /**
103 * Returns a reference to the service that had a change occur in its
104 * lifecycle.
105 * <p>
106 * This reference is the source of the event.
107 *
108 * @return Reference to the service that had a lifecycle change.
109 */
110 public ServiceReference getServiceReference() {
111 return (reference);
112 }
113
114 /**
115 * Returns the type of event. The event type values are:
116 * <ul>
117 * <li>{@link #REGISTERED}
118 * <li>{@link #MODIFIED}
119 * <li>{@link #UNREGISTERING}
120 * </ul>
121 *
122 * @return Type of service lifecycle change.
123 */
124
125 public int getType() {
126 return (type);
127 }
128}
129